add docker
Some checks failed
CI/CD / Vet, test, build (push) Has been cancelled
CI/CD / Docker image (push) Has been cancelled
CI/CD / Deploy binary to server (push) Has been cancelled

This commit is contained in:
2026-10-23 00:39:04 +05:00
parent 965b00dba5
commit e5f01d0e94
16 changed files with 463 additions and 52 deletions

View File

@@ -1,30 +1,39 @@
#!/bin/ash
# Specifies a parent image
# Offline build: nothing in this file touches the network.
# - Go modules come from the committed vendor/ directory.
# - The runtime stage is postgres:14.1-alpine, the same image main-db uses,
# so pg_dump (backups), tzdata and CA certificates are already there and no
# `apk add` is needed. Its layers are shared with main-db on the server.
# The server only needs the base images loaded once (see `make docker-bundle`).
#
# No "# syntax=" directive on purpose: it makes BuildKit pull a frontend image.
FROM golang:1.26.4-alpine AS builder
# Creates an app directory to hold your app’s source code
WORKDIR /build
# Installs Go dependencies
COPY go.mod ./
COPY go.sum ./
RUN go mod download
ENV CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64 \
GOFLAGS=-mod=vendor \
GOPROXY=off
COPY . .
# Builds your app with optional configuration
RUN GOARCH=amd64 GOOS=linux go build -o myapp ./app.go
RUN go build -trimpath -ldflags="-s -w" -o myapp ./app.go
FROM scratch
FROM postgres:14.1-alpine
WORKDIR /app/
# Fresher CA bundle than the 2021 one in postgres:14.1-alpine (HTTPS to mpi.gov.tm).
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
WORKDIR /app
COPY --from=builder /build/myapp .
COPY --from=builder /build/config.yaml .
# Tells Docker which network port your container listens on
# config.yaml is mounted at runtime (see docker-compose.yaml), not baked in.
RUN mkdir -p /app/public/images /app/public/backups /app/logs
EXPOSE 5050
#ENTRYPOINT ["/app/myapp"]
CMD ["/app/myapp"]
# Replaces the postgres docker-entrypoint.sh inherited from the base image.
ENTRYPOINT ["/app/myapp"]