From d2627d6b8f73c468bc61a5dab258e9d319664795 Mon Sep 17 00:00:00 2001 From: asonix Date: Wed, 17 Jun 2020 10:21:54 -0500 Subject: [PATCH] Alter docker dev to create rust environment --- README.md | 23 +++++----- docker/dev/Dockerfile | 81 ++++++----------------------------- docker/dev/dev.sh | 3 +- docker/dev/docker-compose.yml | 11 ++--- 4 files changed, 34 insertions(+), 84 deletions(-) diff --git a/README.md b/README.md index 11a060a..27a180c 100644 --- a/README.md +++ b/README.md @@ -44,20 +44,23 @@ $ ./pict-rs -a 127.0.0.1:8080 -p data/ -w thumbnail identity Run the following commands: ``` # Create a folder for the files (anywhere works) -mkdir ./pict-rs -cd ./pict-rs -mkdir -p volumes/pictrs -sudo chown -R 991:991 volumes/pictrs -wget https://git.asonix.dog/asonix/pict-rs/raw/branch/master/docker/prod/docker-compose.yml -sudo docker-compose up -d +$ mkdir ./pict-rs +$ cd ./pict-rs +$ mkdir -p volumes/pictrs +$ sudo chown -R 991:991 volumes/pictrs +$ wget https://git.asonix.dog/asonix/pict-rs/raw/branch/master/docker/prod/docker-compose.yml +$ sudo docker-compose up -d ``` #### Docker Development -Run the following to develop in docker: +The development system loads a rust environment inside a docker container with the neccessary +dependencies already present ``` -git clone https://git.asonix.dog/asonix/pict-rs -cd pict-rs/docker/dev -./dev.sh +$ git clone https://git.asonix.dog/asonix/pict-rs +$ cd pict-rs/docker/dev +$ ./dev.sh +$ cargo build +$ cargo run ``` ### API diff --git a/docker/dev/Dockerfile b/docker/dev/Dockerfile index fce76d5..4a3ef9f 100644 --- a/docker/dev/Dockerfile +++ b/docker/dev/Dockerfile @@ -1,13 +1,9 @@ -# Target environment -FROM amd64/ubuntu:20.04 as target-env - -ENV \ - TARGET=x86_64-unknown-linux-gnu \ - BUILD_MODE=release - # Basic cross-build environment FROM ubuntu:20.04 as cross-build +ARG UID=1000 +ARG GID=1000 + ENV \ ARCH=amd64 \ HOST=x86_64-unknown-linux \ @@ -32,12 +28,12 @@ ENV \ RUN \ sed 's/http:\/\/\(.*\).ubuntu.com\/ubuntu\//[arch-=amd64,i386] http:\/\/ports.ubuntu.com\/ubuntu-ports\//g' /etc/apt/sources.list > /etc/apt/sources.list.d/ports.list && \ sed -i 's/http:\/\/\(.*\).ubuntu.com\/ubuntu\//[arch=amd64,i386] http:\/\/\1.archive.ubuntu.com\/ubuntu\//g' /etc/apt/sources.list && \ - addgroup --gid 991 build && \ + addgroup --gid $GID build && \ adduser \ --disabled-password \ --gecos "" \ --ingroup build \ - --uid 991 \ + --uid $UID \ --home /opt/build \ build && \ dpkg --add-architecture $ARCH && \ @@ -129,7 +125,13 @@ RUN \ libltdl7:$ARCH \ llvm-dev \ libclang-dev \ - clang + clang \ + libpng16-16:$ARCH \ + libjpeg8:$ARCH \ + libwebp6:$ARCH \ + libwebpdemux2:$ARCH \ + libwebpmux3:$ARCH \ + libgomp1:$ARCH ENV \ PATH=$PATH:/opt/build/.cargo/bin \ @@ -149,64 +151,7 @@ COPY --from=imagemagick-builder /usr/local/ /usr/local USER build -WORKDIR /opt/build - RUN \ - USER=build cargo new repo + mkdir -p /opt/build/repo WORKDIR /opt/build/repo - -COPY --chown=build:build Cargo.toml Cargo.lock ./ - -RUN \ - mkdir -p ./src && \ - echo 'fn main() { println!("Dummy") }' > ./src/main.rs && \ - USER=build cargo build --$BUILD_MODE && \ - rm -rf ./src && \ - rm -rf ./target/$BUILD_MODE/deps/pict_rs-* - -COPY --chown=build:build src ./src/ - -RUN \ - cargo build --$BUILD_MODE --frozen - -# Producing target binary -FROM target-env - -ARG UID=991 -ARG GID=991 - -RUN \ - addgroup --gid $GID pictrs && \ - adduser \ - --disabled-password \ - --gecos "" \ - --ingroup pictrs \ - --uid $UID \ - --home /opt/pict-rs \ - pictrs && \ - apt-get update && \ - apt-get upgrade -y && \ - apt-get install -y \ - libgexiv2-2 \ - libpng16-16 \ - libjpeg8 \ - libwebp6 \ - libwebpdemux2 \ - libwebpmux3 \ - libltdl7 \ - libgomp1 \ - libxml2 \ - tini - -COPY --from=pict-rs-builder /opt/build/repo/target/$BUILD_MODE/pict-rs /usr/local/bin/pict-rs -COPY --from=imagemagick-builder /usr/local /usr/local - -ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib - -VOLUME /mnt -WORKDIR /opt/pict-rs -USER pictrs -EXPOSE 8080 -ENTRYPOINT ["/usr/bin/tini", "--"] -CMD ["/usr/local/bin/pict-rs", "-p", "/mnt"] diff --git a/docker/dev/dev.sh b/docker/dev/dev.sh index 588bcb2..f6ffc63 100755 --- a/docker/dev/dev.sh +++ b/docker/dev/dev.sh @@ -5,4 +5,5 @@ export GROUP_ID=$(id -g) mkdir -p ./volumes/pictrs -docker-compose up --build +docker-compose build --pull +docker-compose run --service-ports pictrs diff --git a/docker/dev/docker-compose.yml b/docker/dev/docker-compose.yml index 48a94b0..471763b 100644 --- a/docker/dev/docker-compose.yml +++ b/docker/dev/docker-compose.yml @@ -3,15 +3,16 @@ version: '3.3' services: pictrs: build: - context: ../../ - dockerfile: docker/dev/Dockerfile + context: . + dockerfile: Dockerfile args: UID: "${USER_ID:-1000}" GID: "${GROUP_ID:-1000}" ports: - - "127.0.0.1:8080:8080" - restart: always + - "8080:8080" + stdin_open: true + tty: true environment: - RUST_LOG=info,pict_rs=debug volumes: - - ./volumes/pictrs:/mnt + - ../../:/opt/build/repo