From df44b67d402c86975d9a19c7c33f4779e67b68fb Mon Sep 17 00:00:00 2001 From: Carlos Polop Date: Thu, 9 Jan 2025 01:18:30 +0100 Subject: [PATCH] docker --- .github/workflows/build_docker.yml | 32 +++++++++++++ .github/workflows/translate_af.yml | 73 +++++++----------------------- Dockerfile | 35 ++++++++++++++ 3 files changed, 83 insertions(+), 57 deletions(-) create mode 100644 .github/workflows/build_docker.yml create mode 100644 Dockerfile diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml new file mode 100644 index 000000000..a07da18d6 --- /dev/null +++ b/.github/workflows/build_docker.yml @@ -0,0 +1,32 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + - master + workflow_dispatch: + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + # 1. Log into GitHub Container Registry + - name: Log in to GHCR + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # 2. Build and push + - name: Build and push Docker image + run: | + # Define image name + IMAGE_NAME=ghcr.io/${{ github.repository }}/translator-image + + # Build Docker image + docker build -t $IMAGE_NAME:latest . + + # Push Docker image to GHCR + docker push $IMAGE_NAME:latest diff --git a/.github/workflows/translate_af.yml b/.github/workflows/translate_af.yml index 1d1403ac4..d189c3a85 100644 --- a/.github/workflows/translate_af.yml +++ b/.github/workflows/translate_af.yml @@ -8,6 +8,7 @@ on: - 'scripts/**' - '.gitignore' - '.github/**' + - Dockerfile workflow_dispatch: concurrency: af @@ -19,93 +20,51 @@ permissions: jobs: run-translation: runs-on: ubuntu-latest - environment: prod - env: - LANGUAGE: Afrikaans - BRANCH: af - + container: + # Use the image you pushed to GHCR + image: ghcr.io/HackTricks-wiki/hacktricks-cloud/translator-image:latest + steps: - name: Checkout code uses: actions/checkout@v2 with: - fetch-depth: 0 #Needed to download everything to be able to access the master & language branches - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.12 - - - name: Install python dependencies - run: | - python -m pip install --upgrade pip - pip3 install openai tqdm tiktoken - - # Install Rust and Cargo - - name: Install Rust and Cargo - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - # Install mdBook and Plugins - - name: Install mdBook and Plugins - run: | - cargo install mdbook - cargo install mdbook-alerts - cargo install mdbook-reading-time - cargo install mdbook-pagetoc - cargo install mdbook-tabs - cargo install mdbook-codename - + fetch-depth: 0 - - name: Update & install wget & translator.py + - name: Update & install translator.py (if needed) run: | - sudo apt-get update - sudo apt-get install wget -y cd scripts rm -f translator.py wget https://raw.githubusercontent.com/carlospolop/hacktricks-cloud/master/scripts/translator.py cd .. - - - name: Download language branch #Make sure we have last version + + - name: Download language branch run: | git config --global user.name 'Translator' git config --global user.email 'github-actions@github.com' - git checkout "$BRANCH" + git checkout af git pull git checkout master - name: Run translation script on changed files run: | - echo "Starting translations" - echo "Commit: $GITHUB_SHA" - - # Export the OpenAI API key as an environment variable export OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} - - # Run the translation script on each changed file git diff --name-only HEAD~1 | grep -v "SUMMARY.md" | while read -r file; do if echo "$file" | grep -qE '\.md$'; then echo -n "$file , " >> /tmp/file_paths.txt - else - echo "Skipping $file" fi done + python scripts/translator.py --language "Afrikaans" --branch "af" --api-key "$OPENAI_API_KEY" -f "$(cat /tmp/file_paths.txt)" -t 3 - echo "Translating $(cat /tmp/file_paths.txt)" - python scripts/translator.py --language "$LANGUAGE" --branch "$BRANCH" --api-key "$OPENAI_API_KEY" -f "$(cat /tmp/file_paths.txt)" -t 3 - - # Push changes to the repository - name: Commit and push changes run: | - git checkout "$BRANCH" + git checkout af git add -A - git commit -m "Translated $BRANCH files" || true - git push --set-upstream origin "$BRANCH" + git commit -m "Translated Afrikaans files" || true + git push --set-upstream origin af - # Build the mdBook - name: Build mdBook - run: MDBOOK_BOOK__LANGUAGE=$BRANCH mdbook build || (cat hacktricks-preprocessor-error.log && exit 1) + run: | + MDBOOK_BOOK__LANGUAGE=af mdbook build || (cat hacktricks-preprocessor-error.log && exit 1) # Login in AWs - name: Configure AWS credentials using OIDC diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..50b95bde9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +# Dockerfile +FROM ubuntu:22.04 + +# Install system dependencies +RUN apt-get update && \ + apt-get install -y \ + curl \ + wget \ + git \ + sudo \ + python3.12 \ + python3-pip \ + build-essential \ + && \ + rm -rf /var/lib/apt/lists/* + +# Upgrade pip +RUN pip3 install --upgrade pip + +# Install Python dependencies +RUN pip3 install openai tqdm tiktoken + +# Install Rust & Cargo +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y +ENV PATH="/root/.cargo/bin:${PATH}" + +# Install mdBook & plugins +RUN cargo install mdbook +RUN cargo install mdbook-alerts +RUN cargo install mdbook-reading-time +RUN cargo install mdbook-pagetoc +RUN cargo install mdbook-tabs +RUN cargo install mdbook-codename + +WORKDIR /app