-
-
Notifications
You must be signed in to change notification settings - Fork 24
97 lines (91 loc) · 3.42 KB
/
docker-push.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
92
93
94
95
96
97
---
name: docker-push
# yamllint disable-line rule:truthy
on:
workflow_run:
workflows: ["lint"]
types:
- completed
push:
tags:
- '*'
concurrency:
group: docker-push-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
push-enabled:
name: push-enabled
runs-on: ubuntu-22.04
outputs:
push-enabled: ${{ steps.check.outputs.push-enabled }}
docker-image-tag: ${{ steps.check.outputs.docker-image-tag }}
steps:
- name: Check if push allowed
id: check
run: |
image_tag=latest
push_enabled=false
is_tagged=false
if [[ '${{ github.event.workflow_run.head_branch }}' =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo -e "\u001b[32mDetected semver tag\u001b[0m"
image_tag='${{ github.event.workflow_run.head_branch }}'
push_enabled=true
elif [[ '${{ github.event.workflow_run.head_branch }}' == "master" ]]; then
echo -e "\u001b[32mDetected master branch\u001b[0m"
push_enabled=true
elif [[ '${{github.ref_name}}' =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo -e "\u001b[32mDetected semver tag\u001b[0m"
image_tag='${{ github.ref_name }}'
push_enabled=true
is_tagged=true
else
echo "::warning ::Unable to detect semver tag or master branch"
push_enabled=false
fi
if [[ "$is_tagged" == "true" ]]; then
echo -e "\u001b[32mSkipping lint workflow_run check\u001b[0m"
else
if [[ '${{ github.event.workflow_run.conclusion }}' != 'success' ]]; then
echo "::warning ::Unable to detect successful lint workflow_run conclusion"
push_enabled=false
else
echo -e "\u001b[32mDetected success lint workflow_run conclusion\u001b[0m"
fi
fi
echo "push-enabled=${push_enabled}" >> $GITHUB_OUTPUT
echo "docker-image-tag=${image_tag}" >> $GITHUB_OUTPUT
docker-push:
name: push latest
runs-on: ubuntu-22.04
needs: push-enabled
if: needs.push-enabled.outputs.push-enabled == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Generate docker metadata
id: docker_meta
uses: crazy-max/ghaction-docker-meta@dbef88086f6cef02e264edb7dbf63250c17cef6c # v1.8.5 => c53f88523ad1fcebbdb10b3bb9cfa7ddb69d6677
with:
images: dokku/ci-docker-image
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
push: ${{ github.event_name != 'pull_request' }}
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: dokku/ci-docker-image:${{ needs.push-enabled.outputs.docker-image-tag }}
labels: |
${{ steps.docker_meta.outputs.labels }}
org.opencontainers.image.version=${{ github.event.workflow_run.head_branch }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}