diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..633fa76 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +target +.env +Dockerfile \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0b745e2..f017653 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -.env \ No newline at end of file +.env +docker-compose.prod.yml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6793667 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +FROM fedora:38 as build +ENV PKG_CONFIG_ALLOW_CROSS=1 + +RUN dnf install -y rust cargo ImageMagick-devel clang --setopt=install_weak_deps=False + +ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse + +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 . . +# Add the wait script +ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.2.1/wait /wait +RUN chmod +x /wait +# Build our code +RUN cargo build --release + +FROM fedora:38 + +RUN dnf install -y ImageMagick-devel --setopt=install_weak_deps=False \ + && dnf clean all \ + && rm -rf /var/cache/yum + +COPY --from=build /usr/src/liquid-rescale-api/target/release/liquid-rescale-api /liquid-rescale-api/liquid-rescale-api +COPY --from=build /wait /wait + +WORKDIR /liquid-rescale-api + +CMD /wait && /liquid-rescale-api/liquid-rescale-api \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..39b57fb --- /dev/null +++ b/docker-compose.yml @@ -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 diff --git a/docker_utils/dummy.rs b/docker_utils/dummy.rs new file mode 100644 index 0000000..f328e4d --- /dev/null +++ b/docker_utils/dummy.rs @@ -0,0 +1 @@ +fn main() {}