-
Notifications
You must be signed in to change notification settings - Fork 1
114 lines (97 loc) · 3.54 KB
/
build_images.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
---
name: 'build images'
on:
push:
branches:
- '**'
# - 'main'
tags:
- 'v*'
jobs:
docker:
runs-on: ubuntu-latest
env:
# Fallback version for builds
BUILD_VERSION: "0.5.5"
steps:
- name: Checkout
uses: actions/checkout@v2
with:
# Get all history including tags
fetch-depth: 0
- name: Prepare OpenCanary build version
id: prep
run: |
PREPARED_BUILD_VERSION=${BUILD_VERSION}
CURRENT_BRANCH=undef
# If this is git tag, use the tag name
if [[ $GITHUB_REF == refs/tags/* ]]; then
PREPARED_BUILD_VERSION=${GITHUB_REF#refs/tags/v}
else
GIT_LATEST_TAG_REF=$(git rev-list --tags --max-count=1)
# Check if there is latest tag set
if [[ -n "$GIT_LATEST_TAG_REF" ]]; then
GIT_LATEST_TAG=$(git describe --tags $GIT_LATEST_TAG_REF)
PREPARED_BUILD_VERSION=${GIT_LATEST_TAG#v}
fi
fi
# If this is git branch, use the branch name
if [[ $GITHUB_REF == refs/heads/* ]]; then
CURRENT_BRANCH=${GITHUB_REF#refs/heads/}
fi
# Set output parameters.
echo ::set-output name=prepared_build_version::${PREPARED_BUILD_VERSION}
echo ::set-output name=current_branch::${CURRENT_BRANCH}
- name: Current branch
run: echo ${{ steps.prep.outputs.current_branch }}
- name: Current build version
run: echo ${{ steps.prep.outputs.prepared_build_version }}
- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v3
with:
images: ${{ secrets.DOCKER_HUB_REPOSITORY }}
tags: |
type=sha,priority=100
type=ref,priority=500,event=branch
type=semver,priority=800,pattern={{version}}
type=semver,priority=850,pattern={{major}}.{{minor}}
type=semver,priority=900,pattern={{major}}.{{minor}}.{{patch}}
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@master
with:
# platforms: all
platforms: amd64,arm,arm64
- name: Available platforms
run: echo ${{ steps.qemu.outputs.platforms }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
if: github.event_name != 'pull_request' && steps.prep.outputs.current_branch == 'main'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build and Push
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
push: ${{ github.event_name != 'pull_request' && steps.prep.outputs.current_branch == 'main' }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
build-args: |
VERSION=${{ steps.prep.outputs.prepared_build_version }}