Skip to content

Docker Build for ademariag on branch master #733

Docker Build for ademariag on branch master

Docker Build for ademariag on branch master #733

---
name: Test, Build and Publish docker image
run-name: Docker Build for ${{ github.actor }} on branch ${{ github.ref_name }}
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
on:
push:
branches:
- master
- main
- test/*
paths-ignore:
- 'docs/**'
- '.github/workflows/documentation.yml'
- 'mkdocs.yml'
- 'CNAME'
release:
types: [created]
pull_request:
paths-ignore:
- 'docs/**'
- '.github/workflows/documentation.yml'
- 'mkdocs.yml'
- 'CNAME'
jobs:
precommit:
name: precommit checks
runs-on: ubuntu-latest
if: success() || failure() # Continue running if other jobs fail
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/[email protected]
test:
name: python ${{ matrix.python-version }} tests
runs-on: ubuntu-latest
if: success() || failure() # Continue running if other jobs fail
strategy:
fail-fast: false
matrix:
python-version: ['3.10', '3.11', '3.12']
steps:
- name: Checkout kapitan recursively
uses: actions/checkout@v4
with:
submodules: recursive
- name: Install poetry
run: pipx install poetry
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
cache: 'poetry'
python-version: ${{ matrix.python-version }}
- name: Install libraries dependencies
run: |
poetry install --with test --no-root --extras=gojsonnet --extras=omegaconf --extras=reclass-rs
- name: Install testing dependencies (Helm)
run: |
sudo apt-get -qq update
sudo apt-get install -y gnupg2 git curl
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
- name: Run pytest
uses: pavelzw/pytest-action@v2
with:
verbose: true
emoji: false
job-summary: true
custom-pytest: poetry run pytest
custom-arguments: '-q'
click-to-expand: true
report-title: 'Kapitan tests'
build:
name: build ${{ matrix.platform }} image
if: success() || failure() # Continue running if other jobs fail
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
- name: Checkout kapitan recursively
uses: actions/checkout@v4
with:
submodules: recursive
# 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@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Builds docker image and allow scoped caching
- name: build Kapitan Image
uses: docker/build-push-action@v6
with:
push: False
platforms: ${{ matrix.platform }}
load: True
file: Dockerfile
tags: local-test-${{ matrix.platform }}
cache-from: type=gha,scope=$GITHUB_REF_NAME-${{ matrix.platform }}
cache-to: type=gha,mode=max,scope=$GITHUB_REF_NAME-${{ matrix.platform }}
- name: Test Kapitan for ${{ matrix.platform }}
run: |
docker run -t --rm local-test-${{ matrix.platform }} --version
publish:
name: publish platform images
# Only starts if everything else is successful
needs: [precommit, test, build]
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
- name: Checkout kapitan recursively
uses: actions/checkout@v4
with:
submodules: recursive
# 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@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME}}
if: env.DOCKERHUB_USERNAME != null
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME}}
with:
# list of Docker images to use as base name for tags
images: |
name=${{ vars.DOCKERHUB_REPOSITORY }}/kapitan
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
flavor: |
latest=auto
suffix=-${{ matrix.platform }},onlatest=true
- name: Build and push by digest
id: push-digest
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME}}
if: env.DOCKERHUB_USERNAME != null
uses: docker/build-push-action@v6
with:
platforms: ${{ matrix.platform }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{steps.meta.outputs.labels}}
cache-from: type=gha,scope=$GITHUB_REF_NAME-${{ matrix.platform }}
cache-to: type=gha,mode=max,scope=$GITHUB_REF_NAME-${{ matrix.platform }}
build-multi-architecture:
name: combine platform images
needs:
- publish
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
# 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@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME}}
if: env.DOCKERHUB_USERNAME != null
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME}}
with:
# list of Docker images to use as base name for tags
images: |
name=${{ vars.DOCKERHUB_REPOSITORY }}/kapitan
# generate Docker tags based on the following events/attributes
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- uses: int128/docker-manifest-create-action@v1
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME}}
if: env.DOCKERHUB_USERNAME != null
with:
tags: ${{ steps.meta.outputs.tags }}
builder: buildx
suffixes: |
-linux-amd64
-linux-arm64