Skip to content

Merge pull request #190 from eurofurence/dependabot/gradle/org.apache… #66

Merge pull request #190 from eurofurence/dependabot/gradle/org.apache…

Merge pull request #190 from eurofurence/dependabot/gradle/org.apache… #66

name: Create and publish Docker image
on:
push:
branches:
- 'main'
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
build-and-push-image:
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- name: install Java 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Checkout repository
run: 'git clone -b "$BRANCH_OR_TAG_NAME" --depth 1 "$FULL_REPO_URL" app'
shell: bash
env:
FULL_REPO_URL: "https://github.com/${{ github.repository }}"
BRANCH_OR_TAG_NAME: ${{ github.ref_name }}
- name: Log in to the Container registry
run: 'echo "$REGISTRY_PASS" | docker login "$REGISTRY" -u "$REGISTRY_USER" --password-stdin'
shell: bash
env:
REGISTRY: 'ghcr.io'
REGISTRY_USER: ${{ github.actor }}
REGISTRY_PASS: ${{ secrets.GITHUB_TOKEN }}
- name: Docker build and push 'latest' image
if: startsWith(github.ref, 'refs/heads/')
run: >
cd app &&
chmod 755 gradlew &&
./gradlew --no-daemon --console=plain clean jar &&
TAG_ARGS=$(echo -n "$IMAGE_TAGS" | sed -r "s_([^ :/]+)_ --tag $REGISTRY/$IMAGE_NAME:\1 _g") &&
docker build
--label org.opencontainers.image.url="$FULL_REPO_URL"
--label org.opencontainers.image.revision="$COMMIT_HASH"
$TAG_ARGS
--pull
. &&
docker push -a "$REGISTRY/$IMAGE_NAME"
shell: bash
env:
REGISTRY: 'ghcr.io'
IMAGE_NAME: ${{ github.repository }}
IMAGE_TAGS: latest
FULL_REPO_URL: "https://github.com/${{ github.repository }}"
COMMIT_HASH: ${{ github.sha }}
- name: Docker release build and push (v0.1)
if: startsWith(github.ref, 'refs/tags/v0.1.')
run: >
cd app &&
chmod 755 gradlew &&
./gradlew --no-daemon --console=plain clean jar &&
docker build
--label org.opencontainers.image.url="$FULL_REPO_URL"
--label org.opencontainers.image.revision="$COMMIT_HASH"
--label org.opencontainers.image.version="$IMAGE_TAG"
--tag $REGISTRY/$IMAGE_NAME:$IMAGE_TAG
--tag $REGISTRY/$IMAGE_NAME:v0.1
--pull
. &&
docker push -a "$REGISTRY/$IMAGE_NAME"
shell: bash
env:
REGISTRY: 'ghcr.io'
IMAGE_NAME: ${{ github.repository }}
IMAGE_TAG: ${{ github.ref_name }}
FULL_REPO_URL: "https://github.com/${{ github.repository }}"
COMMIT_HASH: ${{ github.sha }}