all repos

onasty @ 35d2b54

a one-time notes service
4 files changed, 23 insertions(+), 8 deletions(-)
chore: improve how caching while docker builds done (#111)

* chore(docker): build its own runtime container for all services

* chore(docker): change way the go build cache handled
Author: Smirnov Oleksandr ss2316544@gmail.com
Committed by: GitHub noreply@github.com
Committed at: 2025-05-17 22:08:22 +0300
Parent: 3a159f5
M Dockerfile

@@ -9,11 +9,10 @@ COPY cmd cmd

COPY internal internal ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64 -RUN --mount=type=cache,target=/root/.cache/go-build \ - --mount=type=cache,target=/go/pkg/mod \ +RUN --mount=type=cache,target=/root/.cache/go-build,id=onasty-go-build \ + --mount=type=cache,target=/go/pkg/mod,id=onasty-go-mod \ go build -trimpath -ldflags='-w -s' -o /onasty ./cmd/server -FROM alpine:3.21 +FROM onasty:runtime COPY --from=builder /onasty /onasty -RUN apk --no-cache add ca-certificates ENTRYPOINT ["/onasty"]
M docker-compose.yml

@@ -1,4 +1,10 @@

services: + runtime: + image: onasty:runtime + build: + context: . + dockerfile: runtime.dockerfile + core: image: onasty:core container_name: onasty-core

@@ -9,6 +15,12 @@ env_file: .env

ports: - 8000:8000 - 8001:8001 + depends_on: + - runtime + - mailer + - postgres + - redis + - nats mailer: image: onasty:mailer

@@ -17,6 +29,9 @@ build:

context: . dockerfile: ./mailer/Dockerfile env_file: ./mailer/.env + depends_on: + - runtime + - nats postgres: image: postgres:16-alpine
M mailer/Dockerfile

@@ -9,11 +9,10 @@ COPY internal internal

COPY mailer mailer ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64 -RUN --mount=type=cache,target=/root/.cache/go-build \ - --mount=type=cache,target=/go/pkg/mod \ +RUN --mount=type=cache,target=/root/.cache/go-build,id=onasty-go-build \ + --mount=type=cache,target=/go/pkg/mod,id=onasty-go-mod \ go build -trimpath -ldflags='-w -s' -o /mailer ./mailer -FROM alpine:3.21 +FROM onasty:runtime COPY --from=builder /mailer /mailer -RUN apk --no-cache add ca-certificates ENTRYPOINT ["/mailer"]
A runtime.dockerfile

@@ -0,0 +1,2 @@

+FROM alpine:3.21 +RUN apk --no-cache add ca-certificates