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 df885ae
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
34 changes: 23 additions & 11 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 source files
WORKDIR /
COPY go.mod go.sum main.go mail.go /
COPY go.mod go.sum ./

# Build go package
RUN go build
RUN go mod download

# Run postinstall script and the binary
CMD ["/postinstall.sh", "/heimdall"]
COPY mail.go main.go ./

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

FROM alpine:latest as app

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

ENV TZ="Asia/Kolkata"

WORKDIR /app

COPY metaploy/ ./

RUN chmod +x ./postinstall.sh

COPY --from=builder /src/build .

CMD ["./postinstall.sh", "./build"]
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
8 changes: 3 additions & 5 deletions metaploy/postinstall.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#!/bin/bash

cleanup() {
echo "Container stopped. Removing nginx configuration."
rm /etc/nginx/sites-enabled/heimdall.metaploy.conf
echo "Container stopped. Removing nginx configuration."
rm /etc/nginx/sites-enabled/heimdall.metaploy.conf
}

trap 'cleanup' SIGQUIT SIGTERM SIGHUP

"${@}" &

cp /heimdall.metaploy.conf /etc/nginx/sites-enabled
cp ./heimdall.metaploy.conf /etc/nginx/sites-enabled

wait $!

echo "lmao"

0 comments on commit df885ae

Please sign in to comment.