diff --git a/Dockerfile b/Dockerfile index aac3f34..63dd831 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] \ No newline at end of file +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"] diff --git a/docker-compose.yml b/docker-compose.yml index a6e1152..1a75f9b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: diff --git a/metaploy/postinstall.sh b/metaploy/postinstall.sh index 01fcba4..9f56742 100755 --- a/metaploy/postinstall.sh +++ b/metaploy/postinstall.sh @@ -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"