How do I make pg_dump available?

zaydekPRO

a year ago

I am getting this error: exec: \"pg_dump\": executable file not found in $PATH" I setup my Railway TOML config like this

[build]
builder = "NIXPACKS"
buildCommand = "go build -o app cmd/iconflex-postgres-backup/*.go"

[build.nixpacksPlan.phases.setup]
nixPkgs = ["go", "postgresql"]

[deploy]
numReplicas = 1
startCommand = "./app"
# healthcheckPath = "/healthz"
sleepApplication = false
restartPolicyType = "ON_FAILURE"
restartPolicyMaxRetries = 1

And I can confirm the service is reading the toml command. What am I doing wrong?

0 Replies

a year ago

ive never been able to install postgresql with nixpacks, i always default to a Dockerfile, heres mine that would be a good starting point -

FROM golang:1.22.2-alpine

ARG PG_VERSION='16'

RUN apk add --update --no-cache postgresql${PG_VERSION}-client

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY . ./

RUN go build -ldflags="-w -s" -o main

ENTRYPOINT ["/app/main"]

zaydekPRO

a year ago

Thanks I'm explroign a docker file now


zaydekPRO

a year ago

FROM golang:1.22.2-alpine3.18 AS builder

WORKDIR /app

# Copy Go modules and source code
COPY go.mod go.sum ./
COPY cmd/iconflex-postgres-backup/*.go cmd/iconflex-postgres-backup/

# Install dependencies
RUN go mod download

# Build the Go binary
RUN go build -o app ./cmd/iconflex-postgres-backup/*.go

FROM alpine:latest

# Install PostgreSQL client
ARG PG_VERSION='16'
RUN apk add --update --no-cache "postgresql${PG_VERSION}-client" --repository=https://dl-cdn.alpinelinux.org/alpine/edge/main

# Copy the built binary from the builder stage
COPY --from=builder /app/app /app/

WORKDIR /app

# Expose necessary port if your app needs it
# EXPOSE 8080

# Run the binary
CMD ["/app/app"]

I am trying to figure out the steps


zaydekPRO

a year ago

Are you sure I need to use RUN apk add --update --no-cache postgresql${PG_VERSION}-client --repository=[https://dl-cdn.alpinelinux.org/alpine/edge/main](https://dl-cdn.alpinelinux.org/alpine/edge/main) instead of something more declaraitive?


a year ago

wydm? you want pg_dump and thats how you install it


zaydekPRO

a year ago

Kk


zaydekPRO

a year ago

I'll try it out now


a year ago

although you dont need to edge anymore, postgresql16-client is now on 3.19


zaydekPRO

a year ago

Can you use a Dockerfile and Railway TOML together?


a year ago

yeah but only the setup stuff would be used


zaydekPRO

a year ago

I meant to configure the health server and retries, etc.


a year ago

yeah you can still use the deploy stuff in a railway.toml file with a dockerfile


zaydekPRO

a year ago

Kk


zaydekPRO

a year ago

Thank you


a year ago

no problem, let me know if that works for you


zaydekPRO

a year ago

Getting some problems but not directly related


zaydekPRO

a year ago

So it looks like this

FROM golang:1.22.0-alpine

ARG PG_VERSION='16'

RUN apk add --update --no-cache postgresql${PG_VERSION}-client --repository=https://dl-cdn.alpinelinux.org/alpine/edge/main

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY . ./

RUN go build -o app cmd/iconflex-admin/*.go

ENTRYPOINT ["./app"]

zaydekPRO

a year ago

Here are the logs



a year ago

its still using nixpacks, make sure your Dockerfile is named correctly


zaydekPRO

a year ago


zaydekPRO

a year ago

Oh wait


zaydekPRO

a year ago

OK so I'm using a monorepo


a year ago

set the root directory in the service settings


zaydekPRO

a year ago

Can you colocate a Dockerfile per command?


a year ago

explain what you mean by that please


zaydekPRO

a year ago

So I have like


zaydekPRO

a year ago

cmd/foo/main.go
cmd/bar/main.go


zaydekPRO

a year ago

How can I have a Dockerfile per service?


zaydekPRO

a year ago

Can I customize the Dockerfile per service in Railway?


a year ago

you could have a [Dockerfile.foo](Dockerfile.foo) and a [Dockerfile.bar](Dockerfile.bar) and then choose what Dockerfile to use with RAILWAY_DOCKERFILE_PATH



zaydekPRO

a year ago

1225631814660391200


zaydekPRO

a year ago

Ah


zaydekPRO

a year ago

Right


a year ago

exactly


zaydekPRO

a year ago

OK will try now thank you


zaydekPRO

a year ago

Wow it worked


a year ago

awsome


zaydekPRO

a year ago

Here's the full Dockerfile for reference

FROM golang:1.22.0-alpine

ARG PG_VERSION='16'

RUN apk add --update --no-cache postgresql${PG_VERSION}-client --repository=https://dl-cdn.alpinelinux.org/alpine/edge/main

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY . ./

RUN go build -o app cmd/iconflex-postgres-backup/*.go

ENTRYPOINT ["./app"]

zaydekPRO

a year ago

Is there any reason not to always use a Docker file in general?


zaydekPRO

a year ago

In my case it would allow me to always use the latest Go version without waiting for Nix


a year ago

you lose caching, and now you have to maintain this dockerfile


zaydekPRO

a year ago

OK so use Railway as is, then lean into Nix if you can, and finally use Docker if you have to?


zaydekPRO

a year ago

As a general decision tree


a year ago

exactly!


a year ago

you could also use Dockerfiles to have a multi layered image where the final image that gets published is a small alpine or scratch image, this is what i do for really fast publish times


zaydekPRO

a year ago

OK so for the smallest, fastest build what does that Dockerfile look like?


zaydekPRO

a year ago

That sounds really interesting


a year ago

in my example i have omitted that for brevity, but the Dockerfile you sent at first does do that


a year ago

everything after the second FROM is a fresh small alpine image and doesnt contain all the bulky build tooling that the golang image does

1225634056465678300


zaydekPRO

a year ago

But how do you build Go then?


a year ago

you do that under the first FROM golang image


zaydekPRO

a year ago

Oh you're saying basically the same as the script I'm using just without the Postgres step?


zaydekPRO

a year ago

Alpine + Go then just Alpine?


a year ago

no you still need postgres installed, since you still want pg_dump


zaydekPRO

a year ago

Sorry I mean for another script where I want fast as possible deploys and there's no pg_dump involved


a year ago

ah then yes


zaydekPRO

a year ago

That is just golang-alpine to build then alpine to run, and that is generally faster than just Railway by itself?


zaydekPRO

a year ago

I'd be really interested in like 10 second deploys


a year ago

you couldn't get down to a total of 10 seconds, my multistage builds are ~13 seconds and the publish time is ~6 seconds


a year ago

you dont get build caching like you do using nixpacks, but you skip installing all the nix stuff so its still generally faster in my experience


zaydekPRO

a year ago

OK so your fastest deploys are like 20-30 seconds?


a year ago

yeah but theres still the switch over time when railway tries to do the zero downtime deploys


zaydekPRO

a year ago

Gotcha OK thanks for the help I'll close this out


zaydekPRO

a year ago

Thank you


a year ago

please dont close threads


zaydekPRO

a year ago

Ah just leave it?


a year ago

yeah


zaydekPRO

a year ago

<:salute:1137099685417451530>


a year ago

and you still closed it anyway 😆


zaydekPRO

a year ago

Did I? I didn't press anything