From cf2771688dcaed664580fb6222acfd656629f6c1 Mon Sep 17 00:00:00 2001 From: STAM Date: Wed, 5 Apr 2023 17:50:45 +0300 Subject: [PATCH] torrust-tracker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit wip tt ะตะต --- .../epicmorg.ecosysctem.misc.images.yml | 3 + CHANGELOG.md | 3 + Makefile | 1 + linux/ecosystem/torrust-index/Dockerfile | 77 +++++++++++++++++++ linux/ecosystem/torrust-index/Makefile | 19 +++++ .../torrust-index/docker-compose.yml | 6 ++ .../torrust-index/docker-entrypoint.sh | 8 ++ linux/ecosystem/torrust-index/supervisor.conf | 14 ++++ .../torrust-index/torrust-index.conf | 60 +++++++++++++++ linux/ecosystem/torrust-tracker/Dockerfile | 30 ++++---- .../torrust-tracker/docker-entrypoint.sh | 6 +- 11 files changed, 209 insertions(+), 18 deletions(-) create mode 100644 linux/ecosystem/torrust-index/Dockerfile create mode 100644 linux/ecosystem/torrust-index/Makefile create mode 100644 linux/ecosystem/torrust-index/docker-compose.yml create mode 100644 linux/ecosystem/torrust-index/docker-entrypoint.sh create mode 100644 linux/ecosystem/torrust-index/supervisor.conf create mode 100644 linux/ecosystem/torrust-index/torrust-index.conf diff --git a/.github/workflows/epicmorg.ecosysctem.misc.images.yml b/.github/workflows/epicmorg.ecosysctem.misc.images.yml index 4296b4181..c89083bdf 100644 --- a/.github/workflows/epicmorg.ecosysctem.misc.images.yml +++ b/.github/workflows/epicmorg.ecosysctem.misc.images.yml @@ -126,6 +126,9 @@ jobs: - name: Build and Deploy Torrust Tracker run: cd linux/ecosystem/torrust-tracker && make build && make deploy + - name: Build and Deploy Torrust Index + run: cd linux/ecosystem/torrust-index && make build && make deploy + ################################################################################## build-monero-cli-image: diff --git a/CHANGELOG.md b/CHANGELOG.md index ff886dd7d..caef06627 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog ## 2023 +* `apr` + * `apache2` image fixed + * added `torrust-index` image * `feb-mar` * added new `sentry` advanced image * `jan` diff --git a/Makefile b/Makefile index 1ada3ee52..8c071cff6 100644 --- a/Makefile +++ b/Makefile @@ -402,6 +402,7 @@ ecosystem-opentracker-images: ecosystem-torrust-tracker-images: cd `pwd`/linux/ecosystem/torrust-tracker && pwd && make build && make deploy + cd `pwd`/linux/ecosystem/torrust-index && pwd && make build && make deploy ecosystem-monero-images: cd `pwd`/linux/ecosystem/monero/monerod && pwd && make build && make deploy diff --git a/linux/ecosystem/torrust-index/Dockerfile b/linux/ecosystem/torrust-index/Dockerfile new file mode 100644 index 000000000..71b4d1e25 --- /dev/null +++ b/linux/ecosystem/torrust-index/Dockerfile @@ -0,0 +1,77 @@ + +FROM epicmorg/nodejs:node19 as nodejs + +RUN git clone https://github.com/torrust/torrust-index-frontend.git -b develop /opt/torrust-index-frontend && \ + cd /opt/torrust-index-frontend && \ + echo "VITE_API_BASE_URL=/api" > .env && \ + npm i && \ + npm run build && \ + ls -las && \ + cd ./dist/ && \ + ls -las + + +FROM epicmorg/debian:bullseye-develop as builder + +RUN git clone https://github.com/torrust/torrust-index-backend.git -b develop /opt/torrust-index-backend && \ + cd /opt/torrust-index-backend && \ + echo "DATABASE_URL=sqlite://data.db?mode=rwc" >> .env && \ + cargo install sqlx-cli && \ + sqlx db setup && \ + cargo build --release && \ + ls -las && \ + cd ./target/release/ && \ + mv ./main ./torrust-index-backend && \ + mv ./upgrade ./torrust-index-upgrade && \ + ls -las + +FROM epicmorg/nginx:latest + +ENV TORRUST_PORT=80 +ENV TORRUST_DIR=/app +ENV TORRUST_BIN=${TORRUST_DIR}/bin +ENV TORRUST_DATA=${TORRUST_DIR}/data +ENV TORRUST_UPLOADS=${TORRUST_DIR}/uploads +ENV TORRUST_WWW=${TORRUST_DIR}/www + +RUN mkdir -p ${TORRUST_DIR} ${TORRUST_BIN} ${TORRUST_DATA} ${TORRUST_UPLOADS} ${TORRUST_WWW} + +RUN ln -sf ${TORRUST_DATA}/config.toml ${TORRUST_BIN}/config.toml +RUN ln -sf ${TORRUST_DATA}/data.db ${TORRUST_BIN}/data.db + + +COPY --from=builder /opt/torrust-index-backend/target/release/torrust-index-backend ${TORRUST_BIN}/torrust-index-backend +COPY --from=builder /opt/torrust-index-backend/target/release/torrust-index-upgrade ${TORRUST_BIN}/torrust-index-upgrade +RUN chmod +x ${TORRUST_BIN}/torrust-index-backend && \ + chmod +x ${TORRUST_BIN}/torrust-index-upgrade + +COPY --from=nodejs /opt/torrust-index-frontend/dist/ ${TORRUST_WWW} +RUN tree ${TORRUST_WWW} && \ + chown -R www-data:www-data ${TORRUST_WWW} && \ + ls -las ${TORRUST_WWW} + +RUN apt-get update && \ + apt-get -y install supervisor && \ + mkdir -p /var/log/supervisor && \ + mkdir -p /etc/supervisor/conf.d + +EXPOSE ${TORRUST_PORT} +EXPOSE ${TORRUST_PORT}/udp + +WORKDIR ${TORRUST_DIR} +VOLUME ${TORRUST_DATA} +VOLUME ${TORRUST_UPLOADS} + + +# nginx base configuration +ADD torrust-index.conf /etc/nginx/sites-enabled/torrust-index.conf + +# supervisor base configuration +ADD supervisor.conf /etc/supervisor.conf + +# Add image configuration and scripts +COPY docker-entrypoint.sh /usr/bin/docker-entrypoint.sh +RUN chmod 755 /usr/bin/docker-entrypoint.sh + +ENTRYPOINT ["tini", "-s", "--", "docker-entrypoint.sh"] +CMD ["docker-entrypoint.sh"] diff --git a/linux/ecosystem/torrust-index/Makefile b/linux/ecosystem/torrust-index/Makefile new file mode 100644 index 000000000..9ef622aa9 --- /dev/null +++ b/linux/ecosystem/torrust-index/Makefile @@ -0,0 +1,19 @@ +all: app + +app: + make build + make deploy + make clean + +build: + docker-compose build --compress --parallel --progress plain + +deploy: + docker-compose push + +clean: + docker container prune -f + docker image prune -f + docker network prune -f + docker volume prune -f + docker system prune -af diff --git a/linux/ecosystem/torrust-index/docker-compose.yml b/linux/ecosystem/torrust-index/docker-compose.yml new file mode 100644 index 000000000..b2d27e044 --- /dev/null +++ b/linux/ecosystem/torrust-index/docker-compose.yml @@ -0,0 +1,6 @@ +version: '3.9' +services: + app: + image: "epicmorg/torrust-index:latest" + build: + context: . diff --git a/linux/ecosystem/torrust-index/docker-entrypoint.sh b/linux/ecosystem/torrust-index/docker-entrypoint.sh new file mode 100644 index 000000000..36ab4b87b --- /dev/null +++ b/linux/ecosystem/torrust-index/docker-entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -euo pipefail + +# Setup default Opts +: ${TORRUST_PORT:=80} + +echo "[torrust-index] Starting up with supervisord" +supervisord -c /etc/supervisor.conf diff --git a/linux/ecosystem/torrust-index/supervisor.conf b/linux/ecosystem/torrust-index/supervisor.conf new file mode 100644 index 000000000..560b1df12 --- /dev/null +++ b/linux/ecosystem/torrust-index/supervisor.conf @@ -0,0 +1,14 @@ +[supervisord] +nodaemon=true + +[program:nginx] +command=/usr/sbin/nginx -g 'daemon off;' +killasgroup=true +stopasgroup=true +redirect_stderr=true + +[program:torrust-index-backend] +directory=/app/bin +command=/bin/bash -c "/app/bin/torrust-index-backend" +stdout_logfile=/var/log/supervisor/%(program_name)s.log +stderr_logfile=/var/log/supervisor/%(program_name)s.log \ No newline at end of file diff --git a/linux/ecosystem/torrust-index/torrust-index.conf b/linux/ecosystem/torrust-index/torrust-index.conf new file mode 100644 index 000000000..4f1be690f --- /dev/null +++ b/linux/ecosystem/torrust-index/torrust-index.conf @@ -0,0 +1,60 @@ +set_real_ip_from 192.168.0.0/16; +set_real_ip_from 172.16.0.0/12; +set_real_ip_from 100.64.0.0/10; +set_real_ip_from 10.0.0.0/8; +real_ip_header X-Forwarded-For; +real_ip_recursive on; + +map $http_upgrade $connection_upgrade { + default upgrade; + '' close; +} + +map $scheme $msiis { + http off; + https on; +} + +server { + listen 80; + server_name _; + + root /app/www/; + location / { + try_files $uri $uri/ /index.html; + } + + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Credentials' 'true'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'; + + location /api/ { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Credentials' 'true'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'; + proxy_set_header 'Access-Control-Allow-Origin' '*'; + proxy_set_header 'Access-Control-Allow-Credentials' 'true'; + proxy_set_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + proxy_set_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header Accept-Encoding ""; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Server $host; + proxy_set_header X-FORWARDED-PROTOCOL $scheme; + proxy_set_header X-Url-Scheme $scheme; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Front-End-Https $msiis; + proxy_headers_hash_max_size 512; + proxy_headers_hash_bucket_size 512; + proxy_buffering off; + port_in_redirect off; + proxy_set_header Upgrade $http_upgrade; # WebSocket support + proxy_set_header Connection $connection_upgrade; # WebSocket support + proxy_pass http://127.0.0.1:3000/; + } +} diff --git a/linux/ecosystem/torrust-tracker/Dockerfile b/linux/ecosystem/torrust-tracker/Dockerfile index c584761be..76b886127 100644 --- a/linux/ecosystem/torrust-tracker/Dockerfile +++ b/linux/ecosystem/torrust-tracker/Dockerfile @@ -1,7 +1,7 @@ FROM epicmorg/debian:bullseye-develop as builder -RUN git clone https://github.com/torrust/torrust-tracker.git /opt/torrust-tracker && \ +RUN git clone https://github.com/torrust/torrust-tracker.git -b develop /opt/torrust-tracker && \ cd /opt/torrust-tracker && \ cargo build --release && \ ls -las && \ @@ -11,25 +11,25 @@ RUN git clone https://github.com/torrust/torrust-tracker.git /opt/torrust-tracke FROM epicmorg/debian:bullseye -ENV TRACKER_PORT=1337 -ENV TRACKER_ADMIN=1488 -ENV TRACKER_DIR=/app -ENV TRACKER_DATA=${TRACKER_DIR}/data +ARG TORRUST_PORT=1337 +ARG TORRUST_ADMIN=1488 +ENV TORRUST_DIR=/app +ENV TORRUST_DATA=${TORRUST_DIR}/data -RUN mkdir -p ${TRACKER_DIR} ${TRACKER_DATA} +RUN mkdir -p ${TORRUST_DIR} ${TORRUST_DATA} -RUN ln -sf ${TRACKER_DATA}/config.toml ${TRACKER_DIR}/config.toml -RUN ln -sf ${TRACKER_DATA}/data.db ${TRACKER_DIR}/data.db +RUN ln -sf ${TORRUST_DATA}/config.toml ${TORRUST_DIR}/config.toml +RUN ln -sf ${TORRUST_DATA}/data.db ${TORRUST_DIR}/data.db -COPY --from=builder /opt/torrust-tracker/target/release/torrust-tracker ${TRACKER_DIR}/torrust-tracker -RUN chmod 755 ${TRACKER_DIR}/torrust-tracker +COPY --from=builder /opt/torrust-tracker/target/release/torrust-tracker ${TORRUST_DIR}/torrust-tracker +RUN chmod 755 ${TORRUST_DIR}/torrust-tracker -EXPOSE ${TRACKER_PORT} -EXPOSE ${TRACKER_PORT}/udp -EXPOSE ${TRACKER_ADMIN} +EXPOSE ${TORRUST_PORT} +EXPOSE ${TORRUST_PORT}/udp +EXPOSE ${TORRUST_ADMIN} -WORKDIR ${TRACKER_DIR} -VOLUME ${TRACKER_DATA} +WORKDIR ${TORRUST_DIR} +VOLUME ${TORRUST_DATA} # Add image configuration and scripts COPY docker-entrypoint.sh /usr/bin/docker-entrypoint.sh diff --git a/linux/ecosystem/torrust-tracker/docker-entrypoint.sh b/linux/ecosystem/torrust-tracker/docker-entrypoint.sh index 515377284..7044ea5b1 100755 --- a/linux/ecosystem/torrust-tracker/docker-entrypoint.sh +++ b/linux/ecosystem/torrust-tracker/docker-entrypoint.sh @@ -2,9 +2,9 @@ set -euo pipefail # Setup default Opts -: ${RACKER_PORT:=1337} -: ${RACKER_ADMIN:=1488} +: ${TORRUST_PORT:=1337} +: ${TORRUST_ADMIN:=1488} echo "[torrust-tracker] Starting up" cd /app -/app/torrust-tracker +/app/torrust-tracker \ No newline at end of file