From ad0968262204e7afa0958299b093a8f5046a5f86 Mon Sep 17 00:00:00 2001 From: Szepesi Tibor Date: Sun, 7 Jul 2024 21:20:44 +0200 Subject: [PATCH] Update containerfiles (#73) --- Containerfile | 36 +++++++++++++++++++ Dockerfile | 49 -------------------------- docker-compose.yml => compose.yaml | 5 ++- containerfiles/migration.Containerfile | 36 +++++++++++++++++++ dockerfiles/migration.Dockerfile | 47 ------------------------ 5 files changed, 74 insertions(+), 99 deletions(-) create mode 100644 Containerfile delete mode 100644 Dockerfile rename docker-compose.yml => compose.yaml (72%) create mode 100644 containerfiles/migration.Containerfile delete mode 100644 dockerfiles/migration.Dockerfile diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..96b43d2 --- /dev/null +++ b/Containerfile @@ -0,0 +1,36 @@ +FROM registry.access.redhat.com/ubi9/ubi as chef + +RUN curl --proto '=https' --tlsv1.3 -sSf https://sh.rustup.rs > rustup-init.sh && \ + sh rustup-init.sh --default-toolchain "1.79" --profile minimal -y && \ + source "$HOME/.bashrc" && \ + dnf install clang -y + +ENV PATH="$PATH:/root/.cargo/bin" + +RUN cargo install cargo-chef --locked --version "0.1.67" && \ + rm -rf $CARGO_HOME/registry/ + + + +FROM chef AS planner +WORKDIR /planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + + + +FROM chef AS builder +WORKDIR /builder +COPY --from=planner /planner/recipe.json recipe.json +# Build dependencies +RUN cargo chef cook --release --recipe-path recipe.json +# Build application +COPY . . +RUN cargo build --bin iam --release + + + +FROM registry.access.redhat.com/ubi9/ubi-micro +WORKDIR /app +COPY --from=builder /builder/target/release/iam ./ +CMD ["./iam"] diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index b5f27a4..0000000 --- a/Dockerfile +++ /dev/null @@ -1,49 +0,0 @@ -FROM rust:slim-bookworm as builder - -WORKDIR /builder -RUN cargo new --bin app && \ - cargo new --bin app/iam && \ - cargo new --lib app/iam-entity && \ - cargo new --lib app/iam-migration && \ - cargo new --lib app/iam-common && \ - cargo new --lib app/iam-macros && \ - cargo new --lib app/libiam && \ - cargo new --bin app/cmds - -WORKDIR /builder/app - -COPY ["Cargo.toml", "Cargo.lock", "./"] -COPY ./iam/Cargo.toml ./iam/Cargo.toml -COPY ./iam-entity/Cargo.toml ./iam-entity/Cargo.toml -COPY ./iam-common/Cargo.toml ./iam-common/Cargo.toml -COPY ./iam-macros/Cargo.toml ./iam-macros/Cargo.toml - -RUN rm ./iam-macros/src/lib.rs && \ - touch ./iam-macros/src/lib.rs && \ - cargo build --release && \ - rm -rf ./iam/src/ \ - ./iam-entity/src/ \ - ./iam-common/src/ \ - ./iam-macros/src/ - -COPY ./iam/src/ ./iam/src/ -COPY ./iam-entity/src/ ./iam-entity/src/ -COPY ./iam-common/src/ ./iam-common/src/ -COPY ./iam-macros/src/ ./iam-macros/src/ - -RUN rm target/release/deps/iam* \ - target/release/deps/libiam* && \ - cargo build --release - -FROM debian:12-slim -WORKDIR /app -COPY --from=builder /builder/app/target/release/iam ./ -EXPOSE 3001 - -RUN addgroup --system app && \ - adduser --system --disabled-password --no-create-home --shell /bin/false --ingroup app app && \ - chown -R app:app /app -USER app - -CMD ["./iam"] - diff --git a/docker-compose.yml b/compose.yaml similarity index 72% rename from docker-compose.yml rename to compose.yaml index e4c93f1..5b2b137 100644 --- a/docker-compose.yml +++ b/compose.yaml @@ -1,12 +1,11 @@ -version: '3' - services: database: - image: mysql:8.0 + image: docker.io/mysql:8.0 environment: MYSQL_DATABASE: iam MYSQL_USER: iam MYSQL_PASSWORD: secret + MYSQL_ROOT_PASSWORD: secret TZ: Europe/Budapest ports: - "3306:3306" diff --git a/containerfiles/migration.Containerfile b/containerfiles/migration.Containerfile new file mode 100644 index 0000000..04aac8e --- /dev/null +++ b/containerfiles/migration.Containerfile @@ -0,0 +1,36 @@ +FROM registry.access.redhat.com/ubi9/ubi as chef + +RUN curl --proto '=https' --tlsv1.3 -sSf https://sh.rustup.rs > rustup-init.sh && \ + sh rustup-init.sh --default-toolchain "1.79" --profile minimal -y && \ + source "$HOME/.bashrc" && \ + dnf install clang -y + +ENV PATH="$PATH:/root/.cargo/bin" + +RUN cargo install cargo-chef --locked --version "0.1.67" && \ + rm -rf $CARGO_HOME/registry/ + + + +FROM chef AS planner +WORKDIR /planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + + + +FROM chef AS builder +WORKDIR /builder +COPY --from=planner /planner/recipe.json recipe.json +# Build dependencies +RUN cargo chef cook --release --recipe-path recipe.json +# Build application +COPY . . +RUN cargo build --bin iam-migration --release + + + +FROM registry.access.redhat.com/ubi9/ubi-micro +WORKDIR /app +COPY --from=builder /builder/target/release/iam-migration ./ +CMD ["./iam-migration"] diff --git a/dockerfiles/migration.Dockerfile b/dockerfiles/migration.Dockerfile deleted file mode 100644 index e28e958..0000000 --- a/dockerfiles/migration.Dockerfile +++ /dev/null @@ -1,47 +0,0 @@ -FROM rust:slim-bookworm as builder - -WORKDIR /builder -RUN cargo new --bin app && \ - cargo new --bin app/iam && \ - cargo new --lib app/iam-entity && \ - cargo new --lib app/iam-migration && \ - cargo new --lib app/iam-common && \ - cargo new --lib app/iam-macros && \ - cargo new --lib app/libiam && \ - cargo new --bin app/cmds - -WORKDIR /builder/app - -COPY ["Cargo.toml", "Cargo.lock", "./"] -COPY ./iam-migration/Cargo.toml ./iam-migration/Cargo.toml -COPY ./iam-entity/Cargo.toml ./iam-entity/Cargo.toml -COPY ./iam-common/Cargo.toml ./iam-common/Cargo.toml -COPY ./iam-macros/Cargo.toml ./iam-macros/Cargo.toml - -RUN rm ./iam-macros/src/lib.rs && \ - touch ./iam-macros/src/lib.rs && \ - cargo build -p iam-migration --release && \ - rm -rf ./iam-migration/src \ - ./iam-entity/src/ \ - ./iam-common/src/ - -COPY ./iam-migration/src/ ./iam-migration/src/ -COPY ./iam-entity/src/ ./iam-entity/src/ -COPY ./iam-common/src/ ./iam-common/src/ -COPY ./iam-macros/src/ ./iam-macros/src/ - -RUN rm target/release/deps/iam* \ - target/release/deps/libiam* && \ - cargo build -p iam-migration --release - -FROM debian:12-slim -WORKDIR /app -COPY --from=builder /builder/app/target/release/iam-migration ./ - -RUN addgroup --system app && \ - adduser --system --disabled-password --no-create-home --shell /bin/false --ingroup app app && \ - chown -R app:app /app -USER app - -CMD ["./iam-migration"] -