Skip to content

Instantly share code, notes, and snippets.

@Tiebe
Last active July 24, 2023 13:34
Show Gist options
  • Save Tiebe/f247361f4c0f1292de95727950cd9862 to your computer and use it in GitHub Desktop.
Save Tiebe/f247361f4c0f1292de95727950cd9862 to your computer and use it in GitHub Desktop.
generate docker stuff
import os
from math import ceil
def generate_proxy(accounts: list[str], amount_per_ip: int) -> str:
amount = len(accounts)
docker_compose_file = f"""
version: '3.8'
services:
anonwebproxy:
init: true
ports:
- '10000-10{ceil(amount / amount_per_ip)-1 :03d}:8118'
image: dwightgunning/anonwebproxy:latest
"""
return docker_compose_file
def generate_docker_compose(accounts: list[str], amount_per_ip: int, ip: str) -> str:
amount = len(accounts)
docker_compose_file = """
version: '3.8'
services:
"""
for i in range(ceil(amount / amount_per_ip)):
docker_compose_file += f"""
henk{i}:
image: ghcr.io/tintin10q/headless-henk:latest
labels:
- "com.centurylinklabs.watchtower.scope=headless-henkies"
environment:
- HTTP_PROXY=http://{ip}:10{i :03d}
- HTTPS_PROXY=http://{ip}:10{i :03d}
- no_proxy=chief.placenl.nl
volumes:
- ./henk{i}.toml:/workdir/accounts.toml
- ./henk{i}:/cache
command: --tokens_cache=/cache/tokens_cache.toml
restart: always
"""
with open(f"henks/henk{i}.toml", 'a') as henk_file:
for j in range(amount_per_ip):
index = i * amount_per_ip + j
if index >= amount:
break
henk_file.write(accounts[index] + "\n")
henk_file.truncate(henk_file.tell() - 1)
return docker_compose_file
if __name__ == "__main__":
with open("accounts.toml", 'r') as account_file:
ApI = int(input("Hoeveel wil je er per IP draaien?")) # nee, niet API, accounts per ip :)
server_ip = input("Wat is het local IP van de server waarop ze draaien?")
accounts = account_file.read().split("\n")
if not os.path.isdir("henks"):
os.mkdir("henks")
docker_compose = generate_docker_compose(accounts, ApI, server_ip)
proxy = generate_proxy(accounts, ApI)
with open("henks/henks-compose.yml", 'a') as henk_compose:
henk_compose.write(docker_compose)
with open("henks/proxy-compose.yml", 'a') as proxy_compose:
proxy_compose.write(proxy)
print("Run het volgende commando in de map 'henks':")
print(f"docker compose -f proxy-compose.yml up -d --scale anonwebproxy={ceil(len(accounts) / ApI)} && docker compose -f henks-compose.yml up -d")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment