From 8bc2e324d2d265bec48d4682b3ca2d47f3ee632b Mon Sep 17 00:00:00 2001 From: lza_menace Date: Fri, 3 Jul 2020 21:00:30 -0700 Subject: [PATCH] streamlining container image builds with hacky dummy file --- Cargo.toml | 3 +++ Dockerfile | 30 ++++++++++++++++++++---------- dummy.rs | 1 + 3 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 dummy.rs diff --git a/Cargo.toml b/Cargo.toml index 0daef79..e8280ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,9 @@ name = "wownero-explorer" version = "0.1.0" authors = ["lza_menace "] edition = "2018" +[[bin]] +name = "wownero-explorer" +path = "src/main.rs" [dependencies] rocket = "0.4.4" diff --git a/Dockerfile b/Dockerfile index bd96072..197441f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,32 @@ FROM ubuntu:19.10 as builder +# Install required packages RUN apt-get update && apt-get install -y build-essential - RUN apt-get install -y curl git +# Setup app user and workspace RUN useradd -m -d /home/wownero-explorer wownero-explorer - -RUN mkdir -p /srv && chown -R wownero-explorer:wownero-explorer /srv - +RUN mkdir -p /srv/wownero-explorer && chown -R wownero-explorer:wownero-explorer /srv USER wownero-explorer -WORKDIR /srv +WORKDIR /srv/wownero-explorer +# Install Rust RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | RUSTUP_HOME=/home/wownero-explorer/.rustup sh -s -- -y -RUN git clone https://git.wownero.com/lza_menace/wownero-explorer && \ - cd wownero-explorer && \ - ~/.cargo/bin/rustup override set nightly && \ - ~/.cargo/bin/cargo build --release -FROM ubuntu:19.10 +# Setup dummy build and perform release +COPY dummy.rs . +COPY Cargo.toml . +COPY Cargo.lock . +RUN sed -i 's_src/main.rs_dummy.rs_' Cargo.toml +RUN ~/.cargo/bin/rustup override set nightly +RUN ~/.cargo/bin/cargo build --release + +# Put real source onto image and perform release +RUN sed -i 's_dummy.rs_src/main.rs_' Cargo.toml +COPY src src +RUN ~/.cargo/bin/cargo build --release +FROM ubuntu:19.10 COPY --from=builder /srv/wownero-explorer/target/release/wownero-explorer /bin/wownero-explorer +COPY static static +COPY templates templates diff --git a/dummy.rs b/dummy.rs new file mode 100644 index 0000000..f328e4d --- /dev/null +++ b/dummy.rs @@ -0,0 +1 @@ +fn main() {}