Build and Upload Docker Image #8
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: Build and Upload Docker Image | |
on: | |
push: | |
branches: | |
- main # Trigger the workflow on push or pull request to the main branch | |
workflow_dispatch: # Trigger the workflow manually from the Actions tab | |
jobs: | |
build-and-upload: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Scala 2.13.10 and sbt 1.8.2 | |
uses: olafurpg/setup-scala@v13 | |
with: | |
java-version: adopt@1.11 # Set up JDK 11 | |
scala-version: 2.13.10 | |
sbt-version: 1.8.2 | |
- name: Extract version | |
id: get_version | |
run: echo "$(grep -oP '(?<=ThisBuild / version := ").*(?=")' build.sbt)" > ${{ github.workspace }}/version.txt | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build Docker image | |
run: sbt clean docker:publishLocal | |
- name: Tag Docker image | |
run: | | |
VERSION=$(cat ${{ github.workspace }}/version.txt) | |
docker tag projectemo:$VERSION ghcr.io/vega113/projectemo:$VERSION | |
- name: Push Docker image | |
run: | | |
VERSION=$(cat ${{ github.workspace }}/version.txt) | |
docker push ghcr.io/vega113/projectemo:$VERSION |