Prepare dockerized build for Railway

This commit is contained in:
2023-06-16 20:14:59 -05:00
parent e8cffce4d1
commit ea22c91cac
6 changed files with 140 additions and 9 deletions
+43
View File
@@ -0,0 +1,43 @@
# Build Stage
FROM rust:1.68.0 as builder
RUN USER=root cargo new --bin time-banner
WORKDIR ./time-banner
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
COPY ./Cargo.toml ./Cargo.toml
# Build empty app with downloaded dependencies to produce a stable image layer for next build
RUN cargo build --release
# Build web app with own code
RUN rm src/*.rs
ADD . ./
RUN rm ./target/release/deps/time-banner*
RUN cargo build --release
FROM debian:buster-slim
ARG APP=/usr/src/app
RUN apt-get update \
&& apt-get install -y ca-certificates tzdata \
&& rm -rf /var/lib/apt/lists/*
ENV TZ=Etc/UTC \
APP_USER=appuser
RUN groupadd $APP_USER \
&& useradd -g $APP_USER $APP_USER \
&& mkdir -p ${APP}
COPY --from=builder /time-banner/target/release/time-banner ${APP}/time-banner
RUN chown -R $APP_USER:$APP_USER ${APP}
USER $APP_USER
WORKDIR ${APP}
EXPOSE 3000
ENV PORT 3000
CMD ["./time-banner"]