Skip to content

Commit bc2fd15

Browse files
committed
build agent
1 parent ebfff3b commit bc2fd15

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

.github/workflows/agent.yml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
name: Build Cluster Agent v2
2+
3+
on:
4+
push:
5+
paths:
6+
- '**'
7+
paths-ignore:
8+
- 'v2/**'
9+
# Publish semver tags as releases.
10+
#tags: [ 'v*.*.*' ]
11+
pull_request:
12+
branches:
13+
- main
14+
15+
16+
env:
17+
# Use docker.io for Docker Hub if empty
18+
REGISTRY: ghcr.io
19+
# github.repository as <account>/<repo>
20+
# test
21+
IMAGE_NAME: ${{ github.repository }}-cluster-agent
22+
ROR_VERSION: v1.0.0
23+
24+
jobs:
25+
build-app:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v3
29+
30+
- name: Set up Go
31+
uses: actions/setup-go@v4
32+
with:
33+
go-version: '1.23'
34+
- name: Cache Go modules
35+
uses: actions/cache@v3
36+
with:
37+
path: |
38+
~/.cache/go-build
39+
~/go/pkg/mod
40+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
41+
restore-keys: |
42+
${{ runner.os }}-go-
43+
- name: Build
44+
run: |
45+
go get ./...
46+
mkdir -p dist/isbuilt
47+
CGO_ENABLED=0 go build -o dist/agent -ldflags "-w -extldflags '-static' -X internal/config.version=$ROR_VERSION -X internal/config.commit=$CI_COMMIT_SHORT_SHA" cmd/agent/main.go
48+
touch dist/isbuilt/agent
49+
- name: Archive binary
50+
uses: actions/upload-artifact@v4
51+
with:
52+
name: binary-build
53+
path: |
54+
dist/agent
55+
dist/isbuilt/agent
56+
retention-days: 1
57+
58+
59+
build-container-image:
60+
runs-on: ubuntu-latest
61+
#if: ${{ ! startsWith(github.ref, 'refs/tags/') }}
62+
needs: build-app
63+
permissions:
64+
contents: read
65+
packages: write
66+
id-token: write
67+
68+
steps:
69+
- name: Checkout repository
70+
uses: actions/checkout@v4
71+
72+
- name: Download binary build artifacts
73+
uses: actions/download-artifact@v4
74+
75+
- name: Move artifacts
76+
run: |
77+
mv binary-build dist
78+
79+
- name: Install cosign
80+
if: github.event_name != 'pull_request'
81+
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
82+
with:
83+
cosign-release: 'v2.2.4'
84+
85+
# Set up BuildKit Docker container builder to be able to build
86+
# multi-platform images and export cache
87+
# https://github.com/docker/setup-buildx-action
88+
- name: Set up Docker Buildx
89+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
90+
91+
# Login against a Docker registry except on PR
92+
# https://github.com/docker/login-action
93+
- name: Log into registry ${{ env.REGISTRY }}
94+
if: github.event_name != 'pull_request'
95+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
96+
with:
97+
registry: ${{ env.REGISTRY }}
98+
username: ${{ github.actor }}
99+
password: ${{ secrets.GITHUB_TOKEN }}
100+
101+
# Extract metadata (tags, labels) for Docker
102+
# https://github.com/docker/metadata-action
103+
- name: Extract Docker metadata
104+
id: meta
105+
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
106+
with:
107+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
108+
tags: |
109+
type=raw,value=latest
110+
type=raw,value=${{ env.ROR_VERSION }}
111+
112+
# Build and push Docker image with Buildx (don't push on PR)
113+
# https://github.com/docker/build-push-action
114+
- name: Build and push Docker image
115+
id: build-and-push
116+
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
117+
with:
118+
context: .
119+
push: ${{ github.event_name != 'pull_request' }}
120+
tags: ${{ steps.meta.outputs.tags }}
121+
labels: ${{ steps.meta.outputs.labels }}
122+
cache-from: type=gha
123+
cache-to: type=gha,mode=max
124+
125+
# Sign the resulting Docker image digest except on PRs.
126+
# This will only write to the public Rekor transparency log when the Docker
127+
# repository is public to avoid leaking data. If you would like to publish
128+
# transparency data even for private images, pass --force to cosign below.
129+
# https://github.com/sigstore/cosign
130+
- name: Sign the published Docker image
131+
if: ${{ github.event_name != 'pull_request' }}
132+
env:
133+
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
134+
TAGS: ${{ steps.meta.outputs.tags }}
135+
DIGEST: ${{ steps.build-and-push.outputs.digest }}
136+
# This step uses the identity token to provision an ephemeral certificate
137+
# against the sigstore community Fulcio instance.
138+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

0 commit comments

Comments
 (0)