File tree Expand file tree Collapse file tree 2 files changed +78
-0
lines changed
Expand file tree Collapse file tree 2 files changed +78
-0
lines changed Original file line number Diff line number Diff line change 1+ name : CI - Build and Publish Container
2+
3+ on :
4+ push :
5+ branches : [ main ]
6+ pull_request :
7+ branches : [ main ]
8+
9+ jobs :
10+ build-and-push :
11+ runs-on : ubuntu-latest
12+ permissions :
13+ contents : read
14+ packages : write
15+ id-token : write
16+
17+ steps :
18+ - name : Checkout
19+ uses : actions/checkout@v4
20+
21+ - name : Set up Docker Buildx
22+ uses : docker/setup-buildx-action@v2
23+
24+ - name : Login to GitHub Container Registry
25+ uses : docker/login-action@v2
26+ with :
27+ registry : ghcr.io
28+ username : ${{ github.actor }}
29+ password : ${{ secrets.GITHUB_TOKEN }}
30+
31+ - name : Determine image tags
32+ id : tags
33+ run : |
34+ SHORT_SHA=${GITHUB_SHA::8}
35+ IMAGE=ghcr.io/${GITHUB_REPOSITORY_OWNER}/${GITHUB_REPOSITORY##*/}
36+ # Default tag is sha
37+ echo "tags=${IMAGE}:sha-${SHORT_SHA}" >> $GITHUB_OUTPUT
38+
39+ if [[ "$GITHUB_REF" == refs/tags/* ]]; then
40+ TAG_NAME=${GITHUB_REF#refs/tags/}
41+ echo "tags=${IMAGE}:sha-${SHORT_SHA},${IMAGE}:${TAG_NAME}" >> $GITHUB_OUTPUT
42+ elif [[ "$GITHUB_REF" == refs/heads/main ]]; then
43+ echo "tags=${IMAGE}:sha-${SHORT_SHA},${IMAGE}:latest" >> $GITHUB_OUTPUT
44+ else
45+ # sanitize branch name: replace / with - and remove non-alphanum ._- characters
46+ BRANCH=${GITHUB_REF#refs/heads/}
47+ SAFE_BRANCH=$(echo "$BRANCH" | sed 's#[^A-Za-z0-9._-]#-#g')
48+ echo "tags=${IMAGE}:sha-${SHORT_SHA},${IMAGE}:${SAFE_BRANCH}" >> $GITHUB_OUTPUT
49+ fi
50+
51+ - name : Build and push
52+ uses : docker/build-push-action@v4
53+ with :
54+ context : .
55+ file : Containerfile
56+ platforms : linux/amd64
57+ push : true
58+ tags : ${{ steps.tags.outputs.tags }}
Original file line number Diff line number Diff line change 1+ # Multi-stage build for matrix2acrobits
2+ FROM golang:1.24.10-alpine AS builder
3+ WORKDIR /src
4+
5+ # Cache go mod
6+ COPY go.mod go.sum ./
7+ RUN go env -w GOPROXY=https://proxy.golang.org && go mod download
8+
9+ # Copy source and build
10+ COPY . .
11+ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
12+ go build -ldflags='-s -w' -o /out/matrix2acrobits ./main.go
13+
14+ FROM gcr.io/distroless/static:nonroot
15+ COPY --from=builder /out/matrix2acrobits /usr/local/bin/matrix2acrobits
16+
17+ EXPOSE 8080
18+
19+ USER nonroot:nonroot
20+ ENTRYPOINT ["/usr/local/bin/matrix2acrobits" ]
You can’t perform that action at this time.
0 commit comments