-
Notifications
You must be signed in to change notification settings - Fork 649
62 lines (62 loc) · 2.29 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
name: Docker
on: [ push, pull_request ]
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Decide whether to push to DockerHub, and set tag
if: |
github.event_name == 'push' &&
( startsWith( github.ref, 'refs/tags/' ) ||
contains( fromJSON('["master","develop","testnet","hardfork"]'), github.ref_name ) )
run: |
if [ "${GITHUB_REF_NAME}" == "master" ] ; then
DOCKER_PUSH_TAG=latest
else
DOCKER_PUSH_TAG=${GITHUB_REF_NAME}
fi
echo "DOCKER_PUSH_TAG=${DOCKER_PUSH_TAG}"
echo "DOCKER_PUSH_TAG=${DOCKER_PUSH_TAG}" >> $GITHUB_ENV
VERSION_MAJOR=`echo "${DOCKER_PUSH_TAG}" | cut -f1 -d'.'`
if [ "${VERSION_MAJOR}" != "${DOCKER_PUSH_TAG}" ]; then
VERSION_MINOR=`echo "${DOCKER_PUSH_TAG}" | cut -f2 -d'.'`
DOCKER_PUSH_TAG_SHORT=${VERSION_MAJOR}.${VERSION_MINOR}
if [ "${DOCKER_PUSH_TAG_SHORT}" != "${DOCKER_PUSH_TAG}" ]; then
echo "DOCKER_PUSH_TAG_SHORT=${DOCKER_PUSH_TAG_SHORT}"
echo "DOCKER_PUSH_TAG_SHORT=${DOCKER_PUSH_TAG_SHORT}" >> $GITHUB_ENV
fi
fi
- name: Test tag
if: env.DOCKER_PUSH_TAG != ''
run: echo "${DOCKER_PUSH_TAG}"
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build only
uses: docker/build-push-action@v4
with:
context: .
load: true
- name: Login to DockerHub
if: env.DOCKER_PUSH_TAG != ''
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push to DockerHub (for branches)
if: env.DOCKER_PUSH_TAG != '' && env.DOCKER_PUSH_TAG_SHORT == ''
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_REPO_PATH }}:${{ env.DOCKER_PUSH_TAG }}
- name: Push to DockerHub (for tags)
if: env.DOCKER_PUSH_TAG != '' && env.DOCKER_PUSH_TAG_SHORT != ''
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: |
${{ secrets.DOCKERHUB_REPO_PATH }}:${{ env.DOCKER_PUSH_TAG }}
${{ secrets.DOCKERHUB_REPO_PATH }}:${{ env.DOCKER_PUSH_TAG_SHORT }}