Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker build #36

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ end_of_line = lf

[*.txt]
insert_final_newline = false

[*.yml]
indent_size = 2
68 changes: 68 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#
name: Build and publish 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
NAMESPACE: ${{ github.repository_owner }}
Comment on lines +10 to +12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I need to do anything fancy with perms to make it upload?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it uses the token from github actions to upload to the github registry. If you want to build locally however, you do need to login to the github docker registry


# 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:
# 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" ]

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: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- 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 }}/${{ env.NAMESPACE }}/${{ matrix.image }}

- name: Build and push Docker image
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
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
with:
subject-name: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ matrix.image }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ jobs/

diffbot.pem
config.toml

/config/
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ members = [
]

[profile.release]
lto = true
#lto = true
debug = true
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions config/README.md
Original file line number Diff line number Diff line change
@@ -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.
Empty file added config/config/.gitkeep
Empty file.
36 changes: 36 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
AffectedArc07 marked this conversation as resolved.
Show resolved Hide resolved
Loading