Skip to content

Build and Push Container image to Quay.io 🚀 #118

Build and Push Container image to Quay.io 🚀

Build and Push Container image to Quay.io 🚀 #118

name: build-and-push-quay
run-name: Build and Push Container image to Quay.io 🚀
env:
IMAGE_BASE_NAME: "quay.io/alopezme/quarkus-observability-app"
NATIVE_JAVA_VERSION: "21"
# This section allows the workflow to create a Release
# https://github.com/softprops/action-gh-release/issues/236#issuecomment-1150530128
permissions:
contents: write
# This section ensures that new pushes cancel current executions of the workflow
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
on:
# schedule:
# - cron: '0 10 * * *'
push:
branches:
- 'releases/**'
- 'main'
tags:
- '[0-9]+.[0-9]+.[0-9]+'
paths:
- 'src/**'
- 'pom.xml'
- '.dockerignore'
- '.gitignore'
- '.github/workflows/build-and-push-quay.yml'
jobs:
build-native-artifact:
runs-on: ubuntu-latest
name: "Build Native Package"
steps:
- name: Checkout the code
uses: actions/checkout@v4
# https://github.com/orgs/community/discussions/55854
# - name: Verify Semver
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: ${{ env.NATIVE_JAVA_VERSION }}
distribution: temurin
cache: maven
- name: Build native executable
run: ./mvnw install --no-transfer-progress -Dnative -DskipTests -Dquarkus.native.remote-container-build=true
- name: Release if it is a new tag
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: target/*-runner
generate_release_notes: true
- name: Upload native executable
uses: actions/upload-artifact@v4
with:
name: native-executable
path: target/*-runner
build-and-push-image:
runs-on: ubuntu-latest
needs:
- build-native-artifact
name: "Build Native Image"
steps:
- name: Checkout the code
uses: actions/checkout@v4
- name: Download the native executable
uses: actions/download-artifact@v4
with:
name: native-executable
path: target
- name: Login to Quay.io
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_REPO_USERNAME }}
password: ${{ secrets.QUAY_REPO_TOKEN }}
- name: Build and push image - Mini
uses: docker/build-push-action@v6
with:
push: true
context: .
file: src/main/docker/Dockerfile.native
tags: ${{ env.IMAGE_BASE_NAME }}:latest
- name: Build and push image - Micro
uses: docker/build-push-action@v6
with:
push: true
context: .
file: src/main/docker/Dockerfile.native-micro
tags: ${{ env.IMAGE_BASE_NAME }}:latest-micro
- name: Build and push image - Tag
uses: docker/build-push-action@v6
with:
push: true
context: .
file: src/main/docker/Dockerfile.native-micro
# Hack for pseudo ternary expression: If no tag => Latest, if not, tag value
# Source: https://github.com/orgs/community/discussions/25725#discussioncomment-3248924
tags: ${{ env.IMAGE_BASE_NAME }}:${{ github.ref_name }}
if: startsWith(github.ref, 'refs/tags/')
- name: Build and push image - Expiration
uses: docker/build-push-action@v6
with:
push: true
context: .
file: src/main/docker/Dockerfile.add-expiration
tags: ${{ env.IMAGE_BASE_NAME }}:latest-micro-expiration
build-args: |
IMAGE_NAME=${{ env.IMAGE_BASE_NAME }}
IMAGE_TAG=latest-micro
EXPIRATION_TIME=2h