Skip to content

Commit a5bf297

Browse files
authored
Merge pull request #32 from safedep/chore/docker-add-release-container
chore: Add container release workflow
2 parents fb7840b + d18633d commit a5bf297

3 files changed

Lines changed: 138 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,27 @@ jobs:
3333
uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # v5
3434
with:
3535
token: ${{ secrets.CODECOV_TOKEN }}
36+
37+
build-container-test:
38+
runs-on: ubuntu-latest
39+
timeout-minutes: 15
40+
steps:
41+
- name: Checkout Source
42+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
43+
44+
- name: Setup QEMU
45+
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3
46+
47+
- name: Setup Docker Buildx
48+
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3
49+
50+
- name: Build Multi-Platform Container Image (verification only)
51+
run: |
52+
docker buildx build --platform linux/amd64,linux/arm64 \
53+
-t build-container-test:latest .
54+
55+
- name: Build and Load Native Platform Image for Testing
56+
run: |
57+
docker buildx build --platform linux/amd64 --load \
58+
-t build-container-test:latest .
59+

.github/workflows/container.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Container Image Releaser
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
branches:
8+
- "main"
9+
10+
concurrency: ci-container-release
11+
12+
permissions:
13+
contents: read
14+
15+
env:
16+
REGISTRY: ghcr.io
17+
IMAGE_NAME: ${{ github.repository }}
18+
19+
jobs:
20+
build:
21+
if: "!contains(github.event.commits[0].message, '[noci]')"
22+
timeout-minutes: 30
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: read
26+
packages: write
27+
id-token: write
28+
29+
steps:
30+
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744
31+
with:
32+
submodules: true
33+
fetch-depth: 0
34+
35+
- name: Registry Login
36+
uses: docker/login-action@dd4fa0671be5250ee6f50aedf4cb05514abda2c7
37+
with:
38+
registry: ${{ env.REGISTRY }}
39+
username: ${{ github.actor }}
40+
password: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Setup QEMU
43+
uses: docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7
44+
45+
- name: Setup Docker Buildx
46+
uses: docker/setup-buildx-action@885d1462b80bc1c1c7f0b00334ad271f09369c55
47+
48+
- name: Build and Push Container Image
49+
run: |
50+
# Get the tag if this was a tag push event
51+
if [[ "${{ github.ref_type }}" == "tag" ]]; then
52+
TAG=${{ github.ref_name }}
53+
# Validate tag format (must be vX.Y.Z)
54+
if [[ $TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
55+
# Build and push with both version tag and latest
56+
docker buildx build --push --platform linux/amd64,linux/arm64 \
57+
-t $REGISTRY/$IMAGE_NAME:$TAG \
58+
-t $REGISTRY/$IMAGE_NAME:latest \
59+
.
60+
else
61+
echo "Invalid tag format. Must be in format vX.Y.Z (e.g. v1.2.3)"
62+
exit 1
63+
fi
64+
else
65+
# For non-tag pushes, just use latest tag
66+
docker buildx build --push --platform linux/amd64,linux/arm64 \
67+
-t $REGISTRY/$IMAGE_NAME:latest \
68+
.
69+
fi
70+
71+

Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
FROM --platform=$BUILDPLATFORM golang:1.24.3-bullseye AS build
2+
3+
WORKDIR /build
4+
5+
# Install cross-compilation tools
6+
RUN apt-get update && apt-get install -y --no-install-recommends \
7+
gcc-aarch64-linux-gnu \
8+
libc6-dev-arm64-cross \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
COPY go.mod go.sum ./
12+
13+
RUN go mod download
14+
15+
COPY . .
16+
17+
ARG TARGETPLATFORM
18+
ENV CGO_ENABLED=1
19+
20+
# Set up cross-compilation environment based on target platform
21+
RUN case "${TARGETPLATFORM}" in \
22+
"linux/amd64") \
23+
CC=gcc CXX=g++ GOOS=linux GOARCH=amd64 make ;; \
24+
"linux/arm64") \
25+
CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ GOOS=linux GOARCH=arm64 make ;; \
26+
*) echo "Unsupported platform: ${TARGETPLATFORM}" && exit 1 ;; \
27+
esac
28+
29+
FROM debian:11-slim
30+
31+
RUN apt-get update && apt-get install -y --no-install-recommends \
32+
ca-certificates \
33+
&& rm -rf /var/lib/apt/lists/*
34+
35+
ARG TARGETPLATFORM
36+
37+
LABEL org.opencontainers.image.source=https://github.com/safedep/xbom
38+
LABEL org.opencontainers.image.description="xbom is a tool to generate a Software Bill of Materials (SBOM) enriched with application metadata using static code analysis."
39+
LABEL org.opencontainers.image.licenses=Apache-2.0
40+
41+
COPY --from=build /build/bin/xbom /usr/local/bin/xbom
42+
43+
ENTRYPOINT ["xbom"]

0 commit comments

Comments
 (0)