mirror of
https://github.com/Telecominfraproject/openlan-cgw.git
synced 2026-01-27 18:22:11 +00:00
73 lines
2.5 KiB
Docker
73 lines
2.5 KiB
Docker
# Stage 1: Create a rust build image
|
|
FROM rust:1.77.0 AS builder
|
|
LABEL Description="OpenLan CGW Proxy (Build) environment"
|
|
|
|
# Setup a specific compilation target to the Rust toolchain.
|
|
RUN rustup target add x86_64-unknown-linux-gnu
|
|
|
|
# Install build packages
|
|
RUN apt-get update -q -y && \
|
|
apt-get install -q -y \
|
|
pkg-config \
|
|
build-essential \
|
|
cmake \
|
|
protobuf-compiler \
|
|
libssl-dev
|
|
|
|
# Create directory - ignore errors if exist
|
|
RUN mkdir -p /usr/src/openlan-cgw
|
|
|
|
# Set the working directory
|
|
WORKDIR /usr/src/openlan-cgw
|
|
|
|
# Mount the Cargo.toml and Cargo.lock files
|
|
# Mount the build.rs and src directory
|
|
# Mount cargo registry and git db cache and target cache
|
|
# Build proxy-cgw application
|
|
# Copy binary to default location before cache unmounted
|
|
RUN --mount=type=bind,source=src,target=src \
|
|
--mount=type=bind,source=build.rs,target=build.rs \
|
|
--mount=type=bind,source=Cargo.toml,target=Cargo.toml \
|
|
--mount=type=bind,source=Cargo.lock,target=Cargo.lock \
|
|
--mount=type=cache,target=/usr/src/openlan-cgw/target \
|
|
--mount=type=cache,target=/usr/local/cargo/git/db \
|
|
--mount=type=cache,target=/usr/local/cargo/registry \
|
|
cargo build --bin proxy-cgw --target x86_64-unknown-linux-gnu --release && \
|
|
cp target/x86_64-unknown-linux-gnu/release/proxy-cgw /usr/local/bin
|
|
|
|
CMD ["echo", "proxy-cgw build finished successfully!"]
|
|
|
|
# Stage 2: Create a runtime image
|
|
FROM rust:1.77.0
|
|
|
|
ARG GITHUB_SHA="<unknown>"
|
|
ARG GITHUB_BRANCH="<unknown>"
|
|
ARG GITHUB_TIME="0"
|
|
ENV PROXY_CONTAINER_BUILD_REV=$GITHUB_SHA
|
|
ENV PROXY_CONTAINER_BUILD_BRANCH=$GITHUB_BRANCH
|
|
ENV PROXY_CONTAINER_BUILD_TIME=$GITHUB_TIME
|
|
|
|
LABEL Description="OpenLan CGW Proxy environment"
|
|
|
|
# Create a non-root user and group
|
|
RUN adduser cgw_runner && addgroup cgw_users_group
|
|
|
|
# Add `cgw_runner` user to `cgw_users_group`
|
|
RUN usermod -a -G cgw_users_group cgw_runner
|
|
|
|
# CGW create log file under /var directory
|
|
# It is required to change directory owner
|
|
RUN chown cgw_runner:cgw_users_group "/var"
|
|
|
|
# Switch to non-root user
|
|
USER root
|
|
|
|
# Create volume to certificates directory
|
|
VOLUME [ "/etc/cgw/certs" ]
|
|
|
|
# Copy libs and CGW binaries
|
|
COPY --from=builder /lib/x86_64-linux-gnu/ /lib/x86_64-linux-gnu/
|
|
COPY --from=builder /usr/local/bin/proxy-cgw /usr/local/bin/proxy-cgw
|
|
|
|
CMD ["proxy-cgw"]
|