Skip to content

Commit

Permalink
added matrix based build (#3)
Browse files Browse the repository at this point in the history
* added matrix based build

* 3.11 pypy doesn't exist
  • Loading branch information
hellt authored Sep 28, 2023
1 parent 4152335 commit 37ea20b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 26 deletions.
43 changes: 43 additions & 0 deletions .github/matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2023 Nokia
# Licensed under the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause

# a matrix list of variables used in the container build process
#
# python version are taken from ansible's support matrix - https://docs.ansible.com/ansible/latest/reference_appendices/release_and_maintenance.html#support-life
include:
# 2.11.11
- base-image: "pypy:3.10-slim"
ansible-core-version: "2.11.11"
runs-on: "ubuntu-22.04"

- base-image: "python:3.10-slim"
ansible-core-version: "2.11.11"
runs-on: "ubuntu-22.04"

# 2.12.10
- base-image: "pypy:3.10-slim"
ansible-core-version: "2.12.10"
runs-on: "ubuntu-22.04"

- base-image: "python:3.10-slim"
ansible-core-version: "2.12.10"
runs-on: "ubuntu-22.04"

# 2.13.12
- base-image: "pypy:3.10-slim"
ansible-core-version: "2.13.12"
runs-on: "ubuntu-22.04"

- base-image: "python:3.10-slim"
ansible-core-version: "2.13.12"
runs-on: "ubuntu-22.04"

# 2.14.10
- base-image: "pypy:3.10-slim"
ansible-core-version: "2.14.10"
runs-on: "ubuntu-22.04"

- base-image: "python:3.11-slim"
ansible-core-version: "2.14.10"
runs-on: "ubuntu-22.04"
54 changes: 29 additions & 25 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,41 @@ name: Container build
release:
types:
- published
push:
pull_request:

jobs:
build:
name: Build container
prepare-matrix:
runs-on: ubuntu-22.04
strategy:
matrix:
py-base-image:
- pypy:3.10-slim
- python:3.10-slim

outputs:
matrix: ${{ steps.matrix.outputs.output }}
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: |
echo "$GITHUB_CONTEXT"
- uses: actions/checkout@v3
- uses: fabasoad/data-format-converter-action@main
id: matrix
with:
input: ".github/matrix.yml"
from: "yaml"
to: "json"

build:
name: Build container
needs: prepare-matrix
runs-on: ${{ matrix.runs-on }}
strategy:
# fail-fast: false
matrix: ${{ fromJson(needs.prepare-matrix.outputs.matrix) }}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up QEMU
if: ${{ !github.event.act }}
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
Expand All @@ -34,7 +46,7 @@ jobs:
- name: Process base image
id: base-image
run: |
PY_VERSION=$(./run.sh extract-version "${{ matrix.py-base-image }}")
PY_VERSION=$(./run.sh extract-version "${{ matrix.base-image }}")
echo "::set-output name=py-version::$PY_VERSION"
- name: Docker meta
Expand All @@ -44,8 +56,8 @@ jobs:
images: |
ghcr.io/${{ github.repository }}/${{ steps.base-image.outputs.py-version }}
tags: |
type=ref,event=tag
type=ref,event=branch
type=schedule
type=raw,value=${{ matrix.ansible-core-version }}
# git short commit
type=sha
Expand All @@ -55,30 +67,22 @@ jobs:
context: .
load: true
build-args: |
BASE_IMAGE=${{ matrix.py-base-image }}
BASE_IMAGE=${{ matrix.base-image }}
ANSIBLE_CORE_VERSION=${{ matrix.ansible-core-version }}
tags: app:latest

- name: Test
run: |
docker run --rm app:latest ansible --version
- name: Login to GitHub Container Registry
if: github.event_name == 'release'
if: github.event_name == 'release' && !github.event.act
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Process ansible core version
if: github.event_name == 'release'
id: ansible-core-version
run: |
TAG_NAME=${{ github.event.release.tag_name }}
TAG_NAME=${TAG_NAME#v} # remove the leading v
echo "Tag name without leading v: $TAG_NAME"
echo "::set-output name=ansible-core-version::$TAG_NAME"
- name: Build and Push
if: github.event_name == 'release' && !github.event.act
uses: docker/build-push-action@v4
Expand All @@ -87,6 +91,6 @@ jobs:
push: true
platforms: linux/amd64,linux/arm64
build-args: |
BASE_IMAGE=${{ matrix.py-base-image }}
ANSIBLE_CORE_VERSION=${{ steps.ansible-core-version.outputs.ansible-core-version }}
BASE_IMAGE=${{ matrix.base-image }}
ANSIBLE_CORE_VERSION=${{ matrix.ansible-core-version }}
tags: ${{ steps.meta.outputs.tags }}
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function build {

# testing release-triggered workflow
function test-act-release {
gh act release -W '.github/workflows/build-release.yml' -e .github/workflows/release-event.json -s GITHUB_TOKEN="$(gh auth token)" --matrix py-base-image:pypy:3.10-slim
gh act release -W '.github/workflows/build-release.yml' -e .github/workflows/release-event.json -s GITHUB_TOKEN="$(gh auth token)" --matrix base-image:python:3.10-slim
}

# -----------------------------------------------------------------------------
Expand Down

0 comments on commit 37ea20b

Please sign in to comment.