Skip to content

Publish Petclinic images #2

Publish Petclinic images

Publish Petclinic images #2

# This workflow will clone and build another Java project with Maven, and build and push Docker images to the GitHubs container registry
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
# https://docs.github.com/actions/use-cases-and-examples/publishing-packages/publishing-docker-images
name: Publish Petclinic images
on:
workflow_dispatch:
inputs:
petclinic_repo_url:
description: 'The repository url of Spring Petclinic microservices'
default: 'https://github.com/spring-petclinic/spring-petclinic-microservices.git'
image_tag_version:
description: 'The image tag version of Spring Petclinic microservices, default is the github run id + run_attempt'
defaults:
run:
shell: bash
working-directory: spring-petclinic-microservices
env:
REGISTRY: ghcr.io
IMAGE_INFIX: ${{ github.repository_owner }}/javaaccelerator
CUSTOMERS_SERVICE: spring-petclinic-customers-service
VETS_SERVICE: spring-petclinic-vets-service
VISITS_SERVICE: spring-petclinic-visits-service
API_GATEWAY: spring-petclinic-api-gateway
TAG_VERSION: ${{ inputs.image_tag_version != '' && inputs.image_tag_version || format('{0}{1}', github.run_id, github.run_attempt) }}
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Clone source repo
# Refer to https://github.com/actions/checkout/issues/24#issuecomment-1234831235 to check out another repository
run: |
git config --global url.https://github.com/.insteadOf git://github.com/
git clone ${{ inputs.petclinic_repo_url }}
- name: Build with Maven
run: |
cd spring-petclinic-microservices
mvn -B clean package --file pom.xml -DskipTests
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for customers-service
id: meta-customers
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_INFIX }}/${{ env.CUSTOMERS_SERVICE }}
tags: |
type=raw,value=latest
type=raw,value=${{ env.TAG_VERSION }}
- name: Build and push customers-service image
id: push-customers
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: spring-petclinic-microservices/
file: spring-petclinic-microservices/docker/Dockerfile
push: true
tags: ${{ steps.meta-customers.outputs.tags }}
build-args: ARTIFACT_NAME=${{ env.CUSTOMERS_SERVICE }}
- name: Extract metadata (tags, labels) for vets-service
id: meta-vets
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_INFIX }}/${{ env.VETS_SERVICE }}
tags: |
type=raw,value=latest
type=raw,value=${{ env.TAG_VERSION }}
- name: Build and push vets-service image
id: push-vets
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: spring-petclinic-microservices/
file: spring-petclinic-microservices/docker/Dockerfile
push: true
tags: ${{ steps.meta-vets.outputs.tags }}
build-args: ARTIFACT_NAME=${{ env.VETS_SERVICE }}
- name: Extract metadata (tags, labels) for visits-service
id: meta-visits
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_INFIX }}/${{ env.VISITS_SERVICE }}
tags: |
type=raw,value=latest
type=raw,value=${{ env.TAG_VERSION }}
- name: Build and push visits-service image
id: push-visits
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: spring-petclinic-microservices/
file: spring-petclinic-microservices/docker/Dockerfile
push: true
tags: ${{ steps.meta-visits.outputs.tags }}
build-args: ARTIFACT_NAME=${{ env.VISITS_SERVICE }}
- name: Extract metadata (tags, labels) for api-gateway
id: meta-api
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_INFIX }}/${{ env.API_GATEWAY }}
tags: |
type=raw,value=latest
type=raw,value=${{ env.TAG_VERSION }}
- name: Build and push api-gateway image
id: push-api
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: spring-petclinic-microservices/
file: spring-petclinic-microservices/docker/Dockerfile
push: true
tags: ${{ steps.meta-api.outputs.tags }}
build-args: |
ARTIFACT_NAME=${{ env.API_GATEWAY }}
EXPOSED_PORT=8080