Skip to content

Commit df44b67

Browse files
committed
docker
1 parent 41c85ce commit df44b67

File tree

3 files changed

+83
-57
lines changed

3 files changed

+83
-57
lines changed

.github/workflows/build_docker.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
workflow_dispatch:
9+
10+
jobs:
11+
build-and-push:
12+
runs-on: ubuntu-latest
13+
steps:
14+
# 1. Log into GitHub Container Registry
15+
- name: Log in to GHCR
16+
uses: docker/login-action@v2
17+
with:
18+
registry: ghcr.io
19+
username: ${{ github.actor }}
20+
password: ${{ secrets.GITHUB_TOKEN }}
21+
22+
# 2. Build and push
23+
- name: Build and push Docker image
24+
run: |
25+
# Define image name
26+
IMAGE_NAME=ghcr.io/${{ github.repository }}/translator-image
27+
28+
# Build Docker image
29+
docker build -t $IMAGE_NAME:latest .
30+
31+
# Push Docker image to GHCR
32+
docker push $IMAGE_NAME:latest

.github/workflows/translate_af.yml

Lines changed: 16 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
- 'scripts/**'
99
- '.gitignore'
1010
- '.github/**'
11+
- Dockerfile
1112
workflow_dispatch:
1213

1314
concurrency: af
@@ -19,93 +20,51 @@ permissions:
1920
jobs:
2021
run-translation:
2122
runs-on: ubuntu-latest
22-
environment: prod
23-
env:
24-
LANGUAGE: Afrikaans
25-
BRANCH: af
26-
23+
container:
24+
# Use the image you pushed to GHCR
25+
image: ghcr.io/HackTricks-wiki/hacktricks-cloud/translator-image:latest
26+
2727
steps:
2828
- name: Checkout code
2929
uses: actions/checkout@v2
3030
with:
31-
fetch-depth: 0 #Needed to download everything to be able to access the master & language branches
32-
33-
- name: Set up Python
34-
uses: actions/setup-python@v2
35-
with:
36-
python-version: 3.12
37-
38-
- name: Install python dependencies
39-
run: |
40-
python -m pip install --upgrade pip
41-
pip3 install openai tqdm tiktoken
42-
43-
# Install Rust and Cargo
44-
- name: Install Rust and Cargo
45-
uses: actions-rs/toolchain@v1
46-
with:
47-
toolchain: stable
48-
override: true
49-
50-
# Install mdBook and Plugins
51-
- name: Install mdBook and Plugins
52-
run: |
53-
cargo install mdbook
54-
cargo install mdbook-alerts
55-
cargo install mdbook-reading-time
56-
cargo install mdbook-pagetoc
57-
cargo install mdbook-tabs
58-
cargo install mdbook-codename
59-
31+
fetch-depth: 0
6032

61-
- name: Update & install wget & translator.py
33+
- name: Update & install translator.py (if needed)
6234
run: |
63-
sudo apt-get update
64-
sudo apt-get install wget -y
6535
cd scripts
6636
rm -f translator.py
6737
wget https://raw.githubusercontent.com/carlospolop/hacktricks-cloud/master/scripts/translator.py
6838
cd ..
69-
70-
- name: Download language branch #Make sure we have last version
39+
40+
- name: Download language branch
7141
run: |
7242
git config --global user.name 'Translator'
7343
git config --global user.email '[email protected]'
74-
git checkout "$BRANCH"
44+
git checkout af
7545
git pull
7646
git checkout master
7747
7848
- name: Run translation script on changed files
7949
run: |
80-
echo "Starting translations"
81-
echo "Commit: $GITHUB_SHA"
82-
83-
# Export the OpenAI API key as an environment variable
8450
export OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}
85-
86-
# Run the translation script on each changed file
8751
git diff --name-only HEAD~1 | grep -v "SUMMARY.md" | while read -r file; do
8852
if echo "$file" | grep -qE '\.md$'; then
8953
echo -n "$file , " >> /tmp/file_paths.txt
90-
else
91-
echo "Skipping $file"
9254
fi
9355
done
56+
python scripts/translator.py --language "Afrikaans" --branch "af" --api-key "$OPENAI_API_KEY" -f "$(cat /tmp/file_paths.txt)" -t 3
9457
95-
echo "Translating $(cat /tmp/file_paths.txt)"
96-
python scripts/translator.py --language "$LANGUAGE" --branch "$BRANCH" --api-key "$OPENAI_API_KEY" -f "$(cat /tmp/file_paths.txt)" -t 3
97-
98-
# Push changes to the repository
9958
- name: Commit and push changes
10059
run: |
101-
git checkout "$BRANCH"
60+
git checkout af
10261
git add -A
103-
git commit -m "Translated $BRANCH files" || true
104-
git push --set-upstream origin "$BRANCH"
62+
git commit -m "Translated Afrikaans files" || true
63+
git push --set-upstream origin af
10564
106-
# Build the mdBook
10765
- name: Build mdBook
108-
run: MDBOOK_BOOK__LANGUAGE=$BRANCH mdbook build || (cat hacktricks-preprocessor-error.log && exit 1)
66+
run: |
67+
MDBOOK_BOOK__LANGUAGE=af mdbook build || (cat hacktricks-preprocessor-error.log && exit 1)
10968
11069
# Login in AWs
11170
- name: Configure AWS credentials using OIDC

Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Dockerfile
2+
FROM ubuntu:22.04
3+
4+
# Install system dependencies
5+
RUN apt-get update && \
6+
apt-get install -y \
7+
curl \
8+
wget \
9+
git \
10+
sudo \
11+
python3.12 \
12+
python3-pip \
13+
build-essential \
14+
&& \
15+
rm -rf /var/lib/apt/lists/*
16+
17+
# Upgrade pip
18+
RUN pip3 install --upgrade pip
19+
20+
# Install Python dependencies
21+
RUN pip3 install openai tqdm tiktoken
22+
23+
# Install Rust & Cargo
24+
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
25+
ENV PATH="/root/.cargo/bin:${PATH}"
26+
27+
# Install mdBook & plugins
28+
RUN cargo install mdbook
29+
RUN cargo install mdbook-alerts
30+
RUN cargo install mdbook-reading-time
31+
RUN cargo install mdbook-pagetoc
32+
RUN cargo install mdbook-tabs
33+
RUN cargo install mdbook-codename
34+
35+
WORKDIR /app

0 commit comments

Comments
 (0)