Compare commits
5 Commits
0b7549c2b6
...
master
Author | SHA1 | Date | |
---|---|---|---|
5075fb6b7d
|
|||
7a438a24b3
|
|||
386036554e
|
|||
63a4d7ac32
|
|||
e548f1b268
|
3
.dockerignore
Normal file
3
.dockerignore
Normal file
@ -0,0 +1,3 @@
|
||||
target
|
||||
.env
|
||||
Dockerfile
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
/target
|
||||
.env
|
||||
.env
|
||||
docker-compose.prod.yml
|
34
Cargo.lock
generated
34
Cargo.lock
generated
@ -99,9 +99,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bindgen"
|
||||
version = "0.63.0"
|
||||
version = "0.65.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "36d860121800b2a9a94f9b5604b332d5cffb234ce17609ea479d723dbc9d3885"
|
||||
checksum = "cfdf7b466f9a4903edc73f95d6d2bcd5baf8ae620638762244d3f60143643cc5"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cexpr",
|
||||
@ -110,12 +110,13 @@ dependencies = [
|
||||
"lazycell",
|
||||
"log",
|
||||
"peeking_take_while",
|
||||
"prettyplease",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"regex",
|
||||
"rustc-hash",
|
||||
"shlex",
|
||||
"syn 1.0.109",
|
||||
"syn 2.0.13",
|
||||
"which",
|
||||
]
|
||||
|
||||
@ -169,18 +170,6 @@ version = "0.15.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
|
||||
|
||||
[[package]]
|
||||
name = "dotenvy_macro"
|
||||
version = "0.15.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb0235d912a8c749f4e0c9f18ca253b4c28cfefc1d2518096016d6e3230b6424"
|
||||
dependencies = [
|
||||
"dotenvy",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.8.1"
|
||||
@ -438,7 +427,6 @@ dependencies = [
|
||||
"anyhow",
|
||||
"axum",
|
||||
"dotenvy",
|
||||
"dotenvy_macro",
|
||||
"env_logger",
|
||||
"log",
|
||||
"magick_rust",
|
||||
@ -458,9 +446,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "magick_rust"
|
||||
version = "0.17.0"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "31ad8b956bdc8d2bcb4e6feaeac3642a1d91892271c9e70f2a5c408a755c26e3"
|
||||
checksum = "5cf5e5282afc226caad138bcc3969f62f2460c8df3680d6036878cb5f6c0925c"
|
||||
dependencies = [
|
||||
"bindgen",
|
||||
"libc",
|
||||
@ -597,6 +585,16 @@ version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
|
||||
|
||||
[[package]]
|
||||
name = "prettyplease"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ceca8aaf45b5c46ec7ed39fff75f57290368c1846d33d24a122ca81416ab058"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"syn 2.0.13",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.55"
|
||||
|
10
Cargo.toml
10
Cargo.toml
@ -3,16 +3,18 @@ edition = "2021"
|
||||
name = "liquid-rescale-api"
|
||||
version = "0.1.0"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
# This seems redundant, but it's necessary for Docker to work
|
||||
[[bin]]
|
||||
name = "liquid-rescale-api"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.70"
|
||||
axum = {version = "0.6", features = ["multipart", "macros"]}
|
||||
dotenvy = "0.15.7"
|
||||
dotenvy_macro = "0.15.7"
|
||||
env_logger = "0.10.0"
|
||||
log = "0.4.17"
|
||||
magick_rust = "0.17.0"
|
||||
serde = { version = "1.0.159", features = ["derive"] }
|
||||
magick_rust = "0.18.0"
|
||||
serde = {version = "1.0.159", features = ["derive"]}
|
||||
serde_json = "1.0.95"
|
||||
tokio = {version = "1", features = ["macros", "rt-multi-thread"]}
|
||||
|
90
Dockerfile
Normal file
90
Dockerfile
Normal file
@ -0,0 +1,90 @@
|
||||
FROM debian:11-slim as imagick-builder
|
||||
|
||||
ENV MAGICK_VERSION 7.1.1-8
|
||||
|
||||
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.69.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
20
Makefile
Normal file
@ -0,0 +1,20 @@
|
||||
build:
|
||||
docker buildx build --platform linux/amd64 -t liquid-rescale-api:latest .
|
||||
|
||||
build-plain:
|
||||
docker buildx build --platform linux/amd64 --progress plain -t liquid-rescale-api:latest .
|
||||
|
||||
build-no-cache:
|
||||
docker buildx build --platform linux/amd64 --no-cache -t liquid-rescale-api:latest .
|
||||
|
||||
shell:
|
||||
docker run --rm -it --entrypoint bash liquid-rescale-api:latest
|
||||
|
||||
run:
|
||||
docker run --name liquid-rescale-api --init --rm -it -p 3021:3000 liquid-rescale-api:latest
|
||||
|
||||
tag:
|
||||
docker tag liquid-rescale-api:latest git.zeldon.ru/zeldon/liquid-rescale-api
|
||||
|
||||
push:
|
||||
docker push git.zeldon.ru/zeldon/liquid-rescale-api:latest
|
13
docker-compose.yml
Normal file
13
docker-compose.yml
Normal file
@ -0,0 +1,13 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
liquid-rescale-api:
|
||||
container_name: 'liquid-rescale-api'
|
||||
environment:
|
||||
PORT: 3021
|
||||
ports:
|
||||
- 3021:3021
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
restart: unless-stopped
|
1
docker_utils/dummy.rs
Normal file
1
docker_utils/dummy.rs
Normal file
@ -0,0 +1 @@
|
||||
fn main() {}
|
@ -3,12 +3,10 @@ mod router;
|
||||
mod routes;
|
||||
mod utilities;
|
||||
|
||||
use dotenvy_macro::dotenv;
|
||||
use router::create_router;
|
||||
use std::net::SocketAddr;
|
||||
|
||||
pub async fn run() {
|
||||
let port = dotenv!("PORT");
|
||||
pub async fn run(port: String) {
|
||||
let app = create_router();
|
||||
let address = SocketAddr::from(([0, 0, 0, 0], port.parse().unwrap()));
|
||||
|
||||
|
@ -5,7 +5,8 @@ use log::info;
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
dotenvy::dotenv().ok();
|
||||
let port = dotenvy::var("PORT").unwrap_or("3000".to_string());
|
||||
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
||||
info!("Starting app on {}", dotenvy::var("PORT").unwrap());
|
||||
run().await;
|
||||
info!("Starting app on {}", port);
|
||||
run(port).await;
|
||||
}
|
||||
|
Reference in New Issue
Block a user