-
Notifications
You must be signed in to change notification settings - Fork 8
91 lines (80 loc) · 2.76 KB
/
default__build-push-docker.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
name: Build and push Docker
on:
push:
branches:
- 'main'
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
pull_request:
branches:
- 'disabled-main'
workflow_dispatch:
env:
IMAGE_NAME: ${{ github.event.repository.name }}
SITE_URL_AMD64: 'https://nmc-docker.arm1.nemanjamitic.com'
SITE_URL_ARM64: 'https://nmc-docker.local.nemanjamitic.com'
PLAUSIBLE_SCRIPT_URL: 'https://plausible.arm1.nemanjamitic.com/js/script.js'
jobs:
build:
name: Build and push docker image
runs-on: ubuntu-latest
strategy:
matrix:
platform: [linux/amd64, linux/arm64]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Print commit id, message and tag
run: |
git show -s --format='%h %s'
echo "github.ref -> {{ github.ref }}"
# for arm image
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker metadata
# disable this step
if: false
id: metadata
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value={{sha}},enable=${{ github.ref_type != 'tag' }}
- name: Log in to Docker Hub
uses: docker/login-action@v3
# if: ${{ github.ref_type == 'tag' }}
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set environment variables for each architecture
run: |
if [[ "${{ matrix.platform }}" == "linux/amd64" ]]; then
echo "SITE_URL=${{ env.SITE_URL_AMD64 }}" >> $GITHUB_ENV
elif [[ "${{ matrix.platform }}" == "linux/arm64" ]]; then
echo "SITE_URL=${{ env.SITE_URL_ARM64 }}" >> $GITHUB_ENV
fi
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
# src dir
context: ./
# Dockerfile dir
file: ./docker/Dockerfile
# available linux/amd64,linux/arm64
platforms: linux/amd64,linux/arm64
build-args: |
"ARG_SITE_URL=${{ env.SITE_URL }}"
"ARG_PLAUSIBLE_SCRIPT_URL=${{ env.PLAUSIBLE_SCRIPT_URL }}"
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest
# disabled metadata step
# tags: ${{ steps.metadata.outputs.tags }}
# labels: ${{ steps.metadata.outputs.labels }}
cache-from: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:buildcache
cache-to: type=inline