From c107733addb9e259fd3ee53bd0332c0948332ab0 Mon Sep 17 00:00:00 2001 From: Aditya Siregar Date: Mon, 1 Sep 2025 16:20:27 +0700 Subject: [PATCH] Update --- Dockerfile | 45 +++++++++++---------------------------------- deployment.sh | 2 +- 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/Dockerfile b/Dockerfile index c0762aa..3313af6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,43 +1,20 @@ -# ========================= -# 3) Production runtime -# ========================= +# 1) Build stage +FROM golang:1.21-alpine AS build +RUN apk --no-cache add ca-certificates tzdata git curl +WORKDIR /src +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /out/app ./cmd/server + +# 2) Production stage FROM debian:bullseye-slim AS production - -# Install only minimal runtime deps -RUN apt-get update && apt-get install -y \ - ca-certificates \ - tzdata \ - curl \ - && rm -rf /var/lib/apt/lists/* - -# Create non-root user +RUN apt-get update && apt-get install -y ca-certificates tzdata curl && rm -rf /var/lib/apt/lists/* RUN groupadd -r appuser && useradd -r -g appuser appuser - -# Copy app binary from build COPY --from=build /out/app /app - -# Copy infra/config files (if your app reads config/templates from here) -COPY --from=migration /src/infra /infra - -# Optionally copy migrations and migrate binary so you can run migrations -COPY --from=migration /go/bin/migrate /usr/local/bin/migrate -COPY --from=migration /src/migrations /migrations - -# Permissions -RUN chown -R appuser:appuser /app /infra /migrations - -# Env & timezone ENV TZ=Asia/Jakarta - -# Network EXPOSE 3300 - -# Healthcheck HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \ CMD curl -fsS http://localhost:3300/health || exit 1 - -# Drop privileges USER appuser - -# Default entrypoint -> run the server ENTRYPOINT ["/app"] diff --git a/deployment.sh b/deployment.sh index 5eebf56..0ef1022 100644 --- a/deployment.sh +++ b/deployment.sh @@ -2,7 +2,7 @@ set -euo pipefail APP_NAME="apskel-pos" -PORT="3300" # match the app’s listen port (and EXPOSE/healthcheck) +PORT="3300" echo "🔄 Pulling latest code..." git pull