-
Notifications
You must be signed in to change notification settings - Fork 54
123 lines (107 loc) · 4.78 KB
/
build-gcp-guest-agent.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
name: Build and Upload GCP guest-agent container
on:
workflow_dispatch:
schedule:
- cron: "0 4 * * 2" # Every Tuesday at 4am UTC
env:
REGISTRY: ghcr.io
jobs:
build-gcp-guest-agent:
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
steps:
- name: Get latest release of guest-agent
id: latest-release
run: |
latest=$(curl -fsSL https://api.github.com/repos/GoogleCloudPlatform/guest-agent/releases/latest | jq -r .tag_name)
echo "Latest version of guest-agent is $latest"
echo "latest=$latest" | tee -a "$GITHUB_OUTPUT"
- name: Make tag a valid semver
id: latest-release-semver
run: |
semver="${{ steps.latest-release.outputs.latest }}"
beforeDot="${semver%%.*}"
afterDot="${semver#*.}"
afterDotEvaluated=$((afterDot))
semver="v${beforeDot}.${afterDotEvaluated}.0"
echo "Semver tag of guest-agent is $semver"
echo "latest=$semver" | tee -a "$GITHUB_OUTPUT"
- name: Check if the tag is newer than our last build
id: needs-build
run: |
apiURL="https://ghcr.io/v2/edgelesssys/gcp-guest-agent"
tokenJSON=$(curl -fsSL "https://ghcr.io/token?scope=repository:edgelesssys/gcp-guest-agent:pull")
token=$(jq -r '.token' <<< "$tokenJSON")
tokenHeader=(-H "Authorization: Bearer ${token}")
tags=$(curl -fsSL "${tokenHeader[@]}" "${apiURL}/tags/list")
semverUpstream="${{ steps.latest-release-semver.outputs.latest }}"
rebuild=false
if [[ $(jq -r '.tags | index("latest")' <<< "$tags") == 'null' ]]; then
rebuild=true
elif [[ $(jq -r '.tags | index("${{ steps.latest-release-semver.outputs.latest }}")' <<< "$tags") == 'null' ]]; then
rebuild=true
else
digestLatest=$(curl -fsSL "${tokenHeader[@]}" "${apiURL}/manifests/latest" | jq -r '.config.digest')
digestSemver=$(curl -fsSL "${tokenHeader[@]}" "${apiURL}/manifests/${semverUpstream}" | jq -r '.config.digest')
if [[ "$digestLatest" != "$digestSemver" ]]; then
rebuild=true
fi
fi
if [[ $rebuild == false ]]; then
echo "Latest tag $latestTag is already built, exiting"
echo "out=false" | tee -a "$GITHUB_OUTPUT"
exit 0
fi
echo "Latest tag $latestTag is older than ${semverUpstream}, building"
echo "out=true" | tee -a "$GITHUB_OUTPUT"
- name: Checkout GoogleCloudPlatform/guest-agent
if: steps.needs-build.outputs.out == 'true'
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
repository: "GoogleCloudPlatform/guest-agent"
ref: refs/tags/${{ steps.latest-release.outputs.latest }}
path: "guest-agent"
- name: Checkout Constellation
if: steps.needs-build.outputs.out == 'true'
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
path: "constellation"
ref: ${{ !github.event.pull_request.head.repo.fork && github.head_ref || '' }}
- name: Docker meta
id: meta
if: steps.needs-build.outputs.out == 'true'
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
with:
images: |
${{ env.REGISTRY }}/edgelesssys/gcp-guest-agent
flavor: |
latest=false
tags: |
type=raw,value=${{ steps.latest-release-semver.outputs.latest }}
type=raw,value=${{ github.ref_name }},enable=${{ github.ref_name != 'main' }}
type=sha,value=${{ github.sha }}
type=raw,value=latest,enable=${{ github.ref_name == 'main' }}
- name: Log in to the Container registry
id: docker-login
if: steps.needs-build.outputs.out == 'true'
uses: ./constellation/.github/actions/container_registry_login
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare hardcoded configuration file
if: steps.needs-build.outputs.out == 'true'
run: |
cp "${GITHUB_WORKSPACE}/constellation/3rdparty/gcp-guest-agent/instance_configs.cfg" "${GITHUB_WORKSPACE}/guest-agent/"
- name: Build and push container image
if: steps.needs-build.outputs.out == 'true'
id: build
uses: docker/build-push-action@5176d81f87c23d6fc96624dfdbcd9f3830bbe445 # v6.5.0
with:
context: ./guest-agent
file: ./constellation/3rdparty/gcp-guest-agent/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}