Skip to content

Commit

Permalink
feat: optimise docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
proffapt committed Jul 2, 2024
1 parent 0c27ce8 commit f366656
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
32 changes: 22 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
FROM golang:1.21
FROM golang:1.21 AS builder

# Copy metaploy configuration
COPY metaploy/heimdall.metaploy.conf /
COPY metaploy/postinstall.sh /
WORKDIR /src

COPY go.mod go.sum ./

RUN go mod download

COPY mail.go main.go ./

RUN CGO_ENABLED=1 GOOS=linux go build -o ./heimdall --tags "fts5" -a -ldflags '-linkmode external -extldflags "-static"' .

FROM alpine:latest AS app

ENV TZ="Asia/Kolkata"

RUN apk --no-cache add ca-certificates tzdata nginx bash

# Copy source files
WORKDIR /
COPY go.mod go.sum main.go mail.go /

# Build go package
RUN go build
COPY metaploy/heimdall.metaploy.conf metaploy/postinstall.sh ./

RUN chmod +x ./postinstall.sh

COPY --from=builder /src/heimdall .

# Run postinstall script and the binary
CMD ["/postinstall.sh", "/heimdall"]
CMD ["./postinstall.sh", "./heimdall"]
8 changes: 2 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ services:
container_name: heimdall
build: .
restart: always
environment:
- JWT_SECRET_KEY=${JWT_SECRET_KEY}
- OTP_VALIDITY_PERIOD=${OTP_VALIDITY_PERIOD}
- RESEND_OTP_COOLDOWN=${RESEND_OTP_COOLDOWN}
- JWT_EXPIRY_DAYS=${JWT_EXPIRY_DAYS}

env_file:
- .env
networks:
metaploy-network:
aliases:
Expand Down

0 comments on commit f366656

Please sign in to comment.