Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config_path build argument to Freyja apps dockerfile #49

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Dockerfile.freyja_apps.amd64
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ ARG RUST_VERSION=1.72.1
ARG APP_NAME=freyja-in-memory-app
ARG UID=10001

# CONFIG_PATH must be relative to the project root
ARG CONFIG_PATH=""

FROM docker.io/library/rust:${RUST_VERSION}-slim-bullseye AS build
ARG APP_NAME
ARG CONFIG_PATH
WORKDIR /sdv

COPY ./ .
Expand All @@ -25,6 +29,14 @@ RUN /sdv/container/scripts/argument_sanitizer.sh \
--regex "^[a-zA-Z_0-9-]+$" || \
( echo "Argument sanitizer failed for ARG 'APP_NAME'"; exit 1 )

# Check that CONFIG_PATH argument is valid if it's non-empty.
RUN if [ -n "${CONFIG_PATH}" ]; then \
/sdv/container/scripts/argument_sanitizer.sh \
--arg-value "${CONFIG_PATH}" \
--regex "^[.\/a-zA-Z_0-9-]+$" || \
( echo "Argument sanitizer failed for ARG 'CONFIG_PATH'"; exit 1 ); \
fi

# Add Build dependencies.
RUN apt update && apt upgrade -y && apt install -y \
cmake \
Expand All @@ -38,6 +50,12 @@ RUN cargo build --release -p "${APP_NAME}"
# Copy the built application to working directory.
RUN cp ./target/release/"${APP_NAME}" /sdv/service

# Create the config override directory and if CONFIG_PATH is provided, copy files from it
RUN mkdir -p /sdv/config \
&& if [ -n "${CONFIG_PATH}" ]; then \
cp -r "${CONFIG_PATH}"/* /sdv/config; \
fi

################################################################################
# Create a new stage for running the application that contains the minimal
# runtime dependencies for the application. This often uses a different base
Expand All @@ -51,6 +69,7 @@ RUN cp ./target/release/"${APP_NAME}" /sdv/service
# (e.g., debian@sha256:ac707220fbd7b67fc19b112cee8170b41a9e97f703f588b2cdbbcdcecdd8af57).
FROM docker.io/library/debian:bullseye-slim AS final
ARG UID
ARG CONFIG_PATH

# Copy container scripts.
COPY ./container/scripts/*.sh /sdv/scripts/
Expand Down Expand Up @@ -87,6 +106,9 @@ WORKDIR /sdv
COPY --from=build /sdv/service /sdv/
COPY --from=build /sdv/target/release/build/ /sdv/target/release/build/

# Copy from config override directory into where Freyja expects it
COPY --from=build /sdv/config /sdv/.freyja/config

ENV FREYJA_HOME=/sdv/.freyja

# What the container should run when it is started.
Expand Down
21 changes: 21 additions & 0 deletions Dockerfile.freyja_apps.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ ARG RUST_VERSION=1.72.1
ARG APP_NAME=freyja-in-memory-app
ARG UID=10001

# CONFIG_PATH must be relative to the project root
ARG CONFIG_PATH=""

FROM docker.io/library/rust:${RUST_VERSION}-slim-bullseye AS build
ARG APP_NAME
ARG CONFIG_PATH
WORKDIR /sdv

COPY ./ .
Expand All @@ -25,6 +29,13 @@ RUN /sdv/container/scripts/argument_sanitizer.sh \
--regex "^[a-zA-Z_0-9-]+$" || \
( echo "Argument sanitizer failed for ARG 'APP_NAME'"; exit 1 )

# Check that CONFIG_PATH argument is valid if it is not empty.
RUN [ -z "${CONFIG_PATH}" ] || \
/sdv/container/scripts/argument_sanitizer.sh \
--arg-value "${CONFIG_PATH}" \
--regex "^[.\/a-zA-Z_0-9-]+$" || \
( echo "Argument sanitizer failed for ARG 'CONFIG_PATH'"; exit 1 )

# Add Build dependencies.
RUN apt update && apt upgrade -y && apt install -y \
cmake \
Expand All @@ -41,6 +52,12 @@ RUN cargo build --release --target=aarch64-unknown-linux-gnu -p "${APP_NAME}"
# Copy the built application to working directory.
RUN cp ./target/aarch64-unknown-linux-gnu/release/"${APP_NAME}" /sdv/service

# Create the config override directory and if CONFIG_PATH is provided, copy files from it
RUN mkdir -p /sdv/config \
&& if [ -n "${CONFIG_PATH}" ]; then \
cp -r "${CONFIG_PATH}"/* /sdv/config; \
fi

################################################################################
# Create a new stage for running the application that contains the minimal
# runtime dependencies for the application. This often uses a different base
Expand All @@ -54,6 +71,7 @@ RUN cp ./target/aarch64-unknown-linux-gnu/release/"${APP_NAME}" /sdv/service
# (e.g., debian@sha256:ac707220fbd7b67fc19b112cee8170b41a9e97f703f588b2cdbbcdcecdd8af57).
FROM docker.io/arm64v8/debian:bullseye-slim AS final
ARG UID
ARG CONFIG_PATH

# Copy container scripts.
COPY ./container/scripts/*.sh /sdv/scripts/
Expand Down Expand Up @@ -90,6 +108,9 @@ WORKDIR /sdv
COPY --from=build /sdv/service /sdv/
COPY --from=build /sdv/target/aarch64-unknown-linux-gnu/release/build/ /sdv/target/aarch64-unknown-linux-gnu/release/build/

# Copy from config override directory into where Freyja expects it
COPY --from=build /sdv/config /sdv/.freyja/config

ENV FREYJA_HOME=/sdv/.freyja

# What the container should run when it is started.
Expand Down
Loading