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 1/9] 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: From 684ab14cf8ab6d264a2d1f227b7a36a82eb6db70 Mon Sep 17 00:00:00 2001 From: alexkar598 <25136265+alexkar598@users.noreply.github.com> Date: Sun, 10 Nov 2024 17:51:00 -0500 Subject: [PATCH 2/9] Renames job --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 87d32e50..f3558f14 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,5 +1,5 @@ # -name: Create and publish a Docker image +name: Build and publish Docker image # Configures this workflow to run every time a change is pushed to the branch called `release`. on: From 610bbfdc1df8e214ada80284f1ec6c828ea5fb30 Mon Sep 17 00:00:00 2001 From: alexkar598 <25136265+alexkar598@users.noreply.github.com> Date: Sun, 10 Nov 2024 17:52:37 -0500 Subject: [PATCH 3/9] Adds information in config folder --- config/README.md | 5 +++++ config/config/.gitkeep | 0 2 files changed, 5 insertions(+) create mode 100644 config/README.md create mode 100644 config/config/.gitkeep diff --git a/config/README.md b/config/README.md new file mode 100644 index 00000000..332bb29a --- /dev/null +++ b/config/README.md @@ -0,0 +1,5 @@ +Put mapdiffbot2.toml and icondiffbot2.toml here for docker setups. + +The contents of config will be put in /app/config + +Examples can be found in crates/mapdiffbot2/config.example.toml and crates/icondiffbot2/config.example.toml respectively. diff --git a/config/config/.gitkeep b/config/config/.gitkeep new file mode 100644 index 00000000..e69de29b From 0d26f3a1be57b541ef93ad856be5753886de850e Mon Sep 17 00:00:00 2001 From: alexkar598 <25136265+alexkar598@users.noreply.github.com> Date: Sun, 10 Nov 2024 18:04:33 -0500 Subject: [PATCH 4/9] Fixes build action --- .github/workflows/docker.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index f3558f14..66dbdb25 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -9,6 +9,7 @@ on: # 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 + NAMESPACE: ${{ github.repository_owner }} # There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. jobs: @@ -40,7 +41,7 @@ jobs: id: meta uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 with: - images: ${{ env.REGISTRY }}/${{ matrix.image }} + images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ matrix.image }} - name: Build and push Docker image id: push @@ -48,12 +49,13 @@ jobs: with: context: . push: true + target: ${{ matrix.image }} 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-name: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ matrix.image }} subject-digest: ${{ steps.push.outputs.digest }} push-to-registry: true From 00a3a64d98dc29628661f31383446133d22bb08e Mon Sep 17 00:00:00 2001 From: alexkar598 <25136265+alexkar598@users.noreply.github.com> Date: Sun, 10 Nov 2024 18:07:26 -0500 Subject: [PATCH 5/9] Enable caching on docker --- .github/workflows/docker.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 66dbdb25..a0e47f70 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -52,6 +52,8 @@ jobs: target: ${{ matrix.image }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max - name: Generate artifact attestation uses: actions/attest-build-provenance@v1 From 7ef17b44407fda08ca6f6d7d3d82f6c818d4c023 Mon Sep 17 00:00:00 2001 From: alexkar598 <25136265+alexkar598@users.noreply.github.com> Date: Sun, 10 Nov 2024 18:09:50 -0500 Subject: [PATCH 6/9] Enables buildx --- .github/workflows/docker.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index a0e47f70..01c7d024 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -30,6 +30,9 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Log in to the Container registry uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 with: From 032fb34f3d7d95c3a7db2b526ade66ff59e42f93 Mon Sep 17 00:00:00 2001 From: alexkar598 <25136265+alexkar598@users.noreply.github.com> Date: Sun, 10 Nov 2024 18:14:04 -0500 Subject: [PATCH 7/9] Better caching --- .github/workflows/docker.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 01c7d024..40b0b65b 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -15,6 +15,8 @@ env: jobs: build-and-push-image: strategy: + # Single job at a time to make use of the github cache to only build the rust project once and then build images + max-parallel: 1 matrix: image: [ "mapdiffbot2", "icondiffbot2" ] From ab3868330fd36d8986bc7487d4618022cd945402 Mon Sep 17 00:00:00 2001 From: alexkar598 <25136265+alexkar598@users.noreply.github.com> Date: Sun, 10 Nov 2024 18:56:25 -0500 Subject: [PATCH 8/9] Revert "Better caching" This reverts commit 032fb34f3d7d95c3a7db2b526ade66ff59e42f93. --- .github/workflows/docker.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 40b0b65b..01c7d024 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -15,8 +15,6 @@ env: jobs: build-and-push-image: strategy: - # Single job at a time to make use of the github cache to only build the rust project once and then build images - max-parallel: 1 matrix: image: [ "mapdiffbot2", "icondiffbot2" ] From c81e87d33afd7e990046782104e9e42bdffce864 Mon Sep 17 00:00:00 2001 From: alexkar598 <25136265+alexkar598@users.noreply.github.com> Date: Sun, 10 Nov 2024 18:57:17 -0500 Subject: [PATCH 9/9] Reenables LTO --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index d0efdcce..a6d8925b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,5 +8,5 @@ members = [ ] [profile.release] -#lto = true +lto = true debug = true