Alter docker dev to create rust environment

This commit is contained in:
asonix 2020-06-17 10:21:54 -05:00
parent 044c34f27f
commit d2627d6b8f
4 changed files with 34 additions and 84 deletions

View file

@ -44,20 +44,23 @@ $ ./pict-rs -a 127.0.0.1:8080 -p data/ -w thumbnail identity
Run the following commands: Run the following commands:
``` ```
# Create a folder for the files (anywhere works) # Create a folder for the files (anywhere works)
mkdir ./pict-rs $ mkdir ./pict-rs
cd ./pict-rs $ cd ./pict-rs
mkdir -p volumes/pictrs $ mkdir -p volumes/pictrs
sudo chown -R 991:991 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 $ wget https://git.asonix.dog/asonix/pict-rs/raw/branch/master/docker/prod/docker-compose.yml
sudo docker-compose up -d $ sudo docker-compose up -d
``` ```
#### Docker Development #### 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 $ git clone https://git.asonix.dog/asonix/pict-rs
cd pict-rs/docker/dev $ cd pict-rs/docker/dev
./dev.sh $ ./dev.sh
$ cargo build
$ cargo run
``` ```
### API ### API

View file

@ -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 # Basic cross-build environment
FROM ubuntu:20.04 as cross-build FROM ubuntu:20.04 as cross-build
ARG UID=1000
ARG GID=1000
ENV \ ENV \
ARCH=amd64 \ ARCH=amd64 \
HOST=x86_64-unknown-linux \ HOST=x86_64-unknown-linux \
@ -32,12 +28,12 @@ ENV \
RUN \ 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 '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 && \ 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 \ adduser \
--disabled-password \ --disabled-password \
--gecos "" \ --gecos "" \
--ingroup build \ --ingroup build \
--uid 991 \ --uid $UID \
--home /opt/build \ --home /opt/build \
build && \ build && \
dpkg --add-architecture $ARCH && \ dpkg --add-architecture $ARCH && \
@ -129,7 +125,13 @@ RUN \
libltdl7:$ARCH \ libltdl7:$ARCH \
llvm-dev \ llvm-dev \
libclang-dev \ libclang-dev \
clang clang \
libpng16-16:$ARCH \
libjpeg8:$ARCH \
libwebp6:$ARCH \
libwebpdemux2:$ARCH \
libwebpmux3:$ARCH \
libgomp1:$ARCH
ENV \ ENV \
PATH=$PATH:/opt/build/.cargo/bin \ PATH=$PATH:/opt/build/.cargo/bin \
@ -149,64 +151,7 @@ COPY --from=imagemagick-builder /usr/local/ /usr/local
USER build USER build
WORKDIR /opt/build
RUN \ RUN \
USER=build cargo new repo mkdir -p /opt/build/repo
WORKDIR /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"]

View file

@ -5,4 +5,5 @@ export GROUP_ID=$(id -g)
mkdir -p ./volumes/pictrs mkdir -p ./volumes/pictrs
docker-compose up --build docker-compose build --pull
docker-compose run --service-ports pictrs

View file

@ -3,15 +3,16 @@ version: '3.3'
services: services:
pictrs: pictrs:
build: build:
context: ../../ context: .
dockerfile: docker/dev/Dockerfile dockerfile: Dockerfile
args: args:
UID: "${USER_ID:-1000}" UID: "${USER_ID:-1000}"
GID: "${GROUP_ID:-1000}" GID: "${GROUP_ID:-1000}"
ports: ports:
- "127.0.0.1:8080:8080" - "8080:8080"
restart: always stdin_open: true
tty: true
environment: environment:
- RUST_LOG=info,pict_rs=debug - RUST_LOG=info,pict_rs=debug
volumes: volumes:
- ./volumes/pictrs:/mnt - ../../:/opt/build/repo