-
Notifications
You must be signed in to change notification settings - Fork 295
88 lines (65 loc) · 2.41 KB
/
publish_image.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
name: publish_image
on:
push:
# Publish `master` as Docker `latest` image.
branches:
- master
tags:
- 2.*
env:
IMAGE_NAME: elastalert2
DOCKER_REPO: jertel/elastalert2
jobs:
push:
if: github.repository_owner == 'jertel'
environment: Main
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Log into GitHub Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
- name: Log into Docker Registry
run: echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Install buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
version: latest
- name: Build and Push multi-arch to Docker Hub
run: |
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
TAG2=""
if [[ "$VERSION" == "2."* ]]; then
TAG2="--tag $DOCKER_REPO:2"
fi
echo VERSION=$VERSION
echo TAG2=$TAG2
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx build \
--platform=linux/amd64,linux/arm64 \
--output "type=image,push=true" \
--file ./Dockerfile . \
--tag $DOCKER_REPO:$VERSION $TAG2
- name: Build and push image to GitHub
run: |
docker build . --file Dockerfile --tag $IMAGE_NAME
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$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,')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
# Push to GitHub Package
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
if [[ "$VERSION" == "2."* ]]; then
# Push to GitHub Package
docker tag $IMAGE_NAME $IMAGE_ID:2
docker push $IMAGE_ID:2
fi