Skip to content

Docker Build and Push #2599

Docker Build and Push

Docker Build and Push #2599

Workflow file for this run

---
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@v1
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@v2
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@v2
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@v2
if: startsWith(github.ref, 'refs/tags/')
with:
tags: kapicorp/kapitan:${{ format('{0}', env.MAJOR_VERSION ) }}
platforms: linux/amd64,linux/arm64
file: Dockerfile