Updating docker setup.

main
Heretic 8 months ago
parent 5bc7ef13cc
commit 053fc14d6a

@ -4,6 +4,10 @@ version = "0.1.0"
authors = ["Heretic <tylerjobsearch06@gmx.com>"]
edition = "2018"
[profile.release]
strip = true # Automatically strip symbols from the binary.
opt-level = "z" # Optimize for size.
[dependencies]
actix-web = "4.4.0"
actix-files = "0.6.2"

@ -0,0 +1,57 @@
ARG RUST_VERSION=1.72
ARG RUST_RELEASE_MODE=debug
ARG DISTROLESS_IMAGE=gcr.io/distroless/cc-debian12
# Build the torrents.db file
FROM alpine as db_file_builder
RUN apk add sqlite bash
WORKDIR /app
COPY ./data .
WORKDIR /app/scripts
RUN ./import_to_sqlite_fast.sh
FROM lukemathwalker/cargo-chef:latest-rust-${RUST_VERSION} as chef
WORKDIR /app
FROM chef as planner
COPY ./Cargo.toml ./Cargo.lock ./
COPY ./src src
RUN cargo chef prepare --recipe-path recipe.json
FROM chef as builder
ARG RUST_RELEASE_MODE
COPY --from=planner /app/recipe.json ./recipe.json
# Cargo chef cook
RUN set -ex; \
if [ "${RUST_RELEASE_MODE}" = "debug" ]; then \
cargo chef cook --recipe-path recipe.json; \
else \
cargo chef cook --release --recipe-path recipe.json; \
fi
COPY ./Cargo.toml ./Cargo.lock ./
COPY ./src src
# Cargo build
RUN set -ex; \
if [ "${RUST_RELEASE_MODE}" = "debug" ]; then \
cargo build; \
else \
cargo build --release; \
fi
# reduce binary size
RUN strip ./target/$RUST_RELEASE_MODE/torrents-csv-service
RUN cp ./target/$RUST_RELEASE_MODE/torrents-csv-service /app/torrents-csv-service
# The runner
FROM $DISTROLESS_IMAGE
# Copy resources
COPY --from=builder /app/torrents-csv-service /app/
COPY --from=db_file_builder /app/torrents.db /app/torrents.db
EXPOSE 8080
CMD ["/app/torrents-csv-service"]

@ -1,7 +1,7 @@
#!/bin/sh
# Rebuilding docker
sudo docker build ../../ --file ../prod/Dockerfile -t torrents-csv-server:latest -t dessalines/torrents-csv-server:latest
sudo docker build ../ --file Dockerfile --build-arg RUST_RELEASE_MODE=release -t torrents-csv-server:latest -t dessalines/torrents-csv-server:latest
sudo docker push dessalines/torrents-csv-server:latest
# SSH and pull it

@ -1,48 +0,0 @@
ARG RUST_BUILDER_IMAGE=clux/muslrust:stable
# Build the torrents.db file
FROM alpine:3 as db_file_builder
RUN apk add sqlite bash
WORKDIR /app
COPY ./data .
WORKDIR /app/scripts
RUN ./import_to_sqlite_fast.sh
FROM $RUST_BUILDER_IMAGE as chef
USER root
RUN cargo install cargo-chef --locked
WORKDIR /app
# Chef plan
FROM chef as planner
COPY ./Cargo.toml ./Cargo.lock ./
COPY ./src src
RUN cargo chef prepare --recipe-path recipe.json
# Chef build
FROM chef as builder
ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl
ARG RUSTRELEASEDIR="debug"
COPY --from=planner /app/recipe.json ./recipe.json
RUN cargo chef cook --target ${CARGO_BUILD_TARGET} --recipe-path recipe.json
COPY ./Cargo.toml ./Cargo.lock ./
COPY ./src src
RUN cargo build --target ${CARGO_BUILD_TARGET}
# reduce binary size
RUN strip ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/torrents-csv-service
RUN cp ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/torrents-csv-service /app/torrents-csv-service
# The runner
FROM alpine:3
RUN addgroup -S myuser && adduser -S myuser -G myuser
# Copy resources
COPY --from=builder /app/torrents-csv-service /app/
COPY --from=db_file_builder /app/torrents.db /app/torrents.db
EXPOSE 8080
USER myuser
CMD ["/app/torrents-csv-service"]

