-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (96 loc) · 3.35 KB
/
CICD.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
name: CI/CD
on:
push:
paths-ignore:
- .gitignore
- LICENSE
- README.md
env:
PLATFORMS: linux/amd64,linux/arm64,linux/386,linux/arm/v7
jobs:
build:
name: Build multi-arch Docker image and cache it
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.tags.outputs.tags }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Retrieve Docker build cache
uses: actions/cache@v3
id: cache
with:
path: /tmp/.buildx-cache
key: buildx-cache-${{ hashFiles('Dockerfile') }}
restore-keys: buildx-cache-
- name: Generate image tags
id: tags
uses: docker/metadata-action@v4
with:
images: ghcr.io/speelbarrow/amadeus
tags: |
type=sha,enable=${{ !startsWith(github.ref, 'refs/tags/') }}
type=edge,enable=${{ !startsWith(github.ref, 'refs/tags/') }}
type=ref,event=tag,enable=${{ startsWith(github.ref, 'refs/tags/') }}
- name: Create Docker Buildx builder
if: steps.cache.outputs.cache-hit != 'true'
run: docker buildx create --use --driver=docker-container
- name: Build and cache multi-platform image
if: steps.cache.outputs.cache-hit != 'true'
uses: docker/build-push-action@v4
with:
context: .
tags: ${{ steps.tags.outputs.tags }}
platforms: ${{ env.PLATFORMS }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max,compression=gzip,compression-level=9
verify:
name: Verify project builds in Docker image environment
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Retrieve Docker build cache
uses: actions/cache/restore@v3
with:
path: /tmp/.buildx-cache
key: buildx-cache-${{ hashFiles('Dockerfile') }}
restore-keys: buildx-cache-
- name: Build Docker image from cache
uses: docker/build-push-action@v4
with:
context: .
load: true
cache-from: type=local,src=/tmp/.buildx-cache
tags: ghcr.io/speelbarrow/amadeus
- name: Verify that the project builds successfully
run: docker run --rm ghcr.io/speelbarrow/amadeus
push:
name: Push Docker image from cache to GitHub Container Registry
runs-on: ubuntu-latest
needs: [build, verify]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Retrieve Docker build cache
uses: actions/cache/restore@v3
with:
path: /tmp/.buildx-cache
key: buildx-cache-${{ hashFiles('Dockerfile') }}
restore-keys: buildx-cache-
- name: Create Docker Buildx builder
run: docker buildx create --use --driver=docker-container
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push multi-platform image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ needs.build.outputs.tags }}
platforms: ${{ env.PLATFORMS }}
cache-from: type=local,src=/tmp/.buildx-cache