diff --git a/Dockerfile b/Dockerfile index 33e3c3eb..318938d0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,61 +1,58 @@ -FROM debian:stretch-slim AS build +FROM rust:slim AS build MAINTAINER Ivan ARG FEATURES -RUN apt -o Acquire::https::No-Cache=True -o Acquire::http::No-Cache=True update &&\ - apt-get install -y pkg-config openssl libssl-dev libtag1-dev libtagc0-dev curl yasm build-essential wget libbz2-dev zlib1g-dev &&\ - curl -sL https://deb.nodesource.com/setup_8.x | bash - &&\ - apt-get install -y nodejs - -COPY . /audioserve_src - -RUN curl https://sh.rustup.rs -sSf | sh -s -- -y - -RUN mkdir ffmpeg-static &&\ - curl -sL https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz | tar xJv -C ffmpeg-static --strip-components=1 --wildcards "*/ffmpeg" &&\ - cp /ffmpeg-static/ffmpeg /usr/bin +RUN apt-get update && \ + apt-get install -y \ + curl \ + libbz2-dev \ + libssl1.0-dev \ + libtag1-dev \ + libtagc0-dev \ + openssl \ + pkg-config \ + yasm && \ + mkdir ffmpeg-static && \ + curl -sL https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz | \ + tar xJv -C ffmpeg-static --strip-components=1 --wildcards "*/ffmpeg" && \ + mv /ffmpeg-static/ffmpeg /usr/bin/ffmpeg + +WORKDIR /src +COPY Cargo.toml Cargo.lock /src/ +# To cache this step, we only copy the toml file above +RUN cargo fetch + +COPY . /src + +RUN cargo build --release ${FEATURES} && \ + cargo test --release ${FEATURES} +FROM node:8-alpine as frontend -RUN export PATH=${HOME}/.cargo/bin:$PATH &&\ - cd audioserve_src &&\ - cargo build --release ${FEATURES} &&\ - cargo test --release ${FEATURES} +WORKDIR /src +COPY client /src -RUN cd audioserve_src/client &&\ - npm install &&\ +RUN npm install && \ npm run build -RUN mkdir /ssl &&\ - cd /ssl &&\ - openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem \ - -subj "/C=CZ/ST=Prague/L=Prague/O=Ivan/CN=audioserve" &&\ - openssl pkcs12 -inkey key.pem -in certificate.pem -export -passout pass:mypass -out audioserve.p12 - FROM debian:stretch-slim VOLUME /audiobooks COPY --from=build /audioserve_src/target/release/audioserve /audioserve/audioserve -COPY --from=build /audioserve_src/client/dist /audioserve/client/dist -COPY --from=build /ssl/audioserve.p12 /audioserve/ssl/audioserve.p12 +COPY --from=frontend /audioserve_src/client/dist /audioserve/client/dist COPY --from=build /ffmpeg-static/ffmpeg /usr/bin -RUN adduser audioserve &&\ - chown -R audioserve:audioserve /audioserve &&\ - apt -o Acquire::https::No-Cache=True -o Acquire::http::No-Cache=True update &&\ +RUN adduser audioserve && \ + chown -R audioserve:audioserve /audioserve && \ + apt -o Acquire::https::No-Cache=True -o Acquire::http::No-Cache=True update && \ apt-get install -y libssl1.1 libtag1v5 libtagc0 libbz2-1.0 - + WORKDIR /audioserve USER audioserve - -ENV SECRET=mypass -ENV SSLKEY=./ssl/audioserve.p12 -ENV SSLPASS=mypass -ENV DIRS=/audiobooks ENV PORT=3000 EXPOSE ${PORT} -COPY audioserve.sh . - -CMD ./audioserve.sh +ENTRYPOINT ["/audioserve/audioserve"] +CMD ["/audiobooks"] \ No newline at end of file diff --git a/audioserve.sh b/audioserve.sh deleted file mode 100755 index 20e7971d..00000000 --- a/audioserve.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash -ARGS="${DIRS} --shared-secret ${SECRET}" -if [[ ! -z "${SSLKEY}" ]]; then - ARGS="${ARGS} --ssl-key ${SSLKEY}" -fi - -if [[ ! -z "${SSLPASS}" ]]; then - ARGS="${ARGS} --ssl-key-password ${SSLPASS}" -fi - -if [[ ! -z "${PORT}" ]]; then - ARGS="${ARGS} --listen 0.0.0.0:${PORT}" -fi - -if [[ ! -z "${OTHER_ARGS}" ]]; then - ARGS="${ARGS} ${OTHER_ARGS}" -fi - -./audioserve ${ARGS}