@ -1,3 +0,0 @@
#!/bin/sh
sudo docker build ../../ --file ../dev/Dockerfile -t torrents-csv-server:latest
sudo docker-compose up -d

@ -9,4 +9,3 @@ services:
environment:
TORRENTS_CSV_DB_FILE: /app/torrents.db
TORRENTS_CSV_FRONT_END_DIR: /app/dist
# You should run perseus locally to test

@ -0,0 +1,3 @@
#!/bin/sh
sudo docker build ../ --file Dockerfile -t torrents-csv-server:latest
sudo docker-compose up -d

@ -1,48 +0,0 @@
ARG RUST_BUILDER_IMAGE=clux/muslrust:stable
# Build the torrents.db file
FROM alpine:3 as db_file_builder
RUN apk add sqlite bash
WORKDIR /app
COPY ./data .
WORKDIR /app/scripts
RUN ./import_to_sqlite_fast.sh
FROM $RUST_BUILDER_IMAGE as chef
USER root
RUN cargo install cargo-chef --locked
WORKDIR /app
# Chef plan
FROM chef as planner
COPY ./Cargo.toml ./Cargo.lock ./
COPY ./src src
RUN cargo chef prepare --recipe-path recipe.json
# Chef build
FROM chef as builder
ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl
ARG RUSTRELEASEDIR="release"
COPY --from=planner /app/recipe.json ./recipe.json
RUN cargo chef cook --release --target ${CARGO_BUILD_TARGET} --recipe-path recipe.json
COPY ./Cargo.toml ./Cargo.lock ./
COPY ./src src
RUN cargo build --release --target ${CARGO_BUILD_TARGET}
# reduce binary size
RUN strip ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/torrents-csv-service
RUN cp ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/torrents-csv-service /app/torrents-csv-service
# The runner
FROM alpine:3
RUN addgroup -S myuser && adduser -S myuser -G myuser
# Copy resources
COPY --from=builder /app/torrents-csv-service /app/
COPY --from=db_file_builder /app/torrents.db /app/torrents.db
EXPOSE 8080
USER myuser
CMD ["/app/torrents-csv-service"]

@ -1,45 +0,0 @@
version: '3.7'
networks:
# communication to web and clients
torrentsexternalproxy:
# communication between lemmy services
torrentsinternal:
driver: bridge
internal: true
services:
proxy:
image: nginx:1-alpine
networks:
- torrentsinternal
- torrentsexternalproxy
ports:
# actual and only port facing any connection from outside
- "8904:8904"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
restart: always
depends_on:
- torrents-csv
- torrents-csv-ui-perseus
torrents-csv:
image: dessalines/torrents-csv-server:latest
restart: always
hostname: torrents-csv
networks:
- torrentsinternal
environment:
TORRENTS_CSV_DB_FILE: /app/torrents.db
TORRENTS_CSV_FRONT_END_DIR: /app/dist
torrents-csv-ui-perseus:
image: dessalines/torrents-csv-ui-perseus:latest
restart: always
networks:
- torrentsinternal
environment:
PERSEUS_HOST: "0.0.0.0"
TORRENTS_CSV_ENDPOINT: "http://torrents-csv:8902"

@ -1,55 +0,0 @@
worker_processes 1;
events {
worker_connections 1024;
}
http {
upstream torrents-csv {
server "torrents-csv:8902";
}
upstream torrents-csv-ui-perseus {
server "torrents-csv-ui-perseus:8080";
}
server {
# this is the port inside docker, not the public one yet
listen 8904;
# change if needed, this is facing the public web
server_name localhost;
server_tokens off;
gzip on;
gzip_types text/css application/javascript image/svg+xml;
gzip_vary on;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
# frontend general requests
location / {
set $proxpass "http://torrents-csv-ui-perseus";
proxy_pass $proxpass;
rewrite ^(.+)/+$ $1 permanent;
# Send actual client IP upstream
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# backend
location ~ ^/(service) {
proxy_pass "http://torrents-csv";
# proxy common stuff
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Send actual client IP upstream
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
Loading…
Cancel
Save