Skip to content

Commit

Permalink
Make Dockerfile more generic (#46)
Browse files Browse the repository at this point in the history
This adds support for building a docker for the API with the same
Dockerfile later down the line
  • Loading branch information
kekonn authored Nov 21, 2024
1 parent 4e8ed98 commit c90e789
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
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

0 comments on commit c90e789

Please sign in to comment.