Template
1
0
Fork 0

Docker optimizations and cleanup

This commit is contained in:
Atridad Lahiji 2024-11-03 16:06:21 -06:00
parent f1be386e8b
commit 9dad47b960
Signed by: atridad
SSH key fingerprint: SHA256:LGomp8Opq0jz+7kbwNcdfTcuaLRb5Nh0k5AchDDb438
2 changed files with 19 additions and 5 deletions

View file

@ -3,6 +3,11 @@
**/airbin
**/tmp
**/*.rdb
.git
.gitignore
.dockerignore
Dockerfile
README.md
stylegen
fly.toml
tailwind.config.*.js
tailwind.config.*.js

View file

@ -1,17 +1,26 @@
FROM golang:1.23.2-alpine AS build
FROM golang:1.23.2-alpine AS builder
WORKDIR /app
# Download dependencies
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o /go/bin/app
# Install UPX
RUN apk add --no-cache upx
# Build with optimizations
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags='-s -w -extldflags "-static"' \
-tags netgo,osusergo \
-o /go/bin/app
# Final stage
FROM scratch
COPY --from=build /go/bin/app /app
COPY --from=builder /go/bin/app /app
ENTRYPOINT ["/app"]