R
Railway•11mo ago
Mopsican

How to find Service ID - Docker Cache Mounts

Hi, how can i find my service id? I have cache mounts in my dockerfile, and railway wants me to provide an id, which I've been told is supposed to be my service id.
18 Replies
Percy
Percy•11mo ago
Project ID: N/A
Fragly
Fragly•11mo ago
You can find your service ID in the URL when you go to your service railway.app/project/PROJECT_ID/service/SERVICE_ID
Mopsican
Mopsican•11mo ago
thanks
Fragly
Fragly•11mo ago
happy to help 🙂
Mopsican
Mopsican•11mo ago
sorry, i'm now getting Cache mount ID is not prefixed with cache key offending code RUN --mount=type=cache,id=<service_id>,target=/go/pkg/mod/ \
Brody
Brody•11mo ago
RUN --mount=type=cache,id=s/<service id>-/root/cache/go-build,target=/root/.cache/go-build go mod download
RUN --mount=type=cache,id=s/<service id>-/root/cache/go-build,target=/root/.cache/go-build go mod download
same for go build
Mopsican
Mopsican•11mo ago
It's now throwing: Invalid cache mounts However, it still works locally. full example RUN --mount=type=cache,id=s/<service_id>/root/cache/go-build,target=/root/.cache/go-build \ --mount=type=bind,source=go.sum,target=go.sum \ --mount=type=bind,source=go.mod,target=go.mod \ go mod download -x do i need to change the targets?
Brody
Brody•11mo ago
please try with the exact line I gave before you start modifying it
Mopsican
Mopsican•11mo ago
ok, it's just i need to use RUN --mount=type=cache,id=s/<service_id>/root/cache/go-build,target=/root/.cache/go-build \ apk --update add \ ca-certificates \ tzdata \ && \ update-ca-certificates and RUN --mount=type=cache,id=s/<service_id>/root/cache/go-build,target=/root/.cache/go-build \ --mount=type=bind,target=. \ CGO_ENABLED=0 GOARCH=$TARGETARCH go build -o /bin/server ./ as well #11 0.400 go: no modules specified (see 'go help mod download') it doesn't seem to like bind mounts
Brody
Brody•11mo ago
are you making sure to copy in your go.mod and go.sum files before running go mod download? yes so don't use them lol how about you send your current dockerfile? I've only ever used my own dockerfiles that don't use mount catches and build time is always somewhere around 10 or 15 seconds for the entire build
Mopsican
Mopsican•11mo ago
ARG GO_VERSION=1.21.5
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS build
WORKDIR /src
ARG TARGETARCH
FROM alpine:latest AS final
RUN mkdir -p home/index/
WORKDIR /home/
COPY go.mod go.sum ./
RUN go mod download
RUN --mount=type=cache,id=s/957287b0-89b6-4e31-9e44-84402206d00b-/root/cache/go-build,target=/root/.cache/go-build go build
RUN cd /home
COPY --from=build /bin/server /bin/
EXPOSE 8000
ENTRYPOINT [ "/bin/server" ]
ARG GO_VERSION=1.21.5
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS build
WORKDIR /src
ARG TARGETARCH
FROM alpine:latest AS final
RUN mkdir -p home/index/
WORKDIR /home/
COPY go.mod go.sum ./
RUN go mod download
RUN --mount=type=cache,id=s/957287b0-89b6-4e31-9e44-84402206d00b-/root/cache/go-build,target=/root/.cache/go-build go build
RUN cd /home
COPY --from=build /bin/server /bin/
EXPOSE 8000
ENTRYPOINT [ "/bin/server" ]
Brody
Brody•11mo ago
please enclose it in triple backticks looks kinda overly complex tbh
Mopsican
Mopsican•11mo ago
maybe, i just need to get the exe, mod and sum + the last 2 lines
Brody
Brody•11mo ago
exe huh?
Mopsican
Mopsican•11mo ago
i mean get the build
Brody
Brody•11mo ago
FROM golang:1.21.5 AS build

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY . ./

RUN go build -o main

FROM alpine:latest

WORKDIR /app

COPY --from=build /app/main ./

ENTRYPOINT ["/app/main"]
FROM golang:1.21.5 AS build

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY . ./

RUN go build -o main

FROM alpine:latest

WORKDIR /app

COPY --from=build /app/main ./

ENTRYPOINT ["/app/main"]
keep it simple
Mopsican
Mopsican•11mo ago
thanks managed to do it, just needed to copy local packages and files as well
FROM golang:1.21.5 AS build

WORKDIR /blog

COPY go.mod go.sum ./
COPY ./shared/ ./shared/
COPY ./tem/ ./tem/
RUN go mod download

COPY ./blogPosts/ ./blogPosts/
COPY *.go ./
RUN go get ./shared/
RUN go get ./tem/
RUN go install
RUN ls *


RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main


FROM alpine:latest as final

WORKDIR /blog

COPY --from=build /blog/main ./
COPY --from=build /blog/blogPosts ./blogPosts/

ENTRYPOINT ["/blog/main"]
FROM golang:1.21.5 AS build

WORKDIR /blog

COPY go.mod go.sum ./
COPY ./shared/ ./shared/
COPY ./tem/ ./tem/
RUN go mod download

COPY ./blogPosts/ ./blogPosts/
COPY *.go ./
RUN go get ./shared/
RUN go get ./tem/
RUN go install
RUN ls *


RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main


FROM alpine:latest as final

WORKDIR /blog

COPY --from=build /blog/main ./
COPY --from=build /blog/blogPosts ./blogPosts/

ENTRYPOINT ["/blog/main"]
bit of a mess but it works
Brody
Brody•11mo ago
great!
Want results from more Discord servers?
Add your server