-
Notifications
You must be signed in to change notification settings - Fork 199
76 lines (71 loc) · 2.7 KB
/
docker-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
---
name: Docker Build and Push
on:
push:
paths-ignore:
- 'docs/**'
workflow_run:
workflows:
- Python Tests
types:
- completed
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout kapitan recursively
uses: actions/checkout@master
with:
submodules: recursive
- name: Strip git ref prefix from tag version and store in TAG_VERSION
run: |
echo "TAG_VERSION=${GITHUB_REF#refs/*/v}" >> $GITHUB_ENV
echo "REF_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV
- name: Strip full version and just keep major part in MAJOR_VERSION VAR
run: |
echo "MAJOR_VERSION=${TAG_VERSION:0:4}" >> $GITHUB_ENV
# Printing versions needs to be a separate step,
# as they aren't set during the previous two steps
- name: Print Versions
run: |
echo ${{ env.TAG_VERSION }}
echo ${{ env.MAJOR_VERSION }}
echo ${{ env.REF_NAME }}
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Setup QEMU and Buildx to build multi-platform image
# This was inspired by this example : https://docs.docker.com/build/ci/github-actions/examples/#multi-platform-images
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build PR/versioned tags
if: github.ref != 'refs/heads/master'
uses: docker/build-push-action@v4
with:
tags: kapicorp/kapitan:${{ format('{0}', env.REF_NAME ) }}
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }} # push image only on non-pull_requests
file: Dockerfile
# TODO push and tag as latest if release (and not RC)
- name: Build latest tag
uses: docker/build-push-action@v4
if: github.ref == 'refs/heads/master'
with:
tags: kapicorp/kapitan:${{ format('{0}', env.REF_NAME ) }},kapicorp/kapitan:latest
platforms: linux/amd64,linux/arm64
file: Dockerfile
- name: Test Dockerfile in current ref
run: |
[ ${{ env.REF_NAME }} == "master" ] && tagname="latest" || tagname=${{ env.REF_NAME }}
docker run -t --rm kapicorp/kapitan:${tagname} --version
- name: Build major version tag
uses: docker/build-push-action@v4
if: startsWith(github.ref, 'refs/tags/')
with:
tags: kapicorp/kapitan:${{ format('{0}', env.MAJOR_VERSION ) }}
platforms: linux/amd64,linux/arm64
file: Dockerfile