-
Notifications
You must be signed in to change notification settings - Fork 3
210 lines (183 loc) · 6.61 KB
/
Copy pathci.yml
File metadata and controls
210 lines (183 loc) · 6.61 KB
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
name: Build and Release rapida
on:
push:
branches:
- "main"
pull_request:
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
REGISTRY_IMAGE: ${{ github.repository }}
# --- REQUIRED FOR GHCR AUTHENTICATION ---
permissions:
contents: write
packages: write
jobs:
test:
name: Test
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v5
with:
context: .
target: prod
load: true
tags: rapida:test
# --- TURN ON GITHUB ACTIONS CACHING ---
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Run tests
run: |
docker run --rm --entrypoint /bin/bash \
-u root \
-e SETUPTOOLS_SCM_PRETEND_VERSION="0.0.0.dev0" \
-v ${{ github.workspace }}:/ci-workspace -w /ci-workspace \
rapida:test \
-c "uv pip install .[dev] && pytest tests"
create-tag:
name: Auto-Increment Version
# ONLY run this when code is merged/pushed directly to main
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
#needs: [test]
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
version: ${{ steps.tagger.outputs.new_tag }}
steps:
- uses: actions/checkout@v4
- name: Bump version and push tag
id: tagger
uses: mathieudutour/github-tag-action@v6.2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: patch
build-multi-arch:
name: Build & Push
needs: [create-tag]
environment: azure container registry
runs-on: ${{ matrix.runner }}
strategy:
matrix:
platform: [linux/amd64, linux/arm64]
include:
- platform: linux/amd64
runner: ubuntu-latest
- platform: linux/arm64
runner: ubuntu-22.04-arm
steps:
- uses: actions/checkout@v4
- name: Prepare Variables
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
echo "IMAGE_NAME=$(echo '${{ env.REGISTRY_IMAGE }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/login-action@v3
with:
registry: ${{ secrets.ACR_ENDPOINT }}
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ env.IMAGE_NAME }}
${{ secrets.ACR_ENDPOINT }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ needs.create-tag.outputs.version }}
type=raw,value=latest
- name: Build and push by digest
id: build
uses: docker/build-push-action@v5
with:
context: .
target: prod
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,"name=ghcr.io/${{ env.IMAGE_NAME }},${{ secrets.ACR_ENDPOINT }}/${{ env.IMAGE_NAME }}",push-by-digest=true,name-canonical=true,push=true
build-args: |
RAPIDA_VERSION=${{ needs.create-tag.outputs.version }}
- name: Export digest
run: |
mkdir -p ${{ runner.temp }}/digests
digest="${{ steps.build.outputs.digest }}"
touch "${{ runner.temp }}/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: ${{ runner.temp }}/digests/*
retention-days: 1
deploy-manifests:
name: Merge Manifests
needs: [create-tag, build-multi-arch]
environment: azure container registry
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests
pattern: digests-*
merge-multiple: true
- uses: docker/setup-buildx-action@v3
- name: Prepare Variables
run: |
echo "IMAGE_NAME=$(echo '${{ env.REGISTRY_IMAGE }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/login-action@v3
with:
registry: ${{ secrets.ACR_ENDPOINT }}
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ env.IMAGE_NAME }}
${{ secrets.ACR_ENDPOINT }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ needs.create-tag.outputs.version }}
type=raw,value=latest
- name: Create manifest lists
working-directory: ${{ runner.temp }}/digests
run: |
# 1. Filter the metadata JSON to separate the tags by registry
GHCR_TAGS=$(jq -cr '.tags | map(select(test("ghcr.io"))) | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON")
ACR_TAGS=$(jq -cr '.tags | map(select(test("${{ secrets.ACR_ENDPOINT }}"))) | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON")
# 2. Build and push the GHCR manifest
echo "Creating manifest for GHCR..."
docker buildx imagetools create $GHCR_TAGS \
$(printf "ghcr.io/${{ env.IMAGE_NAME }}@sha256:%s " *)
# 3. Build and push the ACR manifest
echo "Creating manifest for ACR..."
docker buildx imagetools create $ACR_TAGS \
$(printf "${{ secrets.ACR_ENDPOINT }}/${{ env.IMAGE_NAME }}@sha256:%s " *)
create-release:
name: Create GitHub Release
# Wait for the Docker images to be fully published first!
needs: [ create-tag, deploy-manifests ]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Generate Release Notes
uses: softprops/action-gh-release@v2
with:
# Use the exact version tag created earlier in the pipeline
tag_name: ${{ needs.create-tag.outputs.version }}
# This tells GitHub to auto-generate the markdown changelog
generate_release_notes: true