From b3b264e91c12157da1f679ce65dffd34d4279b2a Mon Sep 17 00:00:00 2001 From: Yurii Kovalchuk <103324562+yumirkov@users.noreply.github.com> Date: Wed, 7 Aug 2024 10:46:37 +0300 Subject: [PATCH] ATOR-380 - Onion perf nginx (#6) --- .github/actions/build-and-push/action.yml | 4 +- .github/workflows/live.yml | 14 ++-- Dockerfile | 41 ++++------- docker-compose.yml | 7 ++ docker-entrypoint.sh | 11 --- operations/deploy-live.hcl | 84 +++++++++++++++++++++-- 6 files changed, 106 insertions(+), 55 deletions(-) create mode 100644 docker-compose.yml delete mode 100644 docker-entrypoint.sh diff --git a/.github/actions/build-and-push/action.yml b/.github/actions/build-and-push/action.yml index 3e7f0da..75c786d 100644 --- a/.github/actions/build-and-push/action.yml +++ b/.github/actions/build-and-push/action.yml @@ -24,6 +24,4 @@ runs: context: . file: ./Dockerfile push: true - tags: ${{ inputs.docker-username }}/onionperf-anon:${{ github.sha }},${{ inputs.docker-username }}/onionperf-anon:${{ inputs.docker-tag }} - build-args: | - ANON_ENV=${{ inputs.environment }} \ No newline at end of file + tags: ${{ inputs.docker-username }}/onionperf-anon:${{ github.sha }},${{ inputs.docker-username }}/onionperf-anon:${{ inputs.docker-tag }} \ No newline at end of file diff --git a/.github/workflows/live.yml b/.github/workflows/live.yml index 1ebcc9a..3cffcf9 100644 --- a/.github/workflows/live.yml +++ b/.github/workflows/live.yml @@ -20,10 +20,10 @@ jobs: docker-password: ${{ secrets.DOCKER_HUB_PASSWORD }} docker-tag: latest-live environment: live -# - name: Deploy -# uses: ./.github/actions/deploy -# with: -# environment: dev -# nomad-cacert: operations/admin-ui-ca.crt -# nomad-token: ${{ secrets.NOMAD_TOKEN_SBWS_DEPLOY }} #add deploy token -# nomad-addr: ${{ secrets.NOMAD_DEPLOY_ADDR }} + - name: Deploy + uses: ./.github/actions/deploy + with: + environment: live + nomad-cacert: operations/admin-ui-ca.crt + nomad-token: ${{ secrets.NOMAD_TOKEN_ONIONPERF_DEPLOY }} + nomad-addr: ${{ secrets.NOMAD_ADDR }} diff --git a/Dockerfile b/Dockerfile index 61ef16c..b618af7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,13 +3,11 @@ FROM debian:bookworm ARG DEBIAN_FRONTEND=noninteractive -ARG ANON_ENV=live +WORKDIR /home/onionperf # Install system dependencies RUN apt-get update && apt-get install -y \ - cron \ automake \ - wget \ build-essential \ cmake \ git \ @@ -23,15 +21,14 @@ RUN apt-get update && apt-get install -y \ software-properties-common \ && rm -rf /var/lib/apt/lists/* -WORKDIR /home/onionperf - -# Clone and build Anon -RUN git clone https://github.com/ATOR-Development/ator-protocol.git \ - && cd ator-protocol \ - && ./scripts/ci/update-env.sh ${ANON_ENV} \ - && ./autogen.sh \ - && ./configure --disable-asciidoc \ - && make +RUN apt-get -y update \ + && echo "anon anon/terms boolean true" | debconf-set-selections \ + && apt-get -y install wget apt-transport-https \ + && . /etc/os-release \ + && wget -qO- https://deb.dmz.ator.dev/anon.asc | tee /etc/apt/trusted.gpg.d/anon.asc \ + && echo "deb [signed-by=/etc/apt/trusted.gpg.d/anon.asc] https://deb.dmz.ator.dev anon-live-$VERSION_CODENAME main" > /etc/apt/sources.list.d/anon.list \ + && apt-get -y update \ + && apt-get -y install anon # Clone and build TGen RUN git clone https://github.com/shadow/tgen.git \ @@ -50,25 +47,11 @@ COPY . onionperf RUN cd onionperf \ && pip install --no-cache-dir -r requirements.txt \ - && python setup.py install - -# Set environment variables and working directory -ENV TOR_PATH="/home/onionperf/ator-protocol/src/app/anon" -ENV TGEN_PATH="/home/onionperf/tgen/build/src/tgen" -WORKDIR /home/onionperf + && python setup.py install \ + && cd .. && rm -rf onionperf # Expose Listen and Connect Ports EXPOSE 9510 9520 -# Mount /home/onionperf/results folder to store the results -RUN mkdir /home/onionperf/results -VOLUME /home/onionperf/results - -# Add crontab to prepare the cron configuration -ADD crontab.txt /home/onionperf/crontab.txt -RUN crontab /home/onionperf/crontab.txt - -COPY docker-entrypoint.sh /home/onionperf/ - # Start OnionPerf when the container runs -ENTRYPOINT [ "sh", "./docker-entrypoint.sh" ] \ No newline at end of file +CMD [ "onionperf", "measure", "--tgen", "/home/onionperf/tgen/build/src/tgen", "--tor", "/usr/sbin/anon", "--tgen-listen-port", "9510", "--tgen-connect-port", "9520" ] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..9d80d60 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +version: '3' +services: + onionperf: + image: onionperf + restart: always + volumes: + - ./onionperf-data/:/home/onionperf/onionperf-data/ diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh deleted file mode 100644 index 468d374..0000000 --- a/docker-entrypoint.sh +++ /dev/null @@ -1,11 +0,0 @@ -cd /home/onionperf - -touch /home/onionperf/measure.log -touch /home/onionperf/analyze.log - -crontab -l | { cat; echo "55 2 * * * pkill -INT onionperf 2>&1"; } | crontab - -crontab -l | { cat; echo "56 2 * * * mkdir -p /home/onionperf/results/\$(date +\%Y-\%m-\%d) && /home/onionperf/venv/bin/onionperf analyze --tgen /root/onionperf-data/tgen-client/onionperf.tgen.log --torctl /root/onionperf-data/tor-client/onionperf.torctl.log -p /home/onionperf/results/\$(date +\%Y-\%m-\%d) >> /home/onionperf/analyze.log 2>&1"; } | crontab - -crontab -l | { cat; echo "0 3 * * * /home/onionperf/venv/bin/onionperf measure --tgen /home/onionperf/tgen/build/src/tgen --tor /home/onionperf/ator-protocol/src/app/anon --tgen-listen-port 9510 --tgen-connect-port 9520 >> /home/onionperf/measure.log 2>&1"; } | crontab - - -service cron start -tail -f /home/onionperf/measure.log \ No newline at end of file diff --git a/operations/deploy-live.hcl b/operations/deploy-live.hcl index e498481..b5245c9 100644 --- a/operations/deploy-live.hcl +++ b/operations/deploy-live.hcl @@ -6,7 +6,7 @@ job "onionperf-anon-live" { group "onionperf-anon-live-group" { count = 3 - volume "onionperf-results" { + volume "onionperf-data" { type = "host" read_only = false source = "onionperf-live" @@ -37,14 +37,19 @@ job "onionperf-anon-live" { port "listen-port" { static = 9510 } + + port "http-port" { + static = 9222 + to = 80 + } } task "onionperf-anon-live-task" { driver = "docker" volume_mount { - volume = "onionperf-results" - destination = "/home/onionperf/results" + volume = "onionperf-data" + destination = "/home/onionperf/onionperf-data" read_only = false } @@ -59,8 +64,77 @@ job "onionperf-anon-live" { } resources { - cpu = 512 - memory = 512 + cpu = 256 + memory = 256 + } + } + + task "onionperf-nginx-live-task" { + driver = "docker" + + volume_mount { + volume = "onionperf-data" + destination = "/var/www/onionperf-data" + read_only = true + } + + config { + image = "nginx" + volumes = [ + "local/nginx-onionperf:/etc/nginx/conf.d/default.conf:ro" + ] + ports = ["http-port"] + } + + resources { + cpu = 64 + memory = 64 + } + + service { + name = "onionperf-live" + tags = ["onionperf", "logging"] + port = "http-port" + check { + name = "onionperf nginx http server alive" + type = "tcp" + interval = "10s" + timeout = "10s" + check_restart { + limit = 10 + grace = "30s" + } + } + } + + template { + change_mode = "noop" + data = <