Build Docker image with GitHub actions #4
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: Docker | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- 'v*' | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Coursier cache | |
uses: coursier/cache-action@v6 | |
- uses: coursier/setup-action@v1 | |
with: | |
jvm: adopt:8 | |
apps: sbt scala | |
- name: Compile and prepare Docker configuration | |
run: sbt docker | |
env: | |
DISABLE_ASSERTIONS: 1 | |
GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_TOKEN }} | |
- name: Log in to the GitHub Container registry | |
uses: docker/login-action@v2.1.0 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v4.1.1 | |
with: | |
images: michaelmior/jsonoid-server | |
tags: | | |
# semver tags | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
# set latest tag for default branch | |
type=raw,value=latest,enable={{is_default_branch}} | |
- name: Build and push image | |
uses: docker/build-push-action@v4 | |
with: | |
context: ./target/docker | |
load: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
- name: Build and push image | |
uses: docker/build-push-action@v4 | |
with: | |
context: ./target/docker | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |