-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (116 loc) · 3.84 KB
/
build-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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: Build and publish docker images
on:
push:
# Publish `master` as Docker `latest` image.
branches:
- master
- development
# Publish `v1.2.3` tags as releases.
tags:
- v*
env:
IMAGE_NAME: robles
jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests
run: |
if [ -f docker-compose.test.yml ]; then
docker-compose --file docker-compose.test.yml build
docker-compose --file docker-compose.test.yml run sut
else
docker build . --file Dockerfile
fi
- name: Notify slack - test results
uses: voxmedia/github-action-slack-notify-build@v1
if: failure()
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
with:
channel: circleci
status: FAILED
color: danger
# Push image to DockerHub.
push:
# Ensure test job passes before pushing image.
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- name: Notify slack - build starting
uses: voxmedia/github-action-slack-notify-build@v1
if: success()
id: slack
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
with:
channel: build
status: STARTING
color: warning
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/[email protected]
- name: Set up Docker Buildx
id: buildx
uses: docker/[email protected]
with:
buildkitd-flags: --debug
- name: Log in to DockerHub registry
run: echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u razewareci --password-stdin
- name: Generate tag list
id: generate_tags
run: |
IMAGE_ID=razeware/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Prefix tags with 'release'
if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
TAGS=$(echo "${VERSION}" | sed -E "s/v?([0-9]+)\.([0-9]+)\.([0-9]+)/release-v\1.\2.\3 release-v\1.\2 release-v\1/g")
fi
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && TAGS=latest
[ "$VERSION" == "development" ] && TAGS=staging
echo IMAGE_ID=$IMAGE_ID
echo TAGS=$TAGS
TAG_LIST=""
for TAG in ${TAGS}; do
TAG_LIST="${TAG_LIST}${IMAGE_ID}:${TAG},"
done
echo $TAG_LIST
echo "::set-output name=tag_list::${TAG_LIST}"
- name: Build and push
uses: docker/[email protected]
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.generate_tags.outputs.tag_list }}
- name: Logout of DockerHub Registry
if: ${{ always() }}
run: docker logout
- name: Notify slack - build result successful
uses: voxmedia/github-action-slack-notify-build@v1
if: success()
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
with:
message_id: ${{ steps.slack.outputs.message_id }}
channel: build
status: SUCCESS
color: good
- name: Notify slack - build result failed
uses: voxmedia/github-action-slack-notify-build@v1
if: failure()
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
with:
message_id: ${{ steps.slack.outputs.message_id }}
channel: build
status: FAILED
color: danger