File tree Expand file tree Collapse file tree 2 files changed +100
-0
lines changed
Expand file tree Collapse file tree 2 files changed +100
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Build and Push Docker Image
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+
8+ env :
9+ REGISTRY : ghcr.io
10+ IMAGE_NAME : bcc-code/wayfarer
11+
12+ jobs :
13+ test :
14+ name : Run Tests
15+ runs-on : ubuntu-latest
16+ defaults :
17+ run :
18+ working-directory : backend
19+ steps :
20+ - name : Checkout code
21+ uses : actions/checkout@v4
22+
23+ - name : Set up Go
24+ uses : actions/setup-go@v5
25+ with :
26+ go-version : ' 1.25'
27+
28+ - name : Run unit tests
29+ run : make test
30+
31+ build-and-push :
32+ name : Build and Push Docker Image
33+ needs : test
34+ runs-on : ubuntu-latest
35+ permissions :
36+ contents : read
37+ packages : write
38+ steps :
39+ - name : Checkout code
40+ uses : actions/checkout@v4
41+
42+ - name : Log in to GitHub Container Registry
43+ uses : docker/login-action@v3
44+ with :
45+ registry : ${{ env.REGISTRY }}
46+ username : ${{ github.actor }}
47+ password : ${{ secrets.GITHUB_TOKEN }}
48+
49+ - name : Extract metadata
50+ id : meta
51+ uses : docker/metadata-action@v5
52+ with :
53+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
54+ tags : |
55+ type=raw,value=latest
56+ type=raw,value=main
57+ type=sha,prefix=,format=short
58+
59+ - name : Build and push Docker image
60+ uses : docker/build-push-action@v5
61+ with :
62+ context : .
63+ push : true
64+ tags : ${{ steps.meta.outputs.tags }}
65+ labels : ${{ steps.meta.outputs.labels }}
Original file line number Diff line number Diff line change 1+ # Build stage
2+ FROM golang:1.25 AS builder
3+
4+ WORKDIR /build
5+
6+ # Copy dependency files
7+ COPY backend/go.mod backend/go.sum ./
8+ RUN go mod download
9+
10+ # Copy source code
11+ COPY backend/ ./
12+
13+ # Build static binary
14+ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
15+ -ldflags='-w -s -extldflags "-static"' \
16+ -o server \
17+ ./cmd/server
18+
19+ # Runtime stage
20+ FROM scratch
21+
22+ # Copy CA certificates for HTTPS
23+ COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
24+
25+ # Copy binary
26+ COPY --from=builder /build/server /server
27+
28+ # Run as non-root user
29+ USER 65534
30+
31+ # Expose API port
32+ EXPOSE 8080
33+
34+ # Run the server
35+ ENTRYPOINT ["/server" ]
You can’t perform that action at this time.
0 commit comments