Skip to content

Commit a3ed564

Browse files
committed
fix docker build
1 parent e9add6f commit a3ed564

3 files changed

Lines changed: 17 additions & 28 deletions

File tree

.github/workflows/docker-release.yml

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ on:
44
push:
55
branches: [ main ]
66
# tags: [ 'v*' ]
7-
pull_request:
8-
branches: [ main ]
97

108
env:
119
REGISTRY: ghcr.io
@@ -24,8 +22,6 @@ jobs:
2422

2523
- name: Set up Docker Buildx
2624
uses: docker/setup-buildx-action@v3
27-
with:
28-
version: latest
2925

3026
- name: Log in to GitHub Container Registry
3127
uses: docker/login-action@v3
@@ -41,7 +37,7 @@ jobs:
4137
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
4238
tags: |
4339
type=ref,event=branch
44-
type=ref,event=pr
40+
type=ref,event=tag
4541
type=semver,pattern={{version}}
4642
type=semver,pattern={{major}}.{{minor}}
4743
type=semver,pattern={{major}}
@@ -52,31 +48,16 @@ jobs:
5248
with:
5349
context: .
5450
file: ./Dockerfile
55-
platforms: linux/amd64,linux/arm64
56-
push: ${{ github.event_name != 'pull_request' }}
51+
push: true
5752
tags: ${{ steps.meta.outputs.tags }}
5853
labels: ${{ steps.meta.outputs.labels }}
5954
cache-from: type=gha
6055
cache-to: type=gha,mode=max
6156

62-
- name: Run Trivy vulnerability scanner
63-
uses: aquasecurity/trivy-action@master
64-
with:
65-
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
66-
format: 'sarif'
67-
output: 'trivy-results.sarif'
68-
69-
- name: Upload Trivy scan results
70-
uses: github/codeql-action/upload-sarif@v2
71-
with:
72-
sarif_file: 'trivy-results.sarif'
73-
if: always()
74-
75-
# Separate job for testing the Docker image
7657
test-docker:
7758
runs-on: ubuntu-latest
7859
needs: build-and-push
79-
if: github.event_name != 'pull_request'
60+
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
8061

8162
steps:
8263
- name: Test Docker image

DOCKER_README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,10 @@ The GitHub Actions workflow builds for both `linux/amd64` and `linux/arm64` arch
7777
- Minimal Alpine base image
7878
- Health checks built-in
7979
- Built with security scanning via Trivy
80+
81+
## Build Notes
82+
83+
- CGO disabled for better portability
84+
- Uses system users/groups for container security
85+
- CA certificates updated in final image
86+
- Health check uses shell command format for reliability

Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Multi-stage build for xcstrings-translator
2-
FROM golang:1.25-alpine AS builder
2+
FROM golang:1.21-alpine AS builder
33

44
# Install build dependencies
55
RUN apk add --no-cache \
@@ -18,19 +18,20 @@ RUN go mod download
1818
COPY . .
1919

2020
# Build the application
21-
RUN go build -o bin/xcstrings-translator .
21+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o bin/xcstrings-translator .
2222

2323
# Final stage - minimal Alpine image
2424
FROM alpine:latest
2525

2626
# Install runtime dependencies
2727
RUN apk --no-cache add \
2828
ca-certificates \
29-
tzdata
29+
tzdata \
30+
&& update-ca-certificates
3031

3132
# Create non-root user
32-
RUN addgroup -g 65532 nonroot && \
33-
adduser -D -u 65532 -G nonroot nonroot
33+
RUN addgroup -g 65532 --system nonroot && \
34+
adduser -D -u 65532 -G nonroot --system nonroot
3435

3536
# Copy the binary from builder stage
3637
COPY --from=builder /app/bin/xcstrings-translator /usr/local/bin/xcstrings-translator
@@ -49,7 +50,7 @@ USER nonroot:nonroot
4950

5051
# Health check
5152
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
52-
CMD xcstrings-translator --help || exit 1
53+
CMD ["sh", "-c", "xcstrings-translator --help"]
5354

5455
# Default command
5556
ENTRYPOINT ["xcstrings-translator"]

0 commit comments

Comments
 (0)