Skip to content

Build and Push Container Images #19

Build and Push Container Images

Build and Push Container Images #19

name: Build and Push Container Images
on:
schedule:
- cron: "0 0 * * *"
release:
types: [ created ]
workflow_dispatch:
permissions:
contents: read
packages: write
env:
JAVA_VERSION: "21"
DISTRIBUTION: "corretto"
CONTAINER_REGISTRY: "ghcr.io"
CONTAINER_GROUP: "cloudeko/services"
MODULE_NAME: "zenei"
jobs:
test:
name: Run Tests
uses: ./.github/workflows/run-tests.yml
build-and-push:
needs: test
strategy:
matrix:
include:
- type: jvm
build_args: "-Dquarkus.container-image.build=true"
group: "cloudeko/services/jvm" # We cannot use this for now ${{ env.CONTAINER_GROUP }}. So we need to hardcode it.
- type: native
build_args: "-Dnative -Dquarkus.native.container-build=true"
group: "cloudeko/services" # We cannot use this for now ${{ env.CONTAINER_GROUP }}/native. So we need to hardcode it.
name: Build and Push ${{ matrix.type }} Image
environment: development
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache Maven Dependencies
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.DISTRIBUTION }}
cache: maven
- name: Determine Version and Image Name
id: meta
run: |
if [[ "${{ github.event_name }}" == "release" ]]; then
VERSION="${{ github.event.release.tag_name }}"
else
VERSION=$(echo $GITHUB_SHA | head -c7)-nightly
fi
IMAGE_NAME=$(echo "${{ env.MODULE_NAME }}" | sed -r 's/([a-z])([A-Z])/\1-\2/g' | tr '[:upper:]' '[:lower:]')
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
- name: Set Maven Version
run: mvn versions:set -DnewVersion=${{ steps.meta.outputs.version }}
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ${{ env.CONTAINER_REGISTRY }} -u ${{ github.actor }} --password-stdin
- name: Build and push images
run: |
mvn clean install -DskipTests \
${{ matrix.build_args }} \
-Dquarkus.container-image.push=true \
-Dquarkus.container-image.registry=${{ env.CONTAINER_REGISTRY }} \
-Dquarkus.container-image.group=${{ matrix.group }} \
-Dquarkus.container-image.name=${{ steps.meta.outputs.image_name }} \
-Dquarkus.container-image.tag=${{ steps.meta.outputs.version }}
if [[ "${{ github.event_name }}" == "release" ]]; then
mvn clean install -DskipTests \
${{ matrix.build_args }} \
-Dquarkus.container-image.push=true \
-Dquarkus.container-image.registry=${{ env.CONTAINER_REGISTRY }} \
-Dquarkus.container-image.group=${{ matrix.group }} \
-Dquarkus.container-image.name=${{ steps.meta.outputs.image_name }} \
-Dquarkus.container-image.tag=latest \
-Dquarkus.container-image.additional-tags=${{ steps.meta.outputs.version }}
fi