gitea_pages/backend/Dockerfile
2023-05-21 18:58:10 +02:00

81 lines
3.1 KiB
Docker

# FROM docker.io/lukemathwalker/cargo-chef:latest-rust-1.69.0 as mold
# SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# WORKDIR /tmp
# ARG MOLD_VERSION="1.11.0"
# RUN wget -qO- https://github.com/rui314/mold/archive/refs/tags/v${MOLD_VERSION}.tar.gz | tar zxf -
# WORKDIR /tmp/mold-${MOLD_VERSION}/build
# RUN ../install-build-deps.sh \
# && cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=c++ .. \
# && cmake --build . -j "$(nproc)" \
# && cmake --install .
FROM docker.io/lukemathwalker/cargo-chef:latest-rust-1.69.0 as chef
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# hadolint ignore=DL3009
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
lsb-release=11.1.0 \
wget=1.21-1+deb11u1 \
software-properties-common=0.96.20.2-2.1 \
gnupg=2.2.27-2+deb11u2 \
clang=1:11.0-51+nmu5
WORKDIR /tmp
ARG MOLD_VERSION="1.11.0"
RUN wget -qO- https://github.com/rui314/mold/releases/download/v${MOLD_VERSION}/mold-${MOLD_VERSION}-x86_64-linux.tar.gz | tar xzf - \
&& cp -RT ./mold-${MOLD_VERSION}-x86_64-linux /usr \
&& rm -rf ./mold-${MOLD_VERSION}-x86_64-linux
WORKDIR /
FROM chef as diesel
RUN cargo install diesel_cli --version 2.0.1 --no-default-features --features postgres
FROM chef as planner
WORKDIR /usr/src/gitea_pages
RUN mkdir -p ./src/bin && touch ./src/main.rs
COPY ./Cargo.toml ./Cargo.lock ./
RUN cargo chef prepare --recipe-path recipe.json
FROM chef as builder
WORKDIR /usr/src/gitea_pages
COPY ./.cargo ./.cargo
COPY --from=planner /usr/src/gitea_pages/recipe.json .
RUN cargo chef cook --release --recipe-path recipe.json
COPY --from=planner /usr/src/gitea_pages/Cargo.toml /usr/src/gitea_pages/Cargo.lock ./
# RUN cargo build --release --frozen --offline
COPY ./assets ./assets
COPY ./templates ./templates
COPY ./src ./src
RUN cargo build --release --frozen --offline
FROM docker.io/debian:bullseye-slim as runner
LABEL maintainer="Dominic Grimm <dominic@dergrimm.net>" \
org.opencontainers.image.description="Gitea Pages" \
org.opencontainers.image.licenses="GPLv3" \
org.opencontainers.image.source="https://git.dergrimm.net/dergrimm/gitea_pages" \
org.opencontainers.image.url="https://git.dergrimm.net/dergrimm/gitea_pages"
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN apt-get update && \
apt-get install --no-install-recommends -y \
libpq5=13.10-0+deb11u1 \
git=1:2.30.2-1+deb11u2 \
netcat=1.10-46 \
ca-certificates=20210119 \
wget=1.21-1+deb11u1 && \
wget -qO- https://get.docker.com/ | sh && \
apt-get clean && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /var/lib/apt/ && \
rm -rf /var/lib/dpkg/ && \
rm -rf /var/lib/cache/ && \
rm -rf /var/lib/log/
WORKDIR /usr/local/bin
COPY --from=diesel /usr/local/cargo/bin/diesel .
WORKDIR /opt/gitea_pages
RUN wget -q --show-progress https://raw.githubusercontent.com/vishnubob/wait-for-it/81b1373f17855a4dc21156cfe1694c31d7d1792e/wait-for-it.sh && \
chmod +x wait-for-it.sh
COPY ./run.sh ./migrate.sh ./
RUN chmod +x ./run.sh ./migrate.sh
COPY ./migrations ./migrations
COPY --from=builder /usr/src/gitea_pages/target/release/gitea_pages ./bin/gitea_pages
EXPOSE 8080 8081