Skip to content

Commit b4dd4d7

Browse files
committed
ci: build head docker images on changes in main
Builds docker images with `head-<architecture>` tags on every push to main. Pushes images only if executed on the main branch.
1 parent 0f4b6be commit b4dd4d7

File tree

2 files changed

+208
-0
lines changed

2 files changed

+208
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Build and push head images
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build-head-images:
10+
runs-on: ubuntu-latest
11+
name: Publish head images
12+
if: |
13+
github.repository_owner == 'loft-sh' &&
14+
github.ref_name == 'main'
15+
permissions:
16+
contents: read
17+
id-token: write # This is the key for OIDC cosign!
18+
packages: write
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Set up Go
26+
uses: actions/setup-go@v5
27+
with:
28+
cache: false
29+
go-version-file: go.mod
30+
31+
- name: Install just
32+
uses: extractions/setup-just@v1
33+
34+
- name: Log in to GitHub Container Registry
35+
uses: docker/login-action@v3
36+
with:
37+
registry: ghcr.io
38+
username: ${{ github.actor }}
39+
password: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- name: Setup GoReleaser and Build Images
42+
uses: goreleaser/goreleaser-action@v6
43+
with:
44+
distribution: goreleaser
45+
version: latest
46+
args: release --config .goreleaser.head_images.yaml --clean --skip=announce,validate
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
TELEMETRY_PRIVATE_KEY: ""
50+
CI_BRANCH: ${{ github.ref_name }}

.goreleaser.head_images.yaml

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
version: 2
2+
3+
project_name: vcluster
4+
5+
before:
6+
hooks:
7+
- 'echo "Building head images for {{ .Env.CI_BRANCH }} branch"'
8+
9+
builds:
10+
- id: vcluster
11+
env:
12+
- CGO_ENABLED=0
13+
- GO111MODULE=on
14+
goos:
15+
- linux
16+
goarch:
17+
- amd64
18+
- arm64
19+
binary: vcluster
20+
main: ./cmd/vcluster
21+
dir: .
22+
flags:
23+
- -trimpath
24+
- -mod
25+
- vendor
26+
tags:
27+
- embed_chart
28+
ldflags:
29+
- -s -w
30+
- -X github.com/loft-sh/vcluster/pkg/telemetry.SyncerVersion={{.Version}}
31+
- -X github.com/loft-sh/vcluster/pkg/telemetry.telemetryPrivateKey={{ with index .Env "TELEMETRY_PRIVATE_KEY" }}{{ . }}{{ end }}
32+
33+
- id: vcluster-cli
34+
env:
35+
- CGO_ENABLED=0
36+
- GO111MODULE=on
37+
goos:
38+
- linux
39+
goarch:
40+
- amd64
41+
- arm64
42+
binary: vcluster
43+
main: ./cmd/vclusterctl
44+
dir: .
45+
flags:
46+
- -trimpath
47+
- -mod
48+
- vendor
49+
tags:
50+
- embed_chart
51+
ldflags:
52+
- -s -w
53+
- -X main.version={{.Version}}
54+
- -X github.com/loft-sh/vcluster/pkg/telemetry.SyncerVersion={{.Version}}
55+
- -X github.com/loft-sh/vcluster/pkg/telemetry.telemetryPrivateKey={{ with index .Env "TELEMETRY_PRIVATE_KEY" }}{{ . }}{{ end }}
56+
57+
dockers:
58+
# --- Vcluster images ---
59+
- image_templates:
60+
- "ghcr.io/loft-sh/vcluster-oss:head-amd64"
61+
use: buildx
62+
dockerfile: Dockerfile.release
63+
ids:
64+
- vcluster
65+
build_flag_templates:
66+
- "--platform=linux/amd64"
67+
- "--label=org.opencontainers.image.created={{.Date}}"
68+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
69+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
70+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
71+
- "--label=org.opencontainers.image.version=head"
72+
extra_files:
73+
- dist/vcluster_linux_amd64_v1/vcluster
74+
skip_push: '{{ ne .Env.CI_BRANCH "main" }}'
75+
76+
- image_templates:
77+
- "ghcr.io/loft-sh/vcluster-oss:head-arm64v8"
78+
use: buildx
79+
goarch: arm64
80+
dockerfile: Dockerfile.release
81+
ids:
82+
- vcluster
83+
build_flag_templates:
84+
- "--platform=linux/arm64/v8"
85+
- "--label=org.opencontainers.image.created={{.Date}}"
86+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
87+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
88+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
89+
- "--label=org.opencontainers.image.version=head"
90+
extra_files:
91+
- dist/vcluster_linux_arm64_v8.0/vcluster
92+
skip_push: '{{ ne .Env.CI_BRANCH "main" }}'
93+
94+
# --- Vcluster-cli images ---
95+
- image_templates:
96+
- "ghcr.io/loft-sh/vcluster-cli:head-amd64"
97+
use: buildx
98+
dockerfile: Dockerfile.cli.release
99+
ids:
100+
- vcluster-cli
101+
build_flag_templates:
102+
- "--platform=linux/amd64"
103+
- "--label=org.opencontainers.image.created={{.Date}}"
104+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
105+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
106+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
107+
- "--label=org.opencontainers.image.version=head"
108+
extra_files:
109+
- dist/vcluster-cli_linux_amd64_v1/vcluster-cli
110+
skip_push: '{{ ne .Env.CI_BRANCH "main" }}'
111+
112+
- image_templates:
113+
# Only build head-arm64v8 tag when on main branch
114+
- "ghcr.io/loft-sh/vcluster-cli:head-arm64v8"
115+
use: buildx
116+
goarch: arm64
117+
dockerfile: Dockerfile.cli.release
118+
ids:
119+
- vcluster-cli
120+
build_flag_templates:
121+
- "--platform=linux/arm64/v8"
122+
- "--label=org.opencontainers.image.created={{.Date}}"
123+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
124+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
125+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
126+
- "--label=org.opencontainers.image.version=head"
127+
extra_files:
128+
- dist/vcluster-cli_linux_arm64_v8.0/vcluster-cli
129+
skip_push: '{{ ne .Env.CI_BRANCH "main" }}'
130+
131+
docker_manifests:
132+
# --- Head multi arch ---
133+
- name_template: ghcr.io/loft-sh/vcluster-oss:head
134+
image_templates:
135+
- ghcr.io/loft-sh/vcluster-oss:head-amd64
136+
- ghcr.io/loft-sh/vcluster-oss:head-arm64v8h
137+
skip_push: '{{ ne .Env.CI_BRANCH "main" }}'
138+
139+
# --- Head multi arch for CLI ---
140+
- name_template: ghcr.io/loft-sh/vcluster-cli:head
141+
image_templates:
142+
- ghcr.io/loft-sh/vcluster-cli:head-amd64
143+
- ghcr.io/loft-sh/vcluster-cli:head-arm64v8
144+
skip_push: '{{ ne .Env.CI_BRANCH "main" }}'
145+
146+
# Keep release disabled to avoid creating GitHub releases
147+
release:
148+
disable: true
149+
150+
docker_signs:
151+
- cmd: cosign
152+
env:
153+
- COSIGN_EXPERIMENTAL=1
154+
artifacts: all
155+
args:
156+
- "sign"
157+
- "${artifact}"
158+
- "--yes" # needed on cosign 2.0.0+

0 commit comments

Comments
 (0)