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

Make Dockerfile more generic #46

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 8 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
*.db
*.db-shm
*.db-wal
*.http
/*.json
dist-workspace.toml
justfile
release.toml

.github
.devcontainer
.testdata
.github/
.devcontainer/
.testdata/
.run/
4 changes: 3 additions & 1 deletion .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ name: PR Checks

on:
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
types: [ready_for_review, opened, synchronize]

Expand Down Expand Up @@ -53,10 +52,13 @@ jobs:
printf "Changes to code detected: %s" $code_or_cargo_changed >> $GITHUB_STEP_SUMMARY

- uses: swatinem/rust-cache@v2
if: ${{ steps.check_relevant_changes.outputs.code_or_cargo_changed == 'true' }}
- name: Install Rust toolchain
if: ${{ steps.check_relevant_changes.outputs.code_or_cargo_changed == 'true' }}
uses: dtolnay/rust-toolchain@stable

- name: Verify if CHANGELOG is updated
if: ${{ steps.check_relevant_changes.outputs.code_or_cargo_changed == 'true' }}
run: |
# Extract a list of modified workspace packages
workspace_root=$(cargo metadata --format-version 1 --no-deps | jq -r '.workspace_root')
Expand Down
16 changes: 9 additions & 7 deletions Docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
ARG APP_NAME=fercord
ARG EXEC_NAME=fercord_bot
ARG VARIANT="bookworm"

FROM rust:1-slim-bullseye AS builder
FROM rust:1-slim-${VARIANT} AS builder
ARG APP_NAME
ARG EXEC_NAME
RUN USER=root cargo new --bin ${APP_NAME}
WORKDIR /${APP_NAME}
COPY . .
Expand All @@ -10,13 +13,13 @@ RUN apt-get update \
&& apt-get install -y ca-certificates tzdata pkg-config libssl-dev \
&& rm -rf /var/lib/apt/lists/*

RUN cargo build --bin fercord_bot --release --locked
RUN rm -rf fercord_storage/**.rs fercord_bot/**.rs
RUN cargo build --bin ${EXEC_NAME} --release --locked
RUN rm -rf fercord_storage/**.rs ${EXEC_NAME}/**.rs fercord_common/**.rs
ADD . ./
RUN rm ./target/release/deps/${APP_NAME}*
RUN cargo build --bin fercord_bot --release --locked
RUN cargo build --bin ${EXEC_NAME} --release --locked

FROM debian:bullseye-slim AS runner
FROM debian:${VARIANT}-slim AS runner
RUN apt-get update \
&& apt-get install -y ca-certificates tzdata \
&& rm -rf /var/lib/apt/lists/*
Expand All @@ -26,7 +29,6 @@ ARG UID=1001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
Expand All @@ -42,7 +44,7 @@ ENV TZ=Etc/UTC \
RUST_LOG="info,sqlx::query=warn"

WORKDIR /app
COPY --from=builder /${APP_NAME}/target/release/fercord_bot ./${APP_NAME}
COPY --from=builder /${APP_NAME}/target/release/${EXEC_NAME} ./${APP_NAME}

RUN chown -R $APP_USER:$APP_USER /app

Expand Down
Loading