This commit is contained in:
Aditya Siregar 2025-09-01 16:20:27 +07:00
parent 4c6dc5c8b4
commit c107733add
2 changed files with 12 additions and 35 deletions

View File

@ -1,43 +1,20 @@
# ========================= # 1) Build stage
# 3) Production runtime 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 FROM debian:bullseye-slim AS production
RUN apt-get update && apt-get install -y ca-certificates tzdata curl && rm -rf /var/lib/apt/lists/*
# 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 groupadd -r appuser && useradd -r -g appuser appuser RUN groupadd -r appuser && useradd -r -g appuser appuser
# Copy app binary from build
COPY --from=build /out/app /app 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 ENV TZ=Asia/Jakarta
# Network
EXPOSE 3300 EXPOSE 3300
# Healthcheck
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \ HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -fsS http://localhost:3300/health || exit 1 CMD curl -fsS http://localhost:3300/health || exit 1
# Drop privileges
USER appuser USER appuser
# Default entrypoint -> run the server
ENTRYPOINT ["/app"] ENTRYPOINT ["/app"]

View File

@ -2,7 +2,7 @@
set -euo pipefail set -euo pipefail
APP_NAME="apskel-pos" APP_NAME="apskel-pos"
PORT="3300" # match the apps listen port (and EXPOSE/healthcheck) PORT="3300"
echo "🔄 Pulling latest code..." echo "🔄 Pulling latest code..."
git pull git pull