Skip to content

Commit

Permalink
fix(backend): fix frontend Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason0729 committed Aug 2, 2024
1 parent 9ab9969 commit 7efdf35
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
# Added by cargo

/target
/site

**/Dockerfile
42 changes: 42 additions & 0 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: staging-frontend-publish

on:
push:
branches:
- "staging"
paths:
- "frontend/**"
- .github/workflows/frontend.yml

env:
REGISTRY: ghcr.io

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3
- name: Checkout submodule
run: git submodule update --init --recursive
- name: Install Just
uses: taiki-e/install-action@just
- name: Install docker
uses: docker-practice/actions-setup-docker@master
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: build frontend
uses: docker/build-push-action@v5
with:
build-args: ARCH=x86_64
context: .
file: "./frontend/Dockerfile"
push: true
tags: "ghcr.io/mdcpp/mdoj/frontend:staging"
labels: "frontend"
cache-from: type=gha
cache-to: type=gha,mode=max
6 changes: 0 additions & 6 deletions .github/workflows/judger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ jobs:
uses: actions/checkout@v3
- name: Checkout submodule
run: git submodule update --init --recursive
- name: Install Rust
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly
targets: wasm32-unknown-unknown, x86_64-unknown-linux-gnu
components: clippy, rustfmt
- name: Set up nsjail cache
uses: actions/cache@v3
continue-on-error: false
Expand Down
13 changes: 5 additions & 8 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
FROM rust:1.75.0-slim-buster AS builder
FROM rust:1.75.0-slim-bullseye AS builder

WORKDIR /complier

RUN apt update -y
RUN apt install musl-tools protobuf-compiler pkg-config make -y
RUN apt update -y \
&& apt install musl-tools protobuf-compiler pkg-config make -y

RUN cargo install just

Expand All @@ -12,15 +10,14 @@ RUN --mount=type=cache,target=~/.cargo/registry/index/
RUN --mount=type=cache,target=~/.cargo/registry/cache/
RUN --mount=type=cache,target=~/.cargo/git/db/

WORKDIR /complier

WORKDIR /compiler
COPY . .
RUN --mount=type=cache,target=target

RUN sed -i '/mold/d' backend/Cargo.toml
RUN sed -i '/codegen-backend/d' backend/Cargo.toml

ARG ARCH
ARG ARCH=x86_64

RUN rustup target add ${ARCH}-unknown-linux-musl
RUN cargo install --no-default-features --target ${ARCH}-unknown-linux-musl --path backend
Expand Down
15 changes: 6 additions & 9 deletions backend/migration/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
FROM rust:1.75.0-slim-buster AS builder
FROM rust:1.75.0-slim-bullseye AS builder

ARG ARCH
WORKDIR /complier

RUN apt update -y
RUN apt install musl-tools protobuf-compiler pkg-config make -y
RUN apt update -y \
&& apt install musl-tools protobuf-compiler pkg-config make -y

RUN cargo install just


RUN --mount=type=cache,target=~/.cargo/bin/
RUN --mount=type=cache,target=~/.cargo/registry/index/
RUN --mount=type=cache,target=~/.cargo/registry/cache/
RUN --mount=type=cache,target=~/.cargo/git/db/

WORKDIR /complier

WORKDIR /compiler
COPY . .
RUN --mount=type=cache,target=target

ARG ARCH=x86_64

RUN rustup target add ${ARCH}-unknown-linux-musl
RUN cargo install --target ${ARCH}-unknown-linux-musl --path backend/migration

Expand Down
43 changes: 39 additions & 4 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
From nginx:1.25.3-alpine-slim
FROM rustlang/rust:nightly-bullseye AS builder

WORKDIR /grpc_cert
RUN apt update -y \
&& apt install musl-tools protobuf-compiler pkg-config make -y

RUN cargo install just cargo-leptos

RUN rustup target add wasm32-unknown-unknown

RUN --mount=type=cache,target=~/.cargo/bin/
RUN --mount=type=cache,target=~/.cargo/registry/index/
RUN --mount=type=cache,target=~/.cargo/registry/cache/
RUN --mount=type=cache,target=~/.cargo/git/db/

WORKDIR /compiler
COPY . .
RUN --mount=type=cache,target=target

ARG ARCH=x86_64

RUN rustup target add ${ARCH}-unknown-linux-musl

ENV LEPTOS_OUTPUT_NAME="mdoj"
ENV LEPTOS_BIN_TARGET_TRIPLE=${ARCH}-unknown-linux-musl

RUN cargo leptos build -p frontend --release -vv

FROM scratch
WORKDIR /config
WORKDIR /
COPY index.conf /etc/nginx/conf.d/default.conf
COPY dist/* /var/www/html/

ARG ARCH=x86_64

COPY --from=builder /compiler/target/${ARCH}-unknown-linux-musl/release/frontend .
COPY --from=builder /compiler/target/site /site

ENV LEPTOS_SITE_ADDR="0.0.0.0:8080"
ENV LEPTOS_SITE_ROOT=site

EXPOSE 8080

CMD ["/frontend"]
14 changes: 6 additions & 8 deletions judger/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
FROM rust:1.75.0-slim-buster AS builder
FROM rust:1.75.0-slim-bullseye AS builder

ARG ARCH
WORKDIR /complier

RUN apt update -y
RUN apt install musl-tools protobuf-compiler pkg-config make -y
RUN apt update -y \
&& apt install musl-tools protobuf-compiler pkg-config make -y

RUN cargo install just

Expand All @@ -13,11 +10,12 @@ RUN --mount=type=cache,target=~/.cargo/registry/index/
RUN --mount=type=cache,target=~/.cargo/registry/cache/
RUN --mount=type=cache,target=~/.cargo/git/db/

WORKDIR /complier

WORKDIR /compiler
COPY . .
RUN --mount=type=cache,target=target

ARG ARCH=x86_64

RUN rustup target add ${ARCH}-unknown-linux-musl
RUN cargo install --target ${ARCH}-unknown-linux-musl --path judger

Expand Down

0 comments on commit 7efdf35

Please sign in to comment.