-
Notifications
You must be signed in to change notification settings - Fork 4
114 lines (96 loc) · 3.13 KB
/
build-and-push.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
name: Build
on:
workflow_dispatch: # allow to run manually
push:
branches:
- '**'
tags:
- '**'
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/onegov/onegov-cloud
- name: Build and push docker image
id: push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ghcr.io/onegov/onegov-cloud
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
test-image:
runs-on: ubuntu-latest
needs: build-and-push-image
if: startsWith(github.ref, 'refs/tags/') || contains(github.event.head_commit.message, '[test-container]')
strategy:
matrix:
group: [1, 2, 3, 4, 5, 6]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/onegov/onegov-cloud
- name: Run tests on built image
run: |
docker pull ghcr.io/onegov/onegov-cloud:${{ steps.meta.outputs.version }}
docker run ghcr.io/onegov/onegov-cloud:${{ steps.meta.outputs.version }} test-container "${{matrix.group}}" 6
cleanup-images:
runs-on: ubuntu-latest
needs: build-and-push-image
steps:
- name: Delete unttaged images
uses: seantis/delete-package-versions@main
with:
package-name: 'onegov-cloud'
package-type: 'container'
min-versions-to-keep: 0
delete-only-untagged-versions: 'true'
- name: Delete images tagged with commit hash
uses: seantis/delete-package-versions@main
with:
package-name: 'onegov-cloud'
package-type: 'container'
min-versions-to-keep: 0
ignore-versions: '^(?!sha).*$'
ignore-versions-include-tags: true
- name: Delete old images
uses: seantis/delete-package-versions@main
with:
package-name: 'onegov-cloud'
package-type: 'container'
min-versions-to-keep: 20
ignore-versions: '^release-.*$'
ignore-versions-include-tags: true