Skip to content

Commit

Permalink
actions
Browse files Browse the repository at this point in the history
  • Loading branch information
skull8888888 committed Dec 26, 2024
1 parent 17ae120 commit 1416afe
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 19 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/backend-build.yml
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
55 changes: 36 additions & 19 deletions app-server/Dockerfile
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"]

0 comments on commit 1416afe

Please sign in to comment.