Skip to content

Commit

Permalink
Add flavors (#4)
Browse files Browse the repository at this point in the history
* Add flavors

* Update action.yml

Co-authored-by: Camill Kaipf <87362681+ckaipf@users.noreply.github.com>

* Update action.yml

Co-authored-by: Camill Kaipf <87362681+ckaipf@users.noreply.github.com>

---------

Co-authored-by: Camill Kaipf <87362681+ckaipf@users.noreply.github.com>
  • Loading branch information
lkuchenb and ckaipf authored Jul 30, 2024
1 parent 13a2ff5 commit 73cf015
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
20 changes: 19 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ inputs:
dockerhub_platforms:
description: "Platforms passed to DockerHub build and push action."
default: "linux/amd64,linux/arm64"
flavor:
description: "Flavor to build. Expects 'Dockerfile.{flavor} to be present and appends '-{flavor}' to the tag."
default: ""

runs:
using: "composite"
Expand All @@ -65,9 +68,11 @@ runs:
run: |
if [ -f "setup.py" ]
then
echo "Using setup.py to extract python package version"
PKG_VER="$(python setup.py --version)"
elif [ -f "pyproject.toml" ]
then
echo "Using pyproject.toml to extract python package version"
version=$(python3.12 -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
PKG_VER=$version
else
Expand Down Expand Up @@ -96,13 +101,26 @@ runs:
username: ${{ inputs.dockerhub_username }}
password: ${{ inputs.dockerhub_token }}

- name: Construct Dockerfile and tag suffixes
shell: bash
id: get_suffixes
run: |
if [ -n "${{ inputs.flavor }}" ]; then
echo "dockerfile_suffix=.${{ inputs.flavor }}" >> $GITHUB_OUTPUT
echo "tag_suffix=-${{ inputs.flavor }}" >> $GITHUB_OUTPUT
else
echo "dockerfile_suffix=" >> $GITHUB_OUTPUT
echo "tag_suffix=" >> $GITHUB_OUTPUT
fi
- uses: docker/build-push-action@v5
name: Build and push
id: docker_build
with:
push: true
platforms: "${{ inputs.dockerhub_platforms }}"
tags: "${{ inputs.dockerhub_namespace }}/${{ github.event.repository.name }}:${{ inputs.tag }}"
file: "${{ inputs.working_directory }}/Dockerfile${{ steps.get_suffixes.outputs.dockerfile_suffix }}"
tags: "${{ inputs.dockerhub_namespace }}/${{ github.event.repository.name }}:${{ inputs.tag }}${{ steps.get_suffixes.outputs.tag_suffix }}"
context: "${{ inputs.working_directory }}"

- name: Run Trivy vulnerability scanner
Expand Down
2 changes: 2 additions & 0 deletions test/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM python:3.10.9-alpine
WORKDIR /
7 changes: 6 additions & 1 deletion test/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:

jobs:
test_action:
strategy:
matrix:
flavor: ["", "alpine"]
runs-on: ubuntu-latest
name: Install and test action
steps:
Expand All @@ -16,8 +19,9 @@ jobs:
dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }}
working_directory: ./test
tag: "0.0.0"
dockerhub_namespace: camillkaipf
dockerhub_namespace: datametaci
trivy_severity: "CRITICAL"
flavor: ${{ matrix.flavor }}
- name: Test release
uses: ghga-de/gh-action-ci@v1.0.0
with:
Expand All @@ -26,3 +30,4 @@ jobs:
working_directory: ./test
tag: "0.0.0"
trivy_severity: "CRITICAL"
flavor: ${{ matrix.flavor }}

0 comments on commit 73cf015

Please sign in to comment.