Compose and execute disjunction of basic patterns (#5) #39
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: odinson-rest docker | |
on: | |
push: | |
branches: [main] | |
tags: | |
- "**" | |
pull_request: | |
branches: [main] | |
release: | |
types: [published] | |
# builds and publishes docker images for the default branch. | |
# images are tagged with short commit hash, latest, and any tags. | |
jobs: | |
# Determine value for app version | |
app_version: | |
name: "Determine app version" | |
runs-on: ubuntu-latest | |
outputs: | |
app_version: ${{ steps.app_version.outputs.app_version }} | |
commit: ${{ steps.app_version.outputs.commit }} | |
steps: | |
- name: Set APP_VERSION output | |
id: app_version | |
run: | | |
echo "app_version=${{github.ref_name}}" | |
if [ -z "${app_version}" ]; then | |
app_version=${{github.sha}} | |
echo "app_version=${app_version}" | |
fi | |
echo "app_version=$app_version" >> "$GITHUB_OUTPUT" | |
echo "commit=${{github.sha}}" >> "$GITHUB_OUTPUT" | |
echo "app_version=$app_version" | |
echo "commit=${{github.sha}}" | |
rest: | |
name: "docker image for REST API" | |
needs: [app_version] | |
runs-on: ubuntu-latest | |
steps: | |
# Setup docker | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
# for multi-arch builds (ex. ARM 64) | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
buildkitd-flags: --debug | |
# - name: Prepare buildx builder | |
# run: | | |
# docker buildx create --use --name "multiarch-builder" --platform linux/amd64,linux/arm64 --driver "docker-container" | |
- name: Inspect builder | |
run: | | |
echo "Name: ${{ steps.buildx.outputs.name }}" | |
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" | |
echo "Status: ${{ steps.buildx.outputs.status }}" | |
echo "Flags: ${{ steps.buildx.outputs.flags }}" | |
echo "Platforms: ${{ steps.buildx.outputs.platforms }}" | |
# Checkout code | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
######################################## | |
# lumai/odinson-rest-api | |
######################################## | |
- name: Setup JDK (w/ SBT) | |
uses: actions/setup-java@v3 | |
with: | |
distribution: temurin | |
java-version: 11 | |
#cache: 'sbt' | |
- name: Generate Dockerfile | |
working-directory: . | |
env: | |
#APP_VERSION: ${{needs.app_version.outputs.app_version}} | |
APP_VERSION: ${{needs.app_version.outputs.commit}} | |
run: | | |
sbt "docker:stage" | |
- name: Tags for image | |
id: tags | |
# see https://github.com/docker/metadata-action | |
uses: docker/metadata-action@v4 | |
with: | |
images: lumai/odinson-rest-api | |
tags: | | |
# latest | |
type=raw,value=latest | |
# version | |
type=semver,pattern={{version}} | |
# other tags | |
type=ref,event=tag | |
# short commit hash | |
type=sha | |
- name: Build and push image | |
# see https://github.com/docker/build-push-action | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./target/docker/stage | |
platforms: linux/amd64,linux/arm64 | |
provenance: false | |
push: true | |
# FIXME: re-enable the option below when ready for PR | |
#push: ${{ github.event_name != 'pull_request' }} | |
# references `tags` step in steps for current job | |
tags: ${{ steps.tags.outputs.tags }} |