-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (68 loc) · 2.47 KB
/
rust.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
name: Rust CI/CD
on:
release:
types: [created]
env:
CARGO_TERM_COLOR: always
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
IMAGE_NAME: "shieldauth/shield"
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
arch: [amd64, arm64]
steps:
- uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Determine version from release
shell: bash
run: |
if [[ "$GITHUB_REF" =~ ^refs/tags/v([0-9]+\.[0-9]+\.[0-9]+)(-alpha|-beta)?$ ]]; then
VERSION="${BASH_REMATCH[1]}"
echo "VERSION=$VERSION" >> $GITHUB_ENV
else
echo "Invalid release tag format. Exiting."
exit 1
fi
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/${{ matrix.arch }}
push: true
tags: |
${{ env.IMAGE_NAME }}:${{ github.ref_name }}-${{ matrix.arch }}
${{ env.IMAGE_NAME }}:latest-${{ matrix.arch }}
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache-${{ matrix.arch }}
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache-${{ matrix.arch }},mode=max
create-manifests:
needs: build
runs-on: ubuntu-latest
steps:
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Create and push manifest for version tag
run: |
docker manifest create ${{ env.IMAGE_NAME }}:${{ github.ref_name }} \
${{ env.IMAGE_NAME }}:${{ github.ref_name }}-amd64 \
${{ env.IMAGE_NAME }}:${{ github.ref_name }}-arm64
docker manifest push ${{ env.IMAGE_NAME }}:${{ github.ref_name }}
- name: Create and push manifest for latest tag
run: |
docker manifest create ${{ env.IMAGE_NAME }}:latest \
${{ env.IMAGE_NAME }}:latest-amd64 \
${{ env.IMAGE_NAME }}:latest-arm64
docker manifest push ${{ env.IMAGE_NAME }}:latest