all repos

onasty @ 35d2b54766347ebbc4d3f1e3f1cccf535c140659

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
        9
         COPY internal internal

      
        10
        10
         

      
        11
        11
         ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64

      
        12
        
        -RUN --mount=type=cache,target=/root/.cache/go-build \

      
        13
        
        -    --mount=type=cache,target=/go/pkg/mod \

      
        
        12
        +RUN --mount=type=cache,target=/root/.cache/go-build,id=onasty-go-build \

      
        
        13
        +    --mount=type=cache,target=/go/pkg/mod,id=onasty-go-mod \

      
        14
        14
             go build -trimpath -ldflags='-w -s' -o /onasty ./cmd/server

      
        15
        15
         

      
        16
        
        -FROM alpine:3.21

      
        
        16
        +FROM onasty:runtime

      
        17
        17
         COPY --from=builder /onasty /onasty

      
        18
        
        -RUN apk --no-cache add ca-certificates

      
        19
        18
         ENTRYPOINT ["/onasty"]

      
M docker-compose.yml
···
        1
        1
         services:

      
        
        2
        +  runtime:

      
        
        3
        +    image: onasty:runtime

      
        
        4
        +    build:

      
        
        5
        +      context: .

      
        
        6
        +      dockerfile: runtime.dockerfile

      
        
        7
        +

      
        2
        8
           core:

      
        3
        9
             image: onasty:core

      
        4
        10
             container_name: onasty-core

      ···
        9
        15
             ports:

      
        10
        16
               - 8000:8000

      
        11
        17
               - 8001:8001

      
        
        18
        +    depends_on:

      
        
        19
        +      - runtime

      
        
        20
        +      - mailer

      
        
        21
        +      - postgres

      
        
        22
        +      - redis

      
        
        23
        +      - nats

      
        12
        24
         

      
        13
        25
           mailer:

      
        14
        26
             image: onasty:mailer

      ···
        17
        29
               context: .

      
        18
        30
               dockerfile: ./mailer/Dockerfile

      
        19
        31
             env_file: ./mailer/.env

      
        
        32
        +    depends_on:

      
        
        33
        +      - runtime

      
        
        34
        +      - nats

      
        20
        35
         

      
        21
        36
           postgres:

      
        22
        37
             image: postgres:16-alpine

      
M mailer/Dockerfile
···
        9
        9
         COPY mailer mailer

      
        10
        10
         

      
        11
        11
         ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64

      
        12
        
        -RUN --mount=type=cache,target=/root/.cache/go-build \

      
        13
        
        -    --mount=type=cache,target=/go/pkg/mod \

      
        
        12
        +RUN --mount=type=cache,target=/root/.cache/go-build,id=onasty-go-build \

      
        
        13
        +    --mount=type=cache,target=/go/pkg/mod,id=onasty-go-mod \

      
        14
        14
             go build -trimpath -ldflags='-w -s' -o /mailer ./mailer

      
        15
        15
         

      
        16
        
        -FROM alpine:3.21

      
        
        16
        +FROM onasty:runtime

      
        17
        17
         COPY --from=builder /mailer /mailer

      
        18
        
        -RUN apk --no-cache add ca-certificates

      
        19
        18
         ENTRYPOINT ["/mailer"]

      
A runtime.dockerfile
···
        
        1
        +FROM alpine:3.21

      
        
        2
        +RUN apk --no-cache add ca-certificates