This commit is contained in:
Timofey Gelazoniya 2023-07-13 17:00:09 +03:00
parent 09ff721ba6
commit 5e70207c5d
Signed by: zeldon
GPG Key ID: 047886915281DD2A
7 changed files with 138 additions and 1 deletions

View File

@ -3,6 +3,11 @@ name = "liquid-rescale-api-v2"
version = "0.1.0"
edition = "2021"
# This seems redundant, but it's necessary for Docker to work
[[bin]]
name = "liquid-rescale-api"
path = "src/main.rs"
[toolchain]
channel = "nightly"

90
Dockerfile Normal file
View File

@ -0,0 +1,90 @@
FROM debian:11-slim as imagick-builder
ENV MAGICK_VERSION 7.1.1-12
RUN apt-get update \
&& apt-get -y --no-install-recommends install \
wget \
ca-certificates \
build-essential \
clang \
glib-2.0 \
pkg-config \
libjpeg-dev \
libpng-dev \
liblqr-1-0-dev \
&& apt-get clean
WORKDIR /source
RUN wget "https://github.com/ImageMagick/ImageMagick/archive/${MAGICK_VERSION}.tar.gz"
WORKDIR /build
RUN tar -xvf "/source/${MAGICK_VERSION}.tar.gz" --strip-components=1
RUN ./configure \
--prefix=/opt/imagemagick \
--disable-docs \
--disable-openmp \
--with-gcc-arch=generic \
--with-gslib=no \
--with-magick-plus-plus=no \
--with-perl=no \
| tee configure.log
RUN make -j $(nproc)
RUN make install
FROM rust:1.70.0-slim as builder
RUN apt-get update \
&& apt-get -y --no-install-recommends install \
ca-certificates \
clang \
pkg-config \
&& apt-get clean
COPY --from=imagick-builder /opt/imagemagick /opt/imagemagick
COPY --from=imagick-builder /usr/lib/x86_64-linux-gnu/libjpeg* /usr/lib/x86_64-linux-gnu
COPY --from=imagick-builder /usr/lib/x86_64-linux-gnu/libpng16* /usr/lib/x86_64-linux-gnu
COPY --from=imagick-builder /usr/lib/x86_64-linux-gnu/liblqr-1* /usr/lib/x86_64-linux-gnu
COPY --from=imagick-builder /usr/lib/x86_64-linux-gnu/libglib-2.0* /usr/lib/x86_64-linux-gnu
ENV PKG_CONFIG_ALLOW_CROSS=1
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
ENV PKG_CONFIG_PATH=/opt/imagemagick/lib/pkgconfig
WORKDIR /usr/src/liquid-rescale-api
# Download and compile deps
COPY Cargo.toml .
COPY Cargo.lock .
COPY docker_utils/dummy.rs .
# Change temporarely the path of the code
RUN sed -i 's|src/main.rs|dummy.rs|' Cargo.toml
# Build only deps
RUN cargo build --release
# Now return the file back to normal
RUN sed -i 's|dummy.rs|src/main.rs|' Cargo.toml
# Copy everything
COPY . .
# Build our code
RUN cargo build --release
FROM gcr.io/distroless/cc
COPY --from=builder /usr/src/liquid-rescale-api/target/release/liquid-rescale-api /liquid-rescale-api
COPY --from=imagick-builder /opt/imagemagick /
COPY --from=imagick-builder /usr/lib/x86_64-linux-gnu/libjpeg* /usr/lib/x86_64-linux-gnu
COPY --from=imagick-builder /usr/lib/x86_64-linux-gnu/libpng16* /usr/lib/x86_64-linux-gnu
COPY --from=imagick-builder /usr/lib/x86_64-linux-gnu/liblqr-1* /usr/lib/x86_64-linux-gnu
COPY --from=imagick-builder /usr/lib/x86_64-linux-gnu/libglib-2.0* /usr/lib/x86_64-linux-gnu
COPY --from=imagick-builder /lib/x86_64-linux-gnu/libz* /lib/x86_64-linux-gnu
COPY --from=imagick-builder /lib/x86_64-linux-gnu/libpthread* /lib/x86_64-linux-gnu
COPY --from=imagick-builder /lib/x86_64-linux-gnu/libm* /lib/x86_64-linux-gnu
COPY --from=imagick-builder /lib/x86_64-linux-gnu/libc* /lib/x86_64-linux-gnu
COPY --from=imagick-builder /lib/x86_64-linux-gnu/libpcre* /lib/x86_64-linux-gnu
COPY --from=imagick-builder /lib64/ld-* /lib64
ENTRYPOINT ["./liquid-rescale-api"]

20
Makefile Normal file
View File

@ -0,0 +1,20 @@
IMAGE_NAME = liquid-rescale-api
IMAGE_TAG = v0.1
REGISTY = ghcr.io/xzeldon
IMAGE = $(IMAGE_NAME):$(IMAGE_TAG)
PORT = 8321
build:
docker buildx build -t $(IMAGE) .
run:
docker run --name $(IMAGE_NAME) --init --rm -it -p $(PORT):8321 $(IMAGE)
run-prod:
docker compose -f docker-compose.override.yml up -d
tag:
docker tag $(IMAGE) $(REGISTY)/$(IMAGE)
push:
docker push $(REGISTY)/$(IMAGE)

View File

@ -0,0 +1,8 @@
version: '3'
services:
liquid-rescale-api:
image: ghcr.io/xzeldon/liquid-rescale-api:v0.1
ports:
- 8321:8321
restart: unless-stopped

13
docker-compose.yml Normal file
View File

@ -0,0 +1,13 @@
version: '3'
services:
liquid-rescale-api:
container_name: 'liquid-rescale-api'
environment:
PORT: 8321
ports:
- 8321:8321
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped

1
docker_utils/dummy.rs Normal file
View File

@ -0,0 +1 @@
fn main() {}