From c06ae8280f07285d24fa273adacfb0760ed629c0 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Sat, 22 Oct 2022 21:43:13 +0100 Subject: [PATCH] Add files to deploy on docker-compose. --- .dockerignore | 7 ++++ .github/workflows/build-docker.yml | 37 +++++++++++++++++++++ Cargo.lock | 53 ++++-------------------------- Cargo.toml | 1 - Dockerfile | 33 +++++++++++++++++++ Rocket.toml | 2 +- docker-compose.yml | 14 ++++++-- 7 files changed, 96 insertions(+), 51 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/build-docker.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5b70dbd --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.* +Dockerfile +docker-compose.yml +*.md +target/ +mirror/ +export/ \ No newline at end of file diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml new file mode 100644 index 0000000..d87a8fa --- /dev/null +++ b/.github/workflows/build-docker.yml @@ -0,0 +1,37 @@ +name: Docker Multi-Architecture Build + +on: + push: + paths-ignore: + - "**.md" + branches: + - main + +jobs: + build-docker-image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + with: + platforms: all + - name: Set up Docker BuildX + uses: docker/setup-buildx-action@v2 + with: + version: latest + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: 1337kavin/sponsorblock-mirror:latest + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Cargo.lock b/Cargo.lock index f6175ce..b21e779 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -143,18 +143,6 @@ dependencies = [ "alloc-stdlib", ] -[[package]] -name = "bstr" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" -dependencies = [ - "lazy_static", - "memchr", - "regex-automata", - "serde", -] - [[package]] name = "bumpalo" version = "3.11.0" @@ -221,28 +209,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "csv" -version = "1.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1" -dependencies = [ - "bstr", - "csv-core", - "itoa 0.4.8", - "ryu", - "serde", -] - -[[package]] -name = "csv-core" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" -dependencies = [ - "memchr", -] - [[package]] name = "devise" version = "0.3.1" @@ -285,7 +251,7 @@ dependencies = [ "bitflags", "byteorder", "diesel_derives", - "itoa 1.0.4", + "itoa", "pq-sys", "r2d2", ] @@ -538,7 +504,7 @@ checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" dependencies = [ "bytes", "fnv", - "itoa 1.0.4", + "itoa", ] [[package]] @@ -579,7 +545,7 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa 1.0.4", + "itoa", "pin-project-lite", "socket2", "tokio", @@ -656,12 +622,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" -[[package]] -name = "itoa" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" - [[package]] name = "itoa" version = "1.0.4" @@ -1438,7 +1398,7 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41feea4228a6f1cd09ec7a3593a682276702cd67b5273544757dae23c096f074" dependencies = [ - "itoa 1.0.4", + "itoa", "ryu", "serde", ] @@ -1450,7 +1410,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ "form_urlencoded", - "itoa 1.0.4", + "itoa", "ryu", "serde", ] @@ -1514,7 +1474,6 @@ checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" name = "sponsorblock-mirror" version = "0.1.0" dependencies = [ - "csv", "diesel", "diesel_logger", "diesel_migrations", @@ -1587,7 +1546,7 @@ version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d634a985c4d4238ec39cacaed2e7ae552fbd3c476b552c1deac3021b7d7eaf0c" dependencies = [ - "itoa 1.0.4", + "itoa", "libc", "num_threads", "time-macros", diff --git a/Cargo.toml b/Cargo.toml index 226f4ac..3e480d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,6 @@ version = "0.1.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -csv = "1.1.6" diesel = {version = "2.0.2", features = ["postgres"]} diesel_logger = "0.2.0" diesel_migrations = "2.0.0" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a9ba8c8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM rust:slim as BUILD + +RUN --mount=type=cache,target=/var/cache/apt \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + build-essential pkg-config libssl-dev libpq-dev && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /app/ + +COPY . . + +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/app/target/ \ + cargo build --release && \ + mv target/release/sponsorblock-mirror . + +FROM debian:stable-slim + +RUN --mount=type=cache,target=/var/cache/apt \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + libssl1.1 libpq5 && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /app/ + +COPY --from=BUILD /app/sponsorblock-mirror . +COPY --from=BUILD /app/Rocket.toml . + +EXPOSE 8000 + +CMD ["/app/sponsorblock-mirror"] diff --git a/Rocket.toml b/Rocket.toml index 2c1df32..340a209 100644 --- a/Rocket.toml +++ b/Rocket.toml @@ -5,4 +5,4 @@ address = "0.0.0.0" sponsorblock = { url = "postgresql://sponsorblock:password123@localhost" } [release.databases] -sponsorblock = { url = "postgresql://sponsorblock:password123@sponsorblock" } +sponsorblock = { url = "postgresql://sponsorblock:password123@postgres" } diff --git a/docker-compose.yml b/docker-compose.yml index 143e6b4..1bd26aa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,11 +10,12 @@ services: environment: - MIRROR=TRUE - MIRROR_URL=mirror.sb.mchang.xyz + restart: unless-stopped postgres: image: postgres:15-alpine container_name: postgres-sb-mirror - ports: - - 5432:5432 + # ports: + # - 5432:5432 volumes: - postgres_data:/var/lib/postgresql/data - ./mirror:/mirror @@ -22,5 +23,14 @@ services: - POSTGRES_DB=sponsorblock - POSTGRES_PASSWORD=password123 - POSTGRES_USER=sponsorblock + restart: unless-stopped + sponsorblock-mirror: + image: 1337kavin/sponsorblock-mirror:latest + container_name: sponsorblock-mirror + volumes: + - ./mirror:/app/mirror + ports: + - 8000:8000 + restart: unless-stopped volumes: postgres_data: null