diff --git a/.github/workflows/build-and-publish-docker-image.yml b/.github/workflows/build-and-publish-docker-image.yml index ea0f4cd..8b92073 100644 --- a/.github/workflows/build-and-publish-docker-image.yml +++ b/.github/workflows/build-and-publish-docker-image.yml @@ -51,6 +51,8 @@ jobs: context: . target: cwa-bd push: true + build-args: | + BUILD_VERSION=$(date +'%Y%m%d')-${{ github.sha }} tags: ${{ steps.meta-main.outputs.tags }} labels: ${{ steps.meta-main.outputs.labels }} @@ -82,6 +84,8 @@ jobs: context: . target: cwa-bd-tor push: true + build-args: | + BUILD_VERSION=$(date +'%Y%m%d')-${{ github.sha }} tags: ${{ steps.meta-tor.outputs.tags }} labels: ${{ steps.meta-tor.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index a448fdd..5262682 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,10 @@ # Use python-slim as the base image FROM python:3.10-slim AS base +# Add build argument for version +ARG BUILD_VERSION +ENV BUILD_VERSION=${BUILD_VERSION} + # Set shell to bash with pipefail option SHELL ["/bin/bash", "-o", "pipefail", "-c"] @@ -107,7 +111,7 @@ CMD ["/app/entrypoint.sh"] FROM base AS cwa-bd-tor -ENV ENABLE_TOR=true +ENV USING_TOR=true # Install Tor and dependencies RUN apt-get update && \ @@ -119,8 +123,5 @@ RUN apt-get update && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* -# Tor configuration is handled by entrypoint/script now or permissions set earlier -# RUN chmod +x /app/tor.sh # This is removed as it's done in the base stage setup - # Override the default command to run Tor CMD ["/app/tor.sh"] diff --git a/docker-compose.tor.yml b/docker-compose.tor.yml index 1645541..518aa2d 100644 --- a/docker-compose.tor.yml +++ b/docker-compose.tor.yml @@ -7,8 +7,8 @@ services: BOOK_LANGUAGE: en USE_BOOK_TITLE: true FLASK_DEBUG: false - ENABLE_TOR: true TZ: America/New_York + USING_TOR: true APP_ENV: prod cap_add: - NET_ADMIN diff --git a/entrypoint.sh b/entrypoint.sh index 1f71e09..4763400 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -9,6 +9,9 @@ echo "Starting entrypoint script" echo "Log file: $LOG_FILE" set -e +# Print build version +echo "Build version: $BUILD_VERSION" + # Configure timezone if [ "$TZ" ]; then echo "Setting timezone to $TZ" diff --git a/testing/E2E_test.py b/testing/E2E_test.py index 281e228..c3336a5 100644 --- a/testing/E2E_test.py +++ b/testing/E2E_test.py @@ -139,11 +139,3 @@ assert expected_sha256 == downloaded_sha256, f"Downloaded file SHA256 mismatch. print(f"Downloaded file SHA256 matches expected: {expected_sha256}") print("--- E2E Test Completed Successfully ---") - - - - - - - - diff --git a/tor.sh b/tor.sh index 4d16ab7..fbad4c0 100644 --- a/tor.sh +++ b/tor.sh @@ -1,5 +1,18 @@ #!/bin/bash +LOG_DIR=${LOG_ROOT:-/var/log/}/cwa-book-downloader +mkdir -p $LOG_DIR +LOG_FILE=${LOG_DIR}/cwa-bd_tor.log + +exec 3>&1 4>&2 +exec > >(tee -a $LOG_FILE) 2>&1 +echo "Starting tor script" +echo "Log file: $LOG_FILE" + +set +x set -e + +echo "Build version: $BUILD_VERSION" + echo "[*] Installing Tor and dependencies..." echo "[*] Writing Tor transparent proxy config..." @@ -55,6 +68,7 @@ timeout 300 bash -c ' echo "[✓] Tor is ready." +sleep 5 # Check if outgoing IP is using Tor echo "[*] Verifying Tor connectivity..." RESULT=$(pyrequests https://check.torproject.org/api/ip) @@ -73,10 +87,11 @@ fi # Then set the timezone # Get timezone from IP -TIMEZONE=$(pyrequests https://ipapi.co/timezone) || -TIMEZONE=$(pyrequests http://ip-api.com/line?fields=timezone) || -TIMEZONE=$(pyrequests http://worldtimeapi.org/api/ip | grep -oP '"timezone":"\K[^"]+') || -TIMEZONE=$(pyrequests https://ip2tz.isthe.link/v2 | grep -oP '"timezone": *"\K[^"]+') || +sleep 1 +TIMEZONE=$(pyrequests https://ipapi.co/timezone) || \ +TIMEZONE=$(pyrequests http://ip-api.com/line?fields=timezone) || \ +TIMEZONE=$(pyrequests http://worldtimeapi.org/api/ip | grep -oP '"timezone":"\K[^"]+') || \ +TIMEZONE=$(pyrequests https://ip2tz.isthe.link/v2 | grep -oP '"timezone": *"\K[^"]+') || \ true # If TIMEZONE is not set, use the default timezone