Skip to content

Commit 62b675f

Browse files
authored
ci: init new workflow to build images (#4468)
<!-- Use # to add the issue this pull request is related to. nb: This is the Github issue number, not a Zenhub link. Do not use any punctuation or bullet points. eg: Closes #1234 Fixes #5678 --> Closes <!-- Describe what has changed in this PR --> **What changed?** This replaces the image-build jobs in the PR workflow. We need to find a new home for our images anyway, and GHCR seems like our best option. After merging this PR, we should expect images pushed to our GHCR with the default branch name tag (`main`). Future work: - Review dockerfiles with regards to caching. I have a feeling that it's not optimal now. I would expect better performance, but appears to be an improvement already now. - Add keyless signature to images using Cosign. <!-- Tell your future self why have you made these changes --> **Why was this change made?** Prepare CI for our first community release. <!-- Explain to your reviewers the key implementation points, including why you made certain choices in favour of others. Highlight key areas of the code which need extra attention, and also indicate which parts are less relevant (eg renaming, refactoring, etc --> **How was this change implemented?** <!-- How have you verified this change/product value? Tested locally? Added integration/acceptance test(s)? Unit tests are required. --> **How did you validate the change?** <!-- Is it notable for release? e.g. schema updates, configuration or data migration required? If so, please mention it. --> **Release notes** <!-- Are there any documentation updates that should be made for these changes? --> **Documentation Changes**
1 parent 63db826 commit 62b675f

File tree

2 files changed

+63
-108
lines changed

2 files changed

+63
-108
lines changed

.github/workflows/build-image.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
name: Build image
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
tags:
9+
- v*
10+
pull_request:
11+
branches:
12+
- main
13+
14+
permissions:
15+
contents: read # for actions/checkout to fetch code
16+
env:
17+
REGISTRY: ghcr.io
18+
IMAGE_NAME_BASE: ${{ github.repository }}
19+
jobs:
20+
build-push-image:
21+
runs-on: ubuntu-latest
22+
permissions:
23+
packages: write # for docker/build-push-action to push images
24+
strategy:
25+
matrix:
26+
docker-image:
27+
- gitops
28+
- gitops-server
29+
steps:
30+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
31+
- name: Set build-time flags
32+
run: |
33+
echo "LDFLAGS=$(make echo-ldflags)" >> $GITHUB_ENV
34+
echo "FLUX_VERSION=$(make echo-flux-version)" >> $GITHUB_ENV
35+
- uses: docker/setup-qemu-action@53851d14592bedcffcf25ea515637cff71ef929a # v3.3.0
36+
- uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0
37+
- uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
38+
with:
39+
registry: ${{ env.REGISTRY }}
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
- uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
43+
id: meta
44+
with:
45+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_BASE }}/${{ matrix.docker-image }}
46+
tags: |
47+
type=ref,event=branch
48+
type=ref,event=pr
49+
type=semver,pattern={{version}}
50+
- uses: docker/build-push-action@b32b51a8eda65d6793cd0494a773d4f6bcef32dc # v6.11.0
51+
with:
52+
context: .
53+
file: ${{ matrix.docker-image }}.dockerfile
54+
build-args: |
55+
FLUX_VERSION=${{ env.FLUX_VERSION }}
56+
LDFLAGS=${{ env.LDFLAGS }}
57+
GIT_COMMIT=${{ github.sha }}
58+
push: ${{ github.event_name != 'pull_request' && github.repository == 'weaveworks/weave-gitops' }}
59+
tags: ${{ steps.meta.outputs.tags }}
60+
labels: ${{ steps.meta.outputs.labels }}
61+
cache-from: type=gha
62+
cache-to: type=gha,mode=max

.github/workflows/pr.yaml

Lines changed: 1 addition & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ on:
1010
permissions:
1111
contents: read # for actions/checkout to fetch code
1212

13-
env:
14-
CI_CONTAINER_REGISTRY: europe-west1-docker.pkg.dev
15-
CI_CONTAINER_REPOSITORY: europe-west1-docker.pkg.dev/weave-gitops-clusters/weave-gitops
16-
1713
name: PR CI Workflow
1814
jobs:
1915
ci-js:
@@ -73,89 +69,10 @@ jobs:
7369
- name: Check that make fakes has been run
7470
run: git diff --no-ext-diff --exit-code
7571

