From 950c6077722ef6d3d653151e3f87ae7abbef9a77 Mon Sep 17 00:00:00 2001 From: alexkar598 <25136265+alexkar598@users.noreply.github.com> Date: Sun, 10 Nov 2024 17:50:06 -0500 Subject: [PATCH] Dockerize --- .dockerignore | 1 + .editorconfig | 3 ++ .github/workflows/docker.yml | 59 ++++++++++++++++++++++++++++++++++++ .gitignore | 2 ++ Cargo.toml | 2 +- Dockerfile | 26 ++++++++++++++++ docker-compose.yml | 36 ++++++++++++++++++++++ 7 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..b83d2226 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +/target/ diff --git a/.editorconfig b/.editorconfig index 5db2f4a3..e09ad1ae 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,3 +8,6 @@ end_of_line = lf [*.txt] insert_final_newline = false + +[*.yml] +indent_size = 2 \ No newline at end of file diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..87d32e50 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,59 @@ +# +name: Create and publish a Docker image + +# Configures this workflow to run every time a change is pushed to the branch called `release`. +on: + push: + branches: [master] + +# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. +env: + REGISTRY: ghcr.io + +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. +jobs: + build-and-push-image: + strategy: + matrix: + image: [ "mapdiffbot2", "icondiffbot2" ] + + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + attestations: write + id-token: write + # + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ matrix.image }} + + - name: Build and push Docker image + id: push + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ env.REGISTRY }}/${{ matrix.image }} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true diff --git a/.gitignore b/.gitignore index 75e58523..9c2de779 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ jobs/ diffbot.pem config.toml + +/config/ diff --git a/Cargo.toml b/Cargo.toml index a6d8925b..d0efdcce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,5 +8,5 @@ members = [ ] [profile.release] -lto = true +#lto = true debug = true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..431502f3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM rust:1.82.0-slim-bookworm AS builder + +RUN apt-get update && apt-get install -y pkg-config libssl-dev make + +WORKDIR /app + +COPY . . +RUN --mount=type=cache,target=/app/target \ + --mount=type=cache,target=/usr/local/cargo/registry \ + cargo build --release && cp target/release/mapdiffbot2 target/release/icondiffbot2 . + +FROM debian:bookworm-20241016-slim AS base + +RUN apt-get update && apt-get install -y libssl3 +USER 1000 +WORKDIR /app + +FROM base AS mapdiffbot2 +COPY --from=builder /app/mapdiffbot2 /app/mapdiffbot2 + +ENTRYPOINT /app/mapdiffbot2 + +FROM base AS icondiffbot2 +COPY --from=builder /app/icondiffbot2 /app/icondiffbot2 + +ENTRYPOINT /app/icondiffbot2 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..2e1c02e6 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,36 @@ +services: + icondiffbot2: + image: ghcr.io/spacestation13/icondiffbot2:latest + build: + target: icondiffbot2 + init: true + volumes: + - type: bind + source: ./config/icondiffbot2.toml + target: /app/config.toml + read_only: true + - type: bind + source: ./config/config + target: /app/config + read_only: true + - icondiffbot2_images:/app/images + mapdiffbot2: + image: ghcr.io/spacestation13/mapdiffbot2:latest + build: + target: mapdiffbot2 + init: true + volumes: + - type: bind + source: ./config/mapdiffbot2.toml + target: /app/config.toml + read_only: true + - type: bind + source: ./config/config + target: /app/config + read_only: true + - mapdiffbot2_images:/app/images + - mapdiffbot2_repos:/app/repos +volumes: + icondiffbot2_images: + mapdiffbot2_images: + mapdiffbot2_repos: