-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17ae120
commit 1416afe
Showing
2 changed files
with
75 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Backend build | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- synchronize | ||
- opened | ||
- reopened | ||
paths: | ||
- 'app-server/**' | ||
|
||
jobs: | ||
build-push: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v4 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-app-server-pr-${{ hashFiles('Cargo.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx-app-server-pr- | ||
- name: Build and push image to AWS ECR | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
file: ./app-server/Dockerfile | ||
push: false | ||
platforms: linux/amd64 | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,47 @@ | ||
# Uses the bullseye-slim debian image per the rust recommendation. | ||
FROM rust:1.81-slim-bullseye AS builder | ||
|
||
# Install g++ and other build essentials for compiling openssl/tls dependencies | ||
RUN apt update | ||
RUN apt install -y build-essential | ||
# Build stage with cargo chef for dependency caching | ||
FROM rust:1.81-slim-bullseye AS chef | ||
WORKDIR /app-server | ||
|
||
# Install other openssl / native tls dependencies | ||
RUN apt-get update | ||
RUN apt-get install -y \ | ||
# Install build dependencies and cargo-chef | ||
RUN apt-get update && apt-get install -y \ | ||
build-essential \ | ||
pkg-config \ | ||
libssl-dev \ | ||
protobuf-compiler \ | ||
libfontconfig1-dev \ | ||
libfontconfig \ | ||
libclang-dev | ||
libfontconfig \ | ||
libclang-dev \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& cargo install cargo-chef | ||
|
||
# Clean up some unnecessary apt artifacts | ||
RUN rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /app-server | ||
# Prepare recipe for dependency caching | ||
FROM chef AS planner | ||
COPY . . | ||
RUN cargo chef prepare --recipe-path recipe.json | ||
|
||
EXPOSE 8000 | ||
ARG DATABASE_URL | ||
ENV DATABASE_URL=${DATABASE_URL} | ||
# Build dependencies - this layer is cached | ||
FROM chef AS builder | ||
COPY --from=planner /app-server/recipe.json recipe.json | ||
# Build dependencies | ||
RUN cargo chef cook --release --recipe-path recipe.json | ||
|
||
# Build application | ||
COPY . . | ||
ENV SQLX_OFFLINE=true | ||
RUN cargo build --release --all | ||
|
||
CMD ["./target/release/app-server"] | ||
# Final runtime stage | ||
FROM debian:bullseye-slim AS runtime | ||
WORKDIR /app-server | ||
|
||
# Install only runtime dependencies | ||
RUN apt-get update && apt-get install -y \ | ||
libssl1.1 \ | ||
libfontconfig1 \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
COPY --from=builder /app-server/target/release/app-server . | ||
|
||
EXPOSE 8000 | ||
|
||
CMD ["./app-server"] |