From 56ef153f4a0ab00d854bb3d8ee4037502dda4da1 Mon Sep 17 00:00:00 2001 From: Wi1dcard Date: Fri, 23 Jul 2021 19:30:11 +0800 Subject: [PATCH] Refactor dockerfiles. (#156) --- Dockerfile | 74 ++++++++++++++++++++++------------ Dockerfiles/alpine.Dockerfile | 29 ------------- Dockerfiles/builder.Dockerfile | 33 --------------- Dockerfiles/release.Dockerfile | 33 --------------- 4 files changed, 49 insertions(+), 120 deletions(-) delete mode 100644 Dockerfiles/alpine.Dockerfile delete mode 100644 Dockerfiles/builder.Dockerfile delete mode 100644 Dockerfiles/release.Dockerfile diff --git a/Dockerfile b/Dockerfile index c124c6b2..99401281 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,49 @@ -FROM ubuntu:latest as builder -ARG DEBIAN_FRONTEND=noninteractive - -COPY . shadow -RUN apt-get update && apt-get -y upgrade \ - && apt-get -y install golang cargo libssl-dev clang-tools \ - && cd shadow \ - && cargo build --release -vv \ - && mkdir /target \ - && cp /shadow/target/release/shadow /target \ - && cp /usr/local/lib/libdarwinia_shadow.so /target \ - && cp /lib/x86_64-linux-gnu/libssl.so.1.1 /target \ - && cp /lib/x86_64-linux-gnu/libcrypto.so.1.1 /target - -FROM ubuntu:latest -COPY --from=builder /target /target -RUN apt-get update -y \ - && apt-get install -y ca-certificates \ - && rm -rf /var/lib/apt/lists/* \ - && mv /target/shadow /usr/bin \ - && mv /target/* /usr/lib \ - && rm -rf /target \ - && ldconfig - -ENTRYPOINT ["shadow"] +FROM rust:1 as builder + +ENV CARGO_TERM_COLOR=always +ENV LIBRARY_TYPE=static + +RUN apt-get update +RUN apt-get install -y clang + +## +# Update Rust toolchains +## + +ARG RUST_TOOLCHAIN=nightly-2021-02-28 +RUN rustup update \ + && rustup install ${RUST_TOOLCHAIN} \ + && rustup default ${RUST_TOOLCHAIN} + +## +# Install Go +## + +RUN wget https://golang.org/dl/go1.15.1.linux-amd64.tar.gz +RUN tar -C /usr/local -xvzf go*.linux-amd64.tar.gz + +ENV PATH="$PATH:/usr/local/go/bin" +RUN go version + +## +# Build +## + +WORKDIR /src +COPY . . + +RUN cargo build --release + +## +# Final stage +## + +FROM debian:stable-slim + +RUN apt-get update \ + && apt-get install -y --no-install-recommends ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=builder /src/target/release/shadow /usr/local/bin/ + +ENTRYPOINT [ "/usr/local/bin/shadow" ] diff --git a/Dockerfiles/alpine.Dockerfile b/Dockerfiles/alpine.Dockerfile deleted file mode 100644 index 12c6a87d..00000000 --- a/Dockerfiles/alpine.Dockerfile +++ /dev/null @@ -1,29 +0,0 @@ -# Build Shadow in a stock rust builder container -FROM rust:1.45.2-alpine as shadow -ARG DEBIAN_FRONTEND=noninteractive -ENV TZ=America/Los_Angeles -COPY . shadow - -# Required dynamic libraries -# -# libdarwinia_shadow.so => /usr/local/lib/libdarwinia_shadow.so (0x7fd26af02000) -# libssl.so.1.1 => /lib/libssl.so.1.1 (0x7fd26ae81000) -# libcrypto.so.1.1 => /lib/libcrypto.so.1.1 (0x7fd26ac02000) -# libsqlite3.so.0 => /usr/lib/libsqlite3.so.0 (0x7fd26ab1a000) -# libc.musl-x86_64.so.1 => /lib/ld64.so.1 (0x7fd26bebb000) -RUN apk add --no-cache gcc go openssl-dev llvm\ - && cd shadow \ - && cargo build --release -vv \ - && mkdir /target \ - && cp target/release/shadow /target/ \ - && cp /usr/local/lib/libdarwinia_shadow.so /target/libdarwinia_shadow.so - -# Pull Shadow into a second stage deploy alpine container -FROM alpine:latest -COPY --from=shadow /target /target -RUN mv /target/shadow /usr/local/bin/shadow \ - && mv /target/libdarwinia_shadow.so /usr/local/lib/libdarwinia_shadow.so \ - && cp /lib/libc.musl-x86_64.so.1 /lib/ld64.so.1 \ - && rm -rf /target -EXPOSE 3000 -ENTRYPOINT ["shadow"] diff --git a/Dockerfiles/builder.Dockerfile b/Dockerfiles/builder.Dockerfile deleted file mode 100644 index 3b427141..00000000 --- a/Dockerfiles/builder.Dockerfile +++ /dev/null @@ -1,33 +0,0 @@ -FROM ubuntu:latest as builder -ARG DEBIAN_FRONTEND=noninteractive -ENV TZ=America/Los_Angeles -COPY . shadow -RUN apt-get update && apt-get -y upgrade \ - && apt-get -y install golang cargo libssl-dev clang-tools \ - && cd shadow \ - && cargo build --release -vv \ - && mkdir /target \ - && cp /shadow/target/release/shadow /target \ - && cp /usr/local/lib/libdarwinia_shadow.so /target \ - && cp /lib/x86_64-linux-gnu/libssl.so.1.1 /target \ - && cp /lib/x86_64-linux-gnu/libcrypto.so.1.1 /target - -# FROM debian:stretch-slim -# # linux-vdso.so.1 (0x00007fffdafe6000) -# # libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f5221f0d000) -# # libssl.so.1.1 => /lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007f5221e7a000) -# # libcrypto.so.1.1 => /lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007f5221ba4000) -# # libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5221b9e000) -# # libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f5221b7b000) -# # libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5221b60000) -# # libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f522196c000) -# # /lib64/ld-linux-x86-64.so.2 (0x00007f5223cb4000) -# # libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f522181d000) -# COPY --from=builder /target /target -# RUN mv /target/shadow /usr/bin \ -# && mv /target/* /usr/local/lib \ -# && rm -rf /target \ -# && ldconfig -# -# ENTRYPOINT ["shadow"] - diff --git a/Dockerfiles/release.Dockerfile b/Dockerfiles/release.Dockerfile deleted file mode 100644 index c459681c..00000000 --- a/Dockerfiles/release.Dockerfile +++ /dev/null @@ -1,33 +0,0 @@ -# FROM ubuntu:latest as builder -# ARG DEBIAN_FRONTEND=noninteractive -# ENV TZ=America/Los_Angeles -# COPY . shadow -# RUN apt-get update && apt-get -y upgrade \ -# && apt-get -y install golang cargo libssl-dev clang-tools \ -# && cd shadow \ -# && cargo build --release -vv \ -# && mkdir /target \ -# && cp /shadow/target/release/shadow /target \ -# && cp /usr/local/lib/libdarwinia_shadow.so /target \ -# && cp /lib/x86_64-linux-gnu/libssl.so.1.1 /target \ -# && cp /lib/x86_64-linux-gnu/libcrypto.so.1.1 /target - -FROM debian:stretch-slim -# linux-vdso.so.1 (0x00007fffdafe6000) -# libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f5221f0d000) -# libssl.so.1.1 => /lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007f5221e7a000) -# libcrypto.so.1.1 => /lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007f5221ba4000) -# libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5221b9e000) -# libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f5221b7b000) -# libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5221b60000) -# libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f522196c000) -# /lib64/ld-linux-x86-64.so.2 (0x00007f5223cb4000) -# libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f522181d000) -COPY --from=b:t /target /target -# RUN mv /target/shadow /usr/bin \ -# && mv /target/* /usr/local/lib \ -# && rm -rf /target \ -# && ldconfig -# -# ENTRYPOINT ["shadow"] -