76-
ci-generate-tag:
77-
name: CI Generate Image Tag
78-
runs-on: ubuntu-latest
79-
outputs:
80-
tag: ${{ steps.generate-tag.outputs.tag }}
81-
steps:
82-
- id: generate-tag
83-
run: echo "tag=$(date -u +%s)-${{ github.sha }}" >> $GITHUB_OUTPUT
84-
85-
ci-build-gitops-image:
86-
name: CI Build Gitops Docker Image
87-
runs-on: ubuntu-latest
88-
needs: [ci-generate-tag]
89-
strategy:
90-
matrix:
91-
docker-image:
92-
- gitops
93-
- gitops-server
94-
steps:
95-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
96-
- uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0
97-
- name: Set build-time flags
98-
run: |
99-
echo "LDFLAGS=$(make echo-ldflags)" >> $GITHUB_ENV
100-
echo "FLUX_VERSION=$(make echo-flux-version)" >> $GITHUB_ENV
101-
- name: Build and export
102-
uses: docker/build-push-action@b32b51a8eda65d6793cd0494a773d4f6bcef32dc # v6.11.0
103-
with:
104-
tags: "${{ env.CI_CONTAINER_REPOSITORY }}/${{ matrix.docker-image }}:${{ needs.ci-generate-tag.outputs.tag }}"
105-
outputs: type=docker,dest=/tmp/${{ matrix.docker-image }}.tar
106-
file: ${{ matrix.docker-image }}.dockerfile
107-
build-args: |
108-
FLUX_VERSION=${{ env.FLUX_VERSION }}
109-
LDFLAGS=${{ env.LDFLAGS }}
110-
GIT_COMMIT=${{ github.sha }}
111-
- name: Load docker image
112-
run: docker load --input /tmp/${{ matrix.docker-image }}.tar
113-
- name: Cache docker image
114-
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
115-
with:
116-
name: ${{ matrix.docker-image }}
117-
path: /tmp/${{ matrix.docker-image }}.tar
118-
retention-days: 1
119-
120-
ci-upload-images:
121-
name: CI Upload Images - Disabled
122-
runs-on: ubuntu-latest
123-
# Make sure we only upload images if tests etc have passed
124-
needs: [ci-go, ci-static, ci-js, ci-build-gitops-image, ci-generate-tag]
125-
permissions:
126-
contents: 'read'
127-
id-token: 'write'
128-
if: github.event_name == 'push'
129-
strategy:
130-
matrix:
131-
docker-image:
132-
- gitops
133-
- gitops-server
134-
steps:
135-
- uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0
136-
- uses: google-github-actions/setup-gcloud@6189d56e4096ee891640bb02ac264be376592d6a # v2.1.2
137-
- name: Download cached docker image
138-
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
139-
with:
140-
name: ${{ matrix.docker-image }}
141-
path: /tmp
142-
# - name: Authenticate to Google Cloud
143-
# id: gcloud-auth
144-
# uses: google-github-actions/auth@6fc4af4b145ae7821d527454aa9bd537d1f2dc5f # v2.1.7
145-
# with:
146-
# service_account: ${{ secrets.service_account }}
147-
# workload_identity_provider: ${{ secrets.workload_identity_provider }}
148-
# - name: Login to gcloud for docker
149-
# run: gcloud --quiet auth configure-docker ${{ env.CI_CONTAINER_REGISTRY }}
150-
# - name: Push images to gcloud
151-
# run: |
152-
# docker load --input /tmp/${{ matrix.docker-image }}.tar
153-
# docker push "${{ env.CI_CONTAINER_REPOSITORY }}/${{ matrix.docker-image }}:${{ needs.ci-generate-tag.outputs.tag }}"
154-
15572
ci-upload-binary:
15673
name: Upload Binary - Disabled
15774
runs-on: ${{matrix.os}}
158-
needs: [ci-go, ci-static, ci-js, ci-build-gitops-image]
75+
needs: [ci-go, ci-static, ci-js]
15976
strategy:
16077
matrix:
16178
os: [ubuntu-latest, macOS-latest]
@@ -225,30 +142,6 @@ jobs:
225142
env:
226143
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
227144

228-
# We only push images on merge so create a passing check if everything finished
229-
finish-ci-pr:
230-
name: PR CI Pipeline
231-
runs-on: ubuntu-latest
232-
needs:
233-
- ci-go
234-
- ci-static
235-
- ci-js
236-
- ci-build-gitops-image
237-
if: github.event_name != 'push'
238-
steps:
239-
- run: echo "All done"
240-
241-
finish-ci-merge:
242-
# must match https://github.com/weaveworks/corp/blob/master/github-repo-weave-gitops.tf
243-
name: PR CI Pipeline
244-
runs-on: ubuntu-latest
245-
needs:
246-
- ci-upload-images
247-
- ci-upload-binary
248-
- ci-publish-js-lib
249-
steps:
250-
- run: echo "All done"
251-
252145
# release step updates 'release' status check for non releases branches. See ../../doc/incidents/issues-3907 for full context.
253146
release:
254147
if: ${{ github.event_name == 'pull_request' && !startsWith(github.event.pull_request.head.ref, 'releases/') && !github.event.pull_request.head.repo.fork }}

0 commit comments

Comments
 (0)