-
Notifications
You must be signed in to change notification settings - Fork 148
67 lines (63 loc) · 2.31 KB
/
build-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
---
name: Build and push docker images
env:
DOCKERHUB_REPOSITORY: traccar/traccar
on:
push:
branches:
- master
- v[0-9]+.[0-9]+
defaults:
run:
shell: bash
jobs:
docker-build-push:
name: Build and push docker images
runs-on: ubuntu-22.04
strategy:
matrix:
os: [alpine, debian, ubuntu]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set environment DOCKERHUB_IMAGE_TAGS on master
if: github.ref == 'refs/heads/master' && matrix.os == 'alpine'
run: echo "DOCKERHUB_IMAGE_TAGS=$DOCKERHUB_REPOSITORY:latest" >> $GITHUB_ENV
- name: Set environment DOCKERHUB_IMAGE_TAGS
if: github.ref != 'refs/heads/master'
run: |
_BRANCH=${GITHUB_REF##*/}
_VERSION=${_BRANCH#v*}
_MAJOR_VERSION=${_VERSION%.*}
_DOCKERHUB_IMAGE_TAGS="$DOCKERHUB_REPOSITORY:$_VERSION-${{ matrix.os }}"
_DOCKERHUB_IMAGE_TAGS+=",$DOCKERHUB_REPOSITORY:$_MAJOR_VERSION-${{ matrix.os }}"
_DOCKERHUB_IMAGE_TAGS+=",$DOCKERHUB_REPOSITORY:${{ matrix.os }}"
if [ "${{ matrix.os }}" == "alpine" ]; then
_DOCKERHUB_IMAGE_TAGS+=",$DOCKERHUB_REPOSITORY:$_VERSION"
_DOCKERHUB_IMAGE_TAGS+=",$DOCKERHUB_REPOSITORY:$_MAJOR_VERSION"
fi
echo "DOCKERHUB_IMAGE_TAGS=$_DOCKERHUB_IMAGE_TAGS" >> $GITHUB_ENV
- name: Set environment DOCKERHUB_IMAGE_PLATFORMS
run: |
_DOCKERHUB_IMAGE_PLATFORMS="linux/amd64,linux/arm64"
if [ "${{ matrix.os }}" == "ubuntu" ]; then
_DOCKERHUB_IMAGE_PLATFORMS+=",linux/arm/v7"
fi
echo "DOCKERHUB_IMAGE_PLATFORMS=$_DOCKERHUB_IMAGE_PLATFORMS" >> $GITHUB_ENV
- name: Build and push
if: env.DOCKERHUB_IMAGE_TAGS != ''
uses: docker/build-push-action@v4
with:
file: Dockerfile.${{ matrix.os }}
tags: ${{ env.DOCKERHUB_IMAGE_TAGS }}
platforms: ${{ env.DOCKERHUB_IMAGE_PLATFORMS }}
push: true