From 60a01ea511b3432beb674fc14c3703bc724e2313 Mon Sep 17 00:00:00 2001 From: Tiara Rodney Date: Wed, 13 Apr 2022 12:54:59 +0200 Subject: [PATCH 1/2] refactor(samples/httpaste.it): finalize initial sample - add tor daemon - clean directory structure --- samples/httpaste.it/docker-compose.yml | 11 +++++++++-- samples/httpaste.it/httpaste.service | 17 +++++++++++++++++ .../{ => usr/local/httpaste}/config.ini | 0 .../{ => usr/local/apache2/conf}/httpd.conf | 7 +++++++ samples/httpaste.it/tor/Dockerfile | 10 ++++++++++ samples/httpaste.it/tor/etc/tor/torrc | 3 +++ .../httpaste.it/tor/usr/local/sbin/hostname.sh | 3 +++ 7 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 samples/httpaste.it/httpaste.service rename samples/httpaste.it/httpaste/{ => usr/local/httpaste}/config.ini (100%) rename samples/httpaste.it/httpd/{ => usr/local/apache2/conf}/httpd.conf (90%) create mode 100644 samples/httpaste.it/tor/Dockerfile create mode 100644 samples/httpaste.it/tor/etc/tor/torrc create mode 100755 samples/httpaste.it/tor/usr/local/sbin/hostname.sh diff --git a/samples/httpaste.it/docker-compose.yml b/samples/httpaste.it/docker-compose.yml index 35fb3db..a334189 100644 --- a/samples/httpaste.it/docker-compose.yml +++ b/samples/httpaste.it/docker-compose.yml @@ -4,6 +4,7 @@ services: build: context: ../.. dockerfile: Dockerfile + target: uwsgi environment: HTTPASTE_CONFIGPATH: /usr/local/httpaste/config.ini volumes: @@ -13,7 +14,7 @@ services: target: /shared volume: nocopy: true - - ./httpaste/config.ini:/usr/local/httpaste/config.ini + - ./httpaste/usr/local/httpaste/config.ini:/usr/local/httpaste/config.ini command: -s /shared/uwsgi.sock --chmod-socket=666 httpd: build: @@ -28,6 +29,12 @@ services: target: /shared volume: nocopy: true - - ./httpd/httpd.conf:/usr/local/apache2/conf/httpd.conf + - ./httpd/usr/local/apache2/conf/httpd.conf:/usr/local/apache2/conf/httpd.conf + tor: + build: + context: ./tor + dockerfile: Dockerfile + volumes: + - ./tor/etc/tor/torrc:/etc/tor/torrc volumes: system-shared: \ No newline at end of file diff --git a/samples/httpaste.it/httpaste.service b/samples/httpaste.it/httpaste.service new file mode 100644 index 0000000..37a85cb --- /dev/null +++ b/samples/httpaste.it/httpaste.service @@ -0,0 +1,17 @@ + +[Unit] +Description=httpaste (via Docker Compose) +Requires=docker.service +After=docker.service + +[Service] +WorkingDirectory=/usr/local/src/httpaste/samples/httpaste.it +ExecStart=docker-compose up +ExecStop=docker-compose down +TimeoutStartSec=0 +Restart=on-failure +StartLimitIntervalSec=60 +StartLimitBurst=3 + +[Install] +WantedBy=multi-user.target diff --git a/samples/httpaste.it/httpaste/config.ini b/samples/httpaste.it/httpaste/usr/local/httpaste/config.ini similarity index 100% rename from samples/httpaste.it/httpaste/config.ini rename to samples/httpaste.it/httpaste/usr/local/httpaste/config.ini diff --git a/samples/httpaste.it/httpd/httpd.conf b/samples/httpaste.it/httpd/usr/local/apache2/conf/httpd.conf similarity index 90% rename from samples/httpaste.it/httpd/httpd.conf rename to samples/httpaste.it/httpd/usr/local/apache2/conf/httpd.conf index 04b90e0..4c5ead0 100644 --- a/samples/httpaste.it/httpd/httpd.conf +++ b/samples/httpaste.it/httpd/usr/local/apache2/conf/httpd.conf @@ -61,3 +61,10 @@ ServerName 127.0.0.1 SetEnv proxy-sendchunks ProxyPass "/" "unix:/shared/uwsgi.sock|uwsgi://localhost/" + + + #ProxyPreserveHost On + ServerAlias *.onion + SetEnv proxy-sendchunks + ProxyPass "/" "unix:/shared/uwsgi.sock|uwsgi://localhost/" + diff --git a/samples/httpaste.it/tor/Dockerfile b/samples/httpaste.it/tor/Dockerfile new file mode 100644 index 0000000..cca2e04 --- /dev/null +++ b/samples/httpaste.it/tor/Dockerfile @@ -0,0 +1,10 @@ +FROM debian:bullseye-slim + +RUN apt-get update -y && apt-get install -y tor + +COPY ./usr/local/sbin/hostname.sh /usr/local/sbin/hostname +RUN chmod +x /usr/local/sbin/hostname + +USER debian-tor + +ENTRYPOINT ["tor"] \ No newline at end of file diff --git a/samples/httpaste.it/tor/etc/tor/torrc b/samples/httpaste.it/tor/etc/tor/torrc new file mode 100644 index 0000000..677f5b2 --- /dev/null +++ b/samples/httpaste.it/tor/etc/tor/torrc @@ -0,0 +1,3 @@ +DataDirectory /var/lib/tor +HiddenServiceDir /var/lib/tor/hidden_service/ +HiddenServicePort 80 httpd:80 diff --git a/samples/httpaste.it/tor/usr/local/sbin/hostname.sh b/samples/httpaste.it/tor/usr/local/sbin/hostname.sh new file mode 100755 index 0000000..ee0ff27 --- /dev/null +++ b/samples/httpaste.it/tor/usr/local/sbin/hostname.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh +prop=HiddenServiceDir +cat $(grep $prop /etc/tor/torrc | sed "s/$prop //g")/hostname \ No newline at end of file From 6ec39a9303291b5936364a1dc239a031b5881938 Mon Sep 17 00:00:00 2001 From: Tiara Rodney Date: Wed, 13 Apr 2022 12:56:30 +0200 Subject: [PATCH 2/2] refactor(Dockerfile): add build stages --- Dockerfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 27a6f0c..d64fa0e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ -FROM python:3.10-slim +FROM python:3.10-slim as base LABEL org.label-schema.schema-version="1.0" LABEL org.label-schema.vendor="Tiara Rodney (victoryk.it)" LABEL org.label-schema.name="victorykit/httpaste" LABEL org.label-schema.description="a versatile HTTP pastebin" -LABEL org.label-schema.vcs-url="https://bitbucket.org/victorykit/docker-selenium-grid" +LABEL org.label-schema.vcs-url="https://bitbucket.org/victorykit/httpaste" LABEL org.label-schema.docker.cmd="docker run {image-id} {httpaste-args}" LABEL org.label-schema.version=$BUILD_VERSION LABEL org.label-schema.build-date=$BUILD_DATE @@ -20,6 +20,11 @@ RUN apt-get update && \ python3 setup.py install && \ apt-get remove -y libffi-dev gcc && apt-get autoremove -y && apt-get clean -y +ENTRYPOINT ["httpaste"] + + +FROM base as uwsgi + ENTRYPOINT ["uwsgi", "--master", "--enable-threads", "--manage-script-name", "-w", "httpaste.wsgi:application"] CMD ["-s", "/tmp/yourapplication.sock"] \ No newline at end of file