Skip to content

Commit c731d41

Browse files
committed
Add GitHub Actions for Docker image publishing to ghcr.io/sirosfoundation
- Add docker-publish.yml workflow for building and pushing images - Add multi-stage Dockerfile for containerized builds - Update release.yml with packages permission and ghcr.io login - Update goreleaser config to use sirosfoundation org - Remove Dockerfile from .gitignore
1 parent 7ebd930 commit c731d41

File tree

5 files changed

+122
-8
lines changed

5 files changed

+122
-8
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Build and Publish Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v*'
9+
pull_request:
10+
branches:
11+
- main
12+
13+
env:
14+
REGISTRY: ghcr.io
15+
IMAGE_NAME: sirosfoundation/go-trust
16+
17+
jobs:
18+
build-and-push:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
packages: write
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
28+
- name: Set up QEMU
29+
uses: docker/setup-qemu-action@v3
30+
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v3
33+
34+
- name: Log in to Container Registry
35+
if: github.event_name != 'pull_request'
36+
uses: docker/login-action@v3
37+
with:
38+
registry: ${{ env.REGISTRY }}
39+
username: ${{ github.actor }}
40+
password: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Extract metadata (tags, labels) for Docker
43+
id: meta
44+
uses: docker/metadata-action@v5
45+
with:
46+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
47+
tags: |
48+
type=ref,event=branch
49+
type=ref,event=pr
50+
type=semver,pattern={{version}}
51+
type=semver,pattern={{major}}.{{minor}}
52+
type=semver,pattern={{major}}
53+
type=sha,prefix=
54+
type=raw,value=latest,enable={{is_default_branch}}
55+
56+
- name: Build and push Docker image
57+
uses: docker/build-push-action@v5
58+
with:
59+
context: .
60+
file: ./Dockerfile
61+
platforms: linux/amd64,linux/arm64
62+
push: ${{ github.event_name != 'pull_request' }}
63+
tags: ${{ steps.meta.outputs.tags }}
64+
labels: ${{ steps.meta.outputs.labels }}
65+
cache-from: type=gha
66+
cache-to: type=gha,mode=max

.github/workflows/release.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,33 @@ on:
77

88
permissions:
99
contents: write
10+
packages: write
1011

1112
jobs:
1213
release:
1314
name: Create Release
1415
runs-on: ubuntu-latest
1516

1617
steps:
17-
- uses: actions/checkout@v3
18+
- uses: actions/checkout@v4
1819
with:
1920
fetch-depth: 0
2021

2122
- name: Set up Go
22-
uses: actions/setup-go@v4
23+
uses: actions/setup-go@v5
2324
with:
24-
go-version: '1.20'
25+
go-version: '1.23'
2526
cache: true
2627

28+
- name: Log in to Container Registry
29+
uses: docker/login-action@v3
30+
with:
31+
registry: ghcr.io
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
2735
- name: Run GoReleaser
28-
uses: goreleaser/goreleaser-action@v4
36+
uses: goreleaser/goreleaser-action@v6
2937
with:
3038
distribution: goreleaser
3139
version: latest
@@ -34,7 +42,7 @@ jobs:
3442
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3543

3644
- name: Upload artifacts
37-
uses: actions/upload-artifact@v3
45+
uses: actions/upload-artifact@v4
3846
with:
3947
name: binaries
4048
path: dist/*

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ testdata/postgres
4040
bin/
4141
dist/
4242
build/
43-
Dockerfile
4443

4544
# Temporary files
4645
tmp/

.goreleaser.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ changelog:
5050

5151
dockers:
5252
- image_templates:
53-
- "ghcr.io/sunet/{{ .ProjectName }}:{{ .Version }}"
54-
- "ghcr.io/sunet/{{ .ProjectName }}:latest"
53+
- "ghcr.io/sirosfoundation/{{ .ProjectName }}:{{ .Version }}"
54+
- "ghcr.io/sirosfoundation/{{ .ProjectName }}:latest"
5555
dockerfile: Dockerfile.goreleaser
5656
build_flag_templates:
5757
- "--label=org.opencontainers.image.created={{.Date}}"

Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Build stage
2+
FROM golang:1.23-alpine AS builder
3+
4+
WORKDIR /app
5+
6+
# Install git for fetching dependencies with replace directives
7+
RUN apk add --no-cache git ca-certificates
8+
9+
# Copy go mod files
10+
COPY go.mod go.sum ./
11+
RUN go mod download
12+
13+
# Copy source code
14+
COPY . .
15+
16+
# Build with version information
17+
ARG VERSION=dev
18+
ARG COMMIT=unknown
19+
ARG BUILD_DATE=unknown
20+
21+
RUN CGO_ENABLED=0 GOOS=linux go build \
22+
-ldflags="-s -w -X github.com/sirosfoundation/go-trust/pkg/version.Version=${VERSION} -X github.com/sirosfoundation/go-trust/pkg/version.Commit=${COMMIT} -X github.com/sirosfoundation/go-trust/pkg/version.Date=${BUILD_DATE}" \
23+
-o gt ./main.go
24+
25+
# Runtime stage - using distroless for minimal attack surface
26+
FROM gcr.io/distroless/static-debian12
27+
28+
WORKDIR /app
29+
30+
# Copy binary from builder
31+
COPY --from=builder /app/gt /app/gt
32+
33+
# Copy example configuration (optional, can be overridden at runtime)
34+
COPY --from=builder /app/example /app/example
35+
36+
USER nonroot:nonroot
37+
38+
EXPOSE 8080
39+
40+
ENTRYPOINT ["/app/gt"]
41+
CMD ["serve"]

0 commit comments

Comments
 (0)