-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (83 loc) · 2.81 KB
/
docker-image.yml
File metadata and controls
99 lines (83 loc) · 2.81 KB
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
name: Publish Docker Image
permissions:
actions: write
contents: read
checks: write
id-token: write
pull-requests: write
on:
release:
types: [created]
pull_request:
push:
jobs:
setup:
if: github.event_name == 'release' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
outputs:
dirs: ${{ steps.matrix.outputs.dirs }}
tag: ${{ steps.vars.outputs.tag }}
steps:
- name: Check out repository
uses: actions/checkout@v6
- name: Get the list of directories that contain a Dockerfile
id: matrix
run: |
set -euo pipefail
dirs=$(find -mindepth 3 -maxdepth 3 -type f -name 'Dockerfile' -printf '%h\n' | xargs dirname | cut -d/ -f2- | sort | tr "\n" " " | awk '{$1=$1};1')
dirs=$(jq -n --indent 0 --arg dirs "$dirs" '$dirs | split(" ")')
echo "dirs=$dirs" >> $GITHUB_OUTPUT
- name: Get the tag name for the release
id: vars
run: |
tag="${GITHUB_REF#refs/*/v}" # refs/tags/v1.2.3 -> 1.2.3
echo "tag=$tag" >> $GITHUB_OUTPUT
- run: |
echo "dirs=${{ steps.matrix.outputs.dirs }}"
echo "tag=${{ steps.vars.outputs.tag }}"
build:
needs: [ setup ]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
dirs: ${{ fromJSON(needs.setup.outputs.dirs) }}
steps:
- name: Check out repository
uses: actions/checkout@v6
- name: Set environment variables
run: |
scripts/get_env_variables.sh
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: "${{ secrets.DOCKERHUB_USERNAME }}"
password: "${{ secrets.DOCKERHUB_TOKEN }}"
- name: Build the Docker image
run: |
set -euo pipefail
[ -f docker/docker-compose.yml ] && docker compose -f ./docker/docker-compose.yml build --pull
working-directory: ${{ matrix.dirs }}
env:
TAG: ${{ needs.setup.outputs.tag }}
BUILD_DATE: "${{ env.BUILD_DATE }}"
GIT_COMMIT: "${{ env.GIT_COMMIT }}"
- name: Publish the Docker image
id: publish
run: |
set -euo pipefail
[ -f docker/docker-compose.yml ] && docker compose -f ./docker/docker-compose.yml push
working-directory: ${{ matrix.dirs }}
env:
TAG: ${{ needs.setup.outputs.tag }}
BUILD_DATE: "${{ env.BUILD_DATE }}"
GIT_COMMIT: "${{ env.GIT_COMMIT }}"
- name: Publish the Docker image (Retry)
if: ${{ failure() && steps.publish.outcome == 'failure' }}
run: |
set -euo pipefail
[ -f docker/docker-compose.yml ] && docker compose -f ./docker/docker-compose.yml push
working-directory: ${{ matrix.dirs }}
env:
BUILD_DATE: "${{ env.BUILD_DATE }}"
GIT_COMMIT: "${{ env.GIT_COMMIT }}"