Merge pull request #153 from wildmountainfarms/dependabot/gradle/com.… #90
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: Create and publish a Docker image | |
on: | |
push: | |
branches: | |
- master | |
- dev | |
tags: | |
- 'v*' | |
env: | |
REGISTRY: ghcr.io | |
jobs: | |
build-push: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
strategy: | |
matrix: | |
data: | |
- image-name: solarthing | |
display-name: "SolarThing" | |
build-command: "client:shadowJar" | |
jar-location: "client/build/libs/client-0.0.1-SNAPSHOT-all.jar" | |
- image-name: solarthing-server | |
display-name: "SolarThing Server" | |
build-command: "server:bootJar" | |
jar-location: "server/build/libs/server-0.0.1-SNAPSHOT.jar" | |
env: | |
platforms: ${{ github.ref == 'refs/heads/dev' && 'linux/amd64,linux/arm/v7' || 'linux/amd64,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x' }} | |
steps: | |
# https://github.com/marketplace/actions/checkout | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
# https://github.com/marketplace/actions/setup-java-jdk#supported-distributions | |
distribution: 'temurin' | |
java-version: 17 | |
- if: matrix.data.image-name == 'solarthing-server' | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
- if: matrix.data.image-name == 'solarthing-server' | |
name: Install dependencies | |
run: (cd web && npm install) | |
- name: Build Jar | |
run: ./gradlew ${{ matrix.data.build-command }} | |
# https://github.com/marketplace/actions/docker-login | |
- name: Log in to the Container registry | |
uses: docker/login-action@v2.2.0 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# https://github.com/marketplace/actions/docker-metadata-action | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v4.6.0 | |
with: | |
images: ${{ env.REGISTRY }}/wildmountainfarms/${{ matrix.data.image-name }} | |
# expressions: https://docs.github.com/en/actions/learn-github-actions/expressions | |
tags: | | |
# in our case {{major}} is actually a year, so it's not really signifying a major release | |
type=semver,pattern={{major}}.{{minor}}.{{patch}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=raw,value=latest,priority=750,enable=${{ startsWith(github.ref, 'refs/tags/') && !contains(github.ref, 'rc') && !contains(github.ref, 'beta') }} | |
type=raw,value=beta,priority=740,enable=${{ startsWith(github.ref, 'refs/tags/')}} | |
type=edge,branch=master | |
type=raw,value=dev,enable=${{ github.ref == 'refs/heads/dev' }} | |
type=sha,format=short | |
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys | |
labels: | | |
maintainer=retrodaredevil | |
org.opencontainers.image.title=${{ matrix.data.display-name }} | |
org.opencontainers.image.description=${{ matrix.data.display-name }} running in a docker container | |
org.opencontainers.image.source=https://github.com/wildmountainfarms/solarthing | |
org.opencontainers.image.ref.name=${{ matrix.data.image-name }} | |
org.opencontainers.image.vendor=wildmountainfarms | |
org.opencontainers.image.documentation=https://solarthing.readthedocs.io/en/latest/ | |
org.opencontainers.image.url=https://solarthing.readthedocs.io/en/latest/ | |
org.opencontainers.image.authors=retrodaredevil | |
org.opencontainers.image.base.name=docker.io/eclipse-temurin:19-jre-jammy | |
# https://github.com/marketplace/actions/docker-setup-buildx | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
# https://github.com/marketplace/actions/build-and-push-docker-images | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v4.2.1 | |
with: | |
context: . | |
file: docker/${{ matrix.data.image-name }}/Dockerfile | |
build-args: | | |
JAR_LOCATION=${{ matrix.data.jar-location }} | |
COMMIT_HASH=${{ github.sha }} | |
REF=${{ github.ref }} | |
push: true | |
platforms: ${{ env.platforms }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |