-
Notifications
You must be signed in to change notification settings - Fork 1
223 lines (194 loc) · 8.35 KB
/
publish-provider-family.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
name: Publish Family Provider
on:
workflow_call:
inputs:
subpackages:
description: 'Subpackages to be built individually (e.g. config ec2)'
default: 'config'
required: false
type: string
size:
description: "Number of packages to build and push with each matrix build job"
default: '30'
required: true
type: string
concurrency:
description: "Number of parallel package builds in each matrix job"
default: '1'
required: false
type: string
repository:
description: "Source repository (like provider-aws, provider-azure..)"
required: true
type: string
version:
description: "Version string to use while publishing the packages"
default: ''
required: false
type: string
go-version:
description: 'Go version to use if building needs to be done'
default: '1.22'
required: false
type: string
cleanup-disk:
description: "If set to true, an initial step will be run to reclaim some extra disk space for the build/test jobs in this workflow"
required: false
type: boolean
default: false
secrets:
GHCR_PAT:
required: true
XPKG_UPBOUND_TOKEN:
required: true
env:
# Common versions
DOCKER_BUILDX_VERSION: 'v0.20.1'
UP_VERSION: 'v0.37.1'
# Registry/Org names
CROSSPLANE_REGORG: 'ghcr.io/crossplane-contrib' # xpkg.crossplane.io/crossplane-contrib
UPBOUND_REGORG: 'xpkg.upbound.io/crossplane-contrib'
# Upbound registry specific variables
UP_DOMAIN: "https://upbound.io"
UP_TOKEN: ${{ secrets.XPKG_UPBOUND_TOKEN }}
jobs:
index:
runs-on: ubuntu-latest
outputs:
indices: ${{ steps.calc.outputs.indices }}
steps:
- id: calc
run: |
python3 -c "import math; print(f'indices={list(range(0, math.ceil(len(\"${{ inputs.subpackages }}\".split()) / int(\"${{ inputs.size }}\"))))}')" >> "$GITHUB_OUTPUT"
publish-artifacts:
strategy:
matrix:
index: ${{ fromJSON(needs.index.outputs.indices) }}
needs: index
runs-on: ubuntu-latest-16-cores
steps:
- name: Cleanup Disk
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1
if: ${{ inputs.cleanup-disk }}
with:
android: true
dotnet: true
haskell: true
tool-cache: true
large-packages: false
swap-storage: false
- name: Setup QEMU
uses: docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7 # v2
with:
platforms: all
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@885d1462b80bc1c1c7f0b00334ad271f09369c55 # v2
with:
version: ${{ env.DOCKER_BUILDX_VERSION }}
install: true
- name: Login to GHCR using PAT
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_PAT }}
- name: Checkout
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
with:
submodules: true
- name: Fetch History
run: git fetch --prune --unshallow
- name: Setup Go
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3
with:
go-version: ${{ inputs.go-version }}
- name: Find the Go Build Cache
id: go_cache
run: |
echo "cache=$(make go.cachedir)" >> $GITHUB_OUTPUT && \
echo "mod_cache=$(make go.mod.cachedir)" >> $GITHUB_OUTPUT
- name: Cache the Go Build Cache
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3
with:
path: ${{ steps.go_cache.outputs.cache }}
key: ${{ runner.os }}-build-publish-artifacts-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-build-publish-artifacts-
- name: Cache Go Dependencies
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3
with:
path: ${{ steps.go_cache.outputs.mod_cache }}
key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-pkg-
- name: Vendor Dependencies
run: make vendor vendor.check
- name: Calculate packages to build & push
id: packages
run: |
echo target=$(python3 -c "print(' '.join(\"${{ inputs.subpackages }}\".split()[int(\"${{ matrix.index }}\") * int(\"${{ inputs.size }}\"): (int(\"${{ matrix.index }}\")+1) * int(\"${{ inputs.size }}\")]))") >> "$GITHUB_OUTPUT"
- name: Build Artifacts
id: build_artifacts
run: |
packages=($(echo ${{ steps.packages.outputs.target }} | tr ' ' '\n'))
num_packages=${#packages[@]}
if [ $num_packages -gt 10 ]; then
num_packages=10
fi
make -j $num_packages SUBPACKAGES="${{ steps.packages.outputs.target }}" XPKG_REG_ORGS="${{ env.CROSSPLANE_REGORG }}" XPKG_REG_ORGS_NO_PROMOTE="${{ env.CROSSPLANE_REGORG }}" BRANCH_NAME="main" ${{ inputs.version != '' && format('VERSION={0}', inputs.version) || '' }} build.all
echo "num_packages=$num_packages" >> $GITHUB_OUTPUT
env:
# We're using docker buildx, which doesn't actually load the images it
# builds by default. Specifying --load does so.
BUILD_ARGS: "--load"
- name: Publish Artifacts
run: |
make -j ${{ steps.build_artifacts.outputs.num_packages }} SUBPACKAGES="${{ steps.packages.outputs.target }}" XPKG_REG_ORGS="${{ env.CROSSPLANE_REGORG }}" XPKG_REG_ORGS_NO_PROMOTE="${{ env.CROSSPLANE_REGORG }}" CONCURRENCY="${{ inputs.concurrency }}" BRANCH_NAME="main" ${{ inputs.version != '' && format('VERSION={0}', inputs.version) || '' }} publish
mirror-to-xpkg-upbound-io:
needs: publish-artifacts
runs-on: ubuntu-latest
steps:
- name: Setup QEMU
uses: docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7 # v2
with:
platforms: all
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@885d1462b80bc1c1c7f0b00334ad271f09369c55 # v2
with:
version: ${{ env.DOCKER_BUILDX_VERSION }}
install: true
- name: Setup crane
# crane will inherit credentials from `docker login`
uses: imjasonh/[email protected]
- name: Validate crane installation
run: crane version
- name: Up Login
run: |
curl -fsSLo /tmp/up --create-dirs 'https://cli.upbound.io/stable/${{ env.UP_VERSION }}/bin/linux_amd64/up' && \
chmod +x /tmp/up && \
/tmp/up login
- name: Install docker-credential-up
run: |
curl -fsSLo /tmp/docker-credential-up --create-dirs 'https://cli.upbound.io/stable/${{ env.UP_VERSION }}/bin/linux_amd64/docker-credential-up' && \
chmod +x /tmp/docker-credential-up && \
sudo mv /tmp/docker-credential-up /usr/local/bin/docker-credential-up
- name: Get creds
run: |
echo "${{ env.UP_DOMAIN }}" | docker-credential-up get > $HOME/.up/up.token.json
echo "DOCKER_USERNAME=$(cat $HOME/.up/up.token.json | jq -r '.Username')" >> $GITHUB_ENV
echo "DOCKER_PWD=$(cat $HOME/.up/up.token.json | jq -r '.Secret')" >> $GITHUB_ENV
- name: Login to Upbound
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
if: env.DOCKER_USERNAME != ''
with:
registry: "xpkg.upbound.io"
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_PWD }}
- name: Mirror to xpkg.upbound.io
run: |
for subpackage in ${{ inputs.subpackages }}; do
if [ "$subpackage" != "config" ]; then
crane copy ${{ env.CROSSPLANE_REGORG }}/${{ inputs.repository }}-$subpackage:${{ inputs.version }} ${{ env.UPBOUND_REGORG }}/${{ inputs.repository }}-$subpackage:${{ inputs.version }} --allow-nondistributable-artifacts
elif [ "$subpackage" == "config" ]; then
p=$(echo ${{ inputs.repository }} | sed 's/provider-//')
crane copy ${{ env.CROSSPLANE_REGORG }}/provider-family-$p:${{ inputs.version }} ${{ env.UPBOUND_REGORG }}/provider-family-$p:${{ inputs.version }} --allow-nondistributable-artifacts
fi
done