From 67114c32345b17781990009cf8faec9db3c7c935 Mon Sep 17 00:00:00 2001 From: Robbie Blaine Date: Tue, 7 Nov 2023 12:00:58 +0200 Subject: [PATCH] Docker Build --- .github/workflows/ci.yml | 55 ++++++++++++++++++++++++++++++++++++++++ Dockerfile | 6 +++++ README.md | 5 ++-- 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1e306d2..3808696 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,9 @@ concurrency: group: cicd-${{ github.ref }} cancel-in-progress: true +env: + REGISTRY: ghcr.io/${{ github.repository_owner }} + jobs: test: name: Test @@ -31,3 +34,55 @@ jobs: jvm: 21 - run: scala-cli fmt --check . - run: scala-cli --power test . + + build: + name: Build and push Docker + permissions: + packages: write + runs-on: ubuntu-latest + + needs: test + + concurrency: + group: cicd-build-${{ github.ref }} + cancel-in-progress: true + + steps: + - uses: actions/checkout@v4 + + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ github.token }} + + - uses: VirtusLab/scala-cli-setup@v1 + with: + jvm: 21 + - run: mkdir ./target + - run: scala-cli --power package --standalone . -o ./target/dawn-patrol + + - uses: docker/metadata-action@v5 + id: meta + with: + images: ${{ env.REGISTRY }}/dawn-patrol + tags: | + type=sha,prefix=pr-${{ github.event.pull_request.number }}-,priority=601,enable=${{ github.event_name == 'pull_request' }} + type=sha,prefix={{branch}}-,priority=601,enable=${{ github.event_name == 'push' && github.ref_type == 'branch' }} + type=ref,event=branch,priority=600 + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + + - uses: docker/build-push-action@v5 + with: + context: . + file: Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: | + type=gha,scope=build + type=registry,ref=${{ env.REGISTRY }}/dawn-patrol:latest + cache-to: type=gha,mode=max,scope=build diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7f1ac9b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM eclipse-temurin:21 + +WORKDIR /app +COPY ./target/dawn-patrol ./dawn-patrol + +ENTRYPOINT [ "/app/dawn-patrol" ] diff --git a/README.md b/README.md index 1eb336c..0484376 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,9 @@ Once running, the application will poll the Signal API, obtaining messages for t The messaging logic is defined in [DawnPatrol](src/xyz/didx/DawnPatrol.scala) and [ConversationPollingHandler](src/xyz/didx/ConversationPollingHandler.scala) -To create a docker container for DawnPatrol use: +### Docker +The easiest way to build a docker container for DawnPatrol is to use the `scala-cli`: ```bash -scala-cli --power package --native --docker . --docker-from ghcr.io/graalvm/jdk-community:21 --docker-image-repository dawn-patrol +scala-cli --power package --docker . --docker-from eclipse-temurin:21 --docker-image-repository dawn-patrol ```