diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b24db08 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +# Ignore everything +** + +# Except the following +!src/ +!target/ +!test/ +!project.scala diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..39e65ff --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + # Maintain dependencies for GitHub Actions + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..86f6dbf --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,92 @@ +name: CICD + +on: + workflow_dispatch: + push: + branches: + - "master" + tags: + - "v*" + pull_request: + branches: + - "master" + +concurrency: + group: cicd-${{ github.ref }} + cancel-in-progress: true + +env: + REGISTRY: ghcr.io/${{ github.repository_owner }} + +jobs: + test: + name: Test + runs-on: ubuntu-latest + + concurrency: + group: cicd-test-${{ github.ref }} + cancel-in-progress: true + + steps: + - uses: actions/checkout@v4 + - uses: coursier/cache-action@v6 + - uses: VirtusLab/scala-cli-setup@v1 + with: + 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: coursier/cache-action@v6 + - uses: VirtusLab/scala-cli-setup@v1 + with: + jvm: 21 + - run: mkdir ./target + - run: scala-cli --power package --standalone . --output ./target/dawn-patrol + + - uses: docker/metadata-action@v5 + id: meta + with: + images: ${{ env.REGISTRY }}/dawn-patrol + tags: | + type=raw,value=latest,enable={{is_default_branch}} + 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: + platforms: linux/amd64,linux/arm64 + 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/.gitignore b/.gitignore index 848f117..8e5a814 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,6 @@ build/ .bsp/ .metals/ .lh/ -.vscode/ .cache/ .cache-main .classpath @@ -30,3 +29,27 @@ metals.sbt project/project .config DID_Me + +# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode +# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode diff --git a/.rtx.toml b/.rtx.toml new file mode 100644 index 0000000..6dadddf --- /dev/null +++ b/.rtx.toml @@ -0,0 +1,3 @@ +[tools] +java = "21" +scala-cli = "1.0.5" diff --git a/.scalafmt.conf b/.scalafmt.conf index 1e442aa..9b3343b 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -14,6 +14,7 @@ newlines.source = keep newlines.beforeMultiline = keep newlines.afterCurlyLambdaParams = keep newlines.alwaysBeforeElseAfterCurlyIf = true +encoding = "UTF-8" runner.dialect = scala3 @@ -41,4 +42,4 @@ project.excludeFilters = [ "examples" # Scala 3 scripts and using directives not supported yet "out" "scala-version.scala" -] \ No newline at end of file +] diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..2384750 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "scala-lang.scala" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..70dfafb --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "files.insertFinalNewline": true, + "files.trimFinalNewlines": true, + "files.eol": "\n", + "files.trimTrailingWhitespace": true, + "files.encoding": "utf8" +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..258d04c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM eclipse-temurin:21 + +RUN adduser --system --group --uid 1000 --shell /bin/bash dawn + +WORKDIR /app +COPY --chown=0:0 ./target/dawn-patrol ./dawn-patrol + +USER dawn + +ENV HF_API_KEY= +ENV OPENAI_TOKEN= + +ENTRYPOINT [ "/app/dawn-patrol" ] diff --git a/README.md b/README.md index 1eb336c..60bcff7 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,21 @@ 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 +``` + +To run our Docker image: +```bash +docker run -it --rm \ + -e HF_API_KEY='hf_key' \ + -e OPENAI_TOKEN='oai_key' \ + ghcr.io/didx-xyz/dawn-patrol ``` diff --git a/src/resources/application.conf b/src/resources/application.conf index 2e0e2de..8f71c9f 100644 --- a/src/resources/application.conf +++ b/src/resources/application.conf @@ -59,8 +59,8 @@ openai-conf { } passkit-conf { - keystore-path ="/Users/ian/dev/gleibnif/modules/client/src/main/resources/credentials/didx1.p12" - keystore-password ="amad3usM02art" + keystore-path = "/Users/ian/dev/gleibnif/modules/client/src/main/resources/credentials/didx1.p12" + keystore-password = "amad3usM02art" apple-wwdrca = "/Users/ian/dev/gleibnif/modules/client/src/main/resources/credentials/pass-8.cer" template-path = "/Users/ian/dev/gleibnif/modules/client/src/main/resources/template" #grpc.host=grpc.pub1.passkit.io @@ -71,4 +71,4 @@ passkit-conf { #credentials.password="amad3usM02art" # Number of seconds to allow for checking of the generated assets before they are deleted. Set to -1 to not delete assets. #delete.assets.timeout.seconds=60 -} \ No newline at end of file +}