-
Notifications
You must be signed in to change notification settings - Fork 4
119 lines (102 loc) · 3.61 KB
/
docker-build-and-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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: docker-build-and-push
on:
push:
paths-ignore:
- "README.md"
pull_request:
branches:
- master
paths-ignore:
- "README.md"
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/386
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: docker images before
run: docker image ls
- name: Build awstats for testing
uses: docker/build-push-action@v5
with:
load: true
tags: pabra/awstats:test
cache-from: type=registry,ref=pabra/awstats:buildcache
- name: Build awstats-test
uses: docker/build-push-action@v5
with:
context: ./test
file: ./test/Dockerfile
load: true
tags: pabra/awstats-test:latest
- name: run tests
run: ./run_tests.sh skip_build
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: pabra/awstats
labels: |
org.opencontainers.image.authors=Patrick Braune<pabra@netzfruech.de>
- name: Prepare
id: prep
if: github.event_name != 'pull_request'
run: |
set -ex
DOCKER_IMAGE=pabra/awstats
BRANCH="${GITHUB_REF#refs/heads/}"
SHORT_SHA="${GITHUB_SHA:0:7}"
COMMITS="$( git rev-list --count "${BRANCH}" )"
SUBJECT="$( git show --no-patch --format=%s ${GITHUB_SHA} )"
if [[ "${SUBJECT}" != publish:* ]]; then
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
else
if [ "${BRANCH}" = 'master' ]; then
TAGS="${DOCKER_IMAGE}:${BRANCH}-${COMMITS}-${SHORT_SHA}"
TAGS="${TAGS},${DOCKER_IMAGE}:edge"
elif [ "${BRANCH}" = '7.9' ]; then
TAGS="${DOCKER_IMAGE}:${BRANCH}-${COMMITS}-${SHORT_SHA}"
TAGS="${TAGS},${DOCKER_IMAGE}:${BRANCH}"
TAGS="${TAGS},${DOCKER_IMAGE}:latest"
elif [ "${BRANCH}" = '7.8' ]; then
TAGS="${DOCKER_IMAGE}:${BRANCH}-${COMMITS}-${SHORT_SHA}"
TAGS="${TAGS},${DOCKER_IMAGE}:${BRANCH}"
elif [ "${BRANCH}" = '7.7' ]; then
TAGS="${DOCKER_IMAGE}:${BRANCH}-${COMMITS}-${SHORT_SHA}"
TAGS="${TAGS},${DOCKER_IMAGE}:${BRANCH}"
elif [ "${BRANCH}" = 'actions' ]; then
TAGS="${DOCKER_IMAGE}:${BRANCH}-${COMMITS}-${SHORT_SHA}"
else
TAGS=''
fi
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
fi
- name: debug tags
run: |
set -ex
echo "tags: '${{ steps.prep.outputs.tags }}'"
- name: Login to DockerHub
if: github.event_name != 'pull_request' && steps.prep.outputs.tags
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
if: github.event_name != 'pull_request' && steps.prep.outputs.tags
id: docker_build
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/386
push: true
tags: ${{ steps.prep.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=pabra/awstats:buildcache
cache-to: type=registry,ref=pabra/awstats:buildcache,mode=max