-
Notifications
You must be signed in to change notification settings - Fork 121
73 lines (61 loc) · 2.42 KB
/
docker-multiarch.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
name: Multi-Arch Docker Build
on:
push:
branches:
- develop
- release-v[0-9]+.[0-9]+.[0-9]+*
schedule:
- cron: "00 03 * * 0" # Runs every Sunday at 3 AM UTC
jobs:
build_and_push:
runs-on: ubuntu-latest
env:
REGISTRY: docker.io
USERNAME: dhiway
IMAGE_NAME: ${{ github.event.repository.name }}
COMMIT_SHA: ${{ github.sha }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.USERNAME }}
password: "${{ secrets.DOCKER_PASSWORD }}"
- name: Set build profile
run: |
if [[ "${{ github.ref }}" == "refs/heads/release*" ]]; then
echo "BUILD_PROFILE=production" >> $GITHUB_ENV
echo "LATEST_TAG=true" >> $GITHUB_ENV
else
echo "BUILD_PROFILE=release" >> $GITHUB_ENV
fi
- name: Build and Push to Docker Hub
run: |
docker buildx create --use
DOCKER_BRANCH=${{ github.ref_name }}
docker buildx build --platform linux/amd64,linux/arm64 \
--build-arg CARGO_PROFILE=${{ env.BUILD_PROFILE }} \
--tag ${{ env.REGISTRY }}/${{ env.USERNAME }}/${{ env.IMAGE_NAME }}:$DOCKER_BRANCH \
--tag ${{ env.REGISTRY }}/${{ env.USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.COMMIT_SHA }} \
--file docker/Dockerfile \
--push \
.
if [[ "${{ env.LATEST_TAG }}" == "true" ]]; then
docker buildx imagetools create \
--tag ${{ env.REGISTRY }}/${{ env.USERNAME }}/${{ env.RELEASE_IMAGE_NAME }}:latest \
${{ env.REGISTRY }}/${{ env.USERNAME }}/${{ env.RELEASE_IMAGE_NAME }}:${{ env.IMAGE_TAG }}
fi
- name: Verify Image Tags
run: |
echo "Docker Image Tags:"
echo " - ${{ env.REGISTRY }}/${{ env.USERNAME }}/${{ env.IMAGE_NAME }}:$DOCKER_BRANCH"
echo " - ${{ env.REGISTRY }}/${{ env.USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.COMMIT_SHA }}"
if [[ "${{ env.LATEST_TAG }}" == "true" ]]; then
echo " - ${{ env.REGISTRY }}/${{ env.USERNAME }}/${{ env.RELEASE_IMAGE_NAME }}:latest"
fi