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"]
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
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
a year ago
although you dont need to edge anymore, postgresql16-client is now on 3.19
a year ago
yeah but only the setup stuff would be used
a year ago
yeah you can still use the deploy stuff in a railway.toml file with a dockerfile
a year ago
no problem, let me know if that works for you
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"]
a year ago
its still using nixpacks, make sure your Dockerfile is named correctly
Sorry virtualized scrolling I updated it https://gist.github.com/zaydek/9c58021b66941ab1ce94426fd982a594
a year ago
set the root directory in the service settings
a year ago
explain what you mean by that please
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
a year ago
exactly
a year ago
awsome
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"]
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
OK so use Railway as is, then lean into Nix if you can, and finally use Docker if you have to?
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
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
a year ago
you do that under the first FROM
golang image
Oh you're saying basically the same as the script I'm using just without the Postgres step?
a year ago
no you still need postgres installed, since you still want pg_dump
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
That is just golang-alpine to build then alpine to run, and that is generally faster than just Railway by itself?
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
a year ago
yeah but theres still the switch over time when railway tries to do the zero downtime deploys
a year ago
please dont close threads
a year ago
yeah
a year ago
and you still closed it anyway 😆