Skip to content

feat(build): added build-push-container-images.yml #5

feat(build): added build-push-container-images.yml

feat(build): added build-push-container-images.yml #5

name: Build and Push Container Images
on:
push:
branches:
- master
permissions:
contents: read
packages: write
env:
JAVA_VERSION: "21"
DISTRIBUTION: "corretto"
CONTAINER_REGISTRY: "ghcr.io"
CONTAINER_GROUP: "cloudeko/services"
MODULE_NAME: "zenei"
jobs:
build-and-push:
strategy:
matrix:
include:
- type: jvm
build_args: "-Dquarkus.container-image.build=true"
group: "cloudeko/services" # 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/native" # 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: Calculate Short SHA and Image Name
id: meta
run: |
echo "short_sha=$(echo $GITHUB_SHA | head -c7)" >> $GITHUB_OUTPUT
IMAGE_NAME=$(echo "${{ env.MODULE_NAME }}" | sed -r 's/([a-z])([A-Z])/\1-\2/g' | tr '[:upper:]' '[:lower:]')
echo "image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
- name: Set Maven Version
run: mvn versions:set -DnewVersion=${{ steps.meta.outputs.short_sha }}
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ${{ env.CONTAINER_REGISTRY }} -u ${{ github.actor }} --password-stdin
- name: Build and push image
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.short_sha }}