-
Notifications
You must be signed in to change notification settings - Fork 39
79 lines (73 loc) · 2.77 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
name: CI/CD
on:
push:
pull_request:
schedule:
- cron: '0 10 25 * *' # Monthly at 10am on the 25th
jobs:
build:
# https://docs.docker.com/build/ci/github-actions/multi-platform/
name: 📦 Build and Push to Docker Hub
runs-on: ubuntu-latest
steps:
# https://github.com/orgs/community/discussions/25678#discussioncomment-5242449
- name: Free Disk Space
run: rm -rf /opt/hostedtoolcache
- name: Checkout
uses: actions/checkout@v4
- name: Set up Environment
run: cat .envrc >> "$GITHUB_ENV"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# https://docs.docker.com/build/ci/github-actions/manage-tags-labels/
- name: Docker meta
uses: docker/metadata-action@v5
id: meta
with:
# list of Docker images to use as base name for tags
images: ${{ env.IMAGE }}
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=match,pattern=v\d.\d.\d
type=match,pattern=v\d.\d
# Customize OCI labels.
labels: |
org.opencontainers.image.title=${{ env.TITLE }}
org.opencontainers.image.description=${{ env.DESCRIPTION }}
org.opencontainers.image.vendor=${{ env.VENDOR }}
org.opencontainers.image.authors=${{ env.AUTHORS }}
org.opencontainers.image.url=${{ env.URL }}
org.opencontainers.image.documentation=${{ env.DOCS }}
org.opencontainers.image.source=${{ env.SOURCE }}
org.opencontainers.image.version=v${{ env.VERSION }}
org.opencontainers.image.licenses=${{ env.LICENSE }}
org.opencontainers.image.ref.name=${{ env.NAME }}-v${{ env.VERSION }}
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and Export to Docker
uses: docker/build-push-action@v5
with:
context: .
load: true
tags: ${{ env.IMAGE }}:test
build-args: VERSION=${{ env.VERSION }}
- name: Test
run: docker run --rm "${{ env.IMAGE }}:test"
# Release on a v* tag.
- name: Build and Push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ startsWith(github.ref, 'refs/tags/v') }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: VERSION=${{ env.VERSION }}