Merge pull request #243 from caryoscelus/docker-update

Docker update & minor improvements
This commit is contained in:
caryoscelus 2023-11-23 19:02:28 +00:00 committed by GitHub
commit 28440346b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 139 additions and 84 deletions

View file

@ -1,3 +1,5 @@
venv venv
Dockerfile* docker
data data
__pycahce__
log

1
.gitignore vendored
View file

@ -19,6 +19,7 @@ __pycache__/
# Data dir # Data dir
data/* data/*
docker/data/
*.db *.db
# Virtualenv # Virtualenv

View file

@ -1,17 +0,0 @@
FROM python:3.10.4-alpine
RUN apk --update --no-cache --no-progress add gcc libffi-dev musl-dev make openssl g++
WORKDIR /app
COPY . .
RUN python3 -m venv venv \
&& source venv/bin/activate \
&& python3 -m pip install -r requirements.txt
CMD source venv/bin/activate \
&& python3 zeronet.py --ui_ip "*" --fileserver_port 26552 \
--tor $TOR_ENABLED --tor_controller tor:$TOR_CONTROL_PORT \
--tor_proxy tor:$TOR_SOCKS_PORT --tor_password $TOR_CONTROL_PASSWD main
EXPOSE 43110 26552

View file

@ -1,18 +0,0 @@
FROM python:3.10.4-alpine
RUN apk --update --no-cache --no-progress add tor gcc libffi-dev musl-dev make openssl g++ \
&& echo "ControlPort 9051" >> /etc/tor/torrc \
&& echo "CookieAuthentication 1" >> /etc/tor/torrc
WORKDIR /app
COPY . .
RUN python3 -m venv venv \
&& source venv/bin/activate \
&& python3 -m pip install -r requirements.txt
CMD (tor&) \
&& source venv/bin/activate \
&& python3 zeronet.py --ui_ip "*" --fileserver_port 26552
EXPOSE 43110 26552

View file

@ -1,10 +0,0 @@
FROM alpine:3.16.0
RUN apk --update --no-cache --no-progress add tor
CMD hashed_control_password=$(tor --quiet --hash-password $TOR_CONTROL_PASSWD) \
&& tor --SocksPort 0.0.0.0:$TOR_SOCKS_PORT \
--ControlPort 0.0.0.0:$TOR_CONTROL_PORT \
--HashedControlPassword $hashed_control_password
EXPOSE $TOR_SOCKS_PORT $TOR_CONTROL_PORT

View file

@ -97,7 +97,7 @@ Install autoconf and other basic development tools, python3 and pip, then procee
##### Apt-based (debian, ubuntu, etc) ##### Apt-based (debian, ubuntu, etc)
- `sudo apt update` - `sudo apt update`
- `sudo apt install pkg-config libffi-dev python3-pip python3-venv python3-dev build-essential` - `sudo apt install git pkg-config libffi-dev python3-pip python3-venv python3-dev build-essential libtool`
##### Red Hat and Fedora based ##### Red Hat and Fedora based
- `yum install epel-release -y 2>/dev/null` - `yum install epel-release -y 2>/dev/null`

25
docker/Dockerfile Normal file
View file

@ -0,0 +1,25 @@
FROM python:3.12-alpine
RUN apk --update --no-cache --no-progress add git gcc libffi-dev musl-dev make openssl g++ autoconf automake libtool
RUN adduser -u 1600 -D service-0net
USER service-0net:service-0net
WORKDIR /home/service-0net
COPY requirements.txt .
RUN python3 -m pip install -r requirements.txt
# the part below is updated with source updates
COPY . .
ENTRYPOINT python3 zeronet.py --ui_ip "*" --fileserver_port 26552 \
--tor $TOR_ENABLED --tor_controller tor:$TOR_CONTROL_PORT \
--tor_proxy tor:$TOR_SOCKS_PORT --tor_password $TOR_CONTROL_PASSWD
CMD main
EXPOSE 43110 26552

26
docker/debian.Dockerfile Normal file
View file

@ -0,0 +1,26 @@
FROM python:3.12-slim-bookworm
RUN apt-get update
RUN apt-get -y install git openssl pkg-config libffi-dev python3-pip python3-dev build-essential libtool
RUN useradd -u 1600 -m service-0net
USER service-0net:service-0net
WORKDIR /home/service-0net
COPY requirements.txt .
RUN python3 -m pip install -r requirements.txt
# the part below is updated with source updates
COPY . .
ENTRYPOINT python3 zeronet.py --ui_ip "*" --fileserver_port 26552 \
--tor $TOR_ENABLED --tor_controller tor:$TOR_CONTROL_PORT \
--tor_proxy tor:$TOR_SOCKS_PORT --tor_password $TOR_CONTROL_PASSWD
CMD main
EXPOSE 43110 26552

View file

@ -1,51 +1,55 @@
version: '3' version: '3'
services: services:
tor: tor:
tty: true tty: true
stdin_open: true stdin_open: true
build: build:
context: . context: ..
dockerfile: Dockerfile.tor dockerfile: docker/tor.Dockerfile
networks: networks:
- 0net-network - 0net-network
ports:
- "9050:9050"
- "9051:9051"
environment: &tor-environments environment: &tor-environments
# since we are using tor internally, password doesn't really matter
TOR_CONTROL_PASSWD: some_password TOR_CONTROL_PASSWD: some_password
TOR_SOCKS_PORT: 9050 TOR_SOCKS_PORT: 9050
TOR_CONTROL_PORT: 9051 TOR_CONTROL_PORT: 9051
0net:
0net-conservancy:
tty: true tty: true
stdin_open: true stdin_open: true
build: build:
context: . context: ..
dockerfile: docker/Dockerfile
networks: networks:
- 0net-network - 0net-network
volumes: volumes:
- 0net-data:/app/data # NOTE: this refers to docker/data..
- ./data:/home/service-0net/data
ports: ports:
- "26552:26552" - "26552:26552"
- "43110:43110" - "127.0.0.1:43110:43110"
depends_on: depends_on:
- tor - tor
environment: environment:
TOR_ENABLED: enable TOR_ENABLED: enable
<<: *tor-environments <<: *tor-environments
# integrated container with tor
0net-tor: 0net-tor:
tty: true tty: true
stdin_open: true stdin_open: true
build: build:
context: . context: ..
dockerfile: Dockerfile.integrated_tor dockerfile: docker/znctor.Dockerfile
networks: networks:
- 0net-network - 0net-network
volumes: volumes:
- 0net-data:/app/data # NOTE: this refers to docker/data..
- ./data:/home/service-0net/data
ports: ports:
- "26552:26552" - "26552:26552"
- "43110:43110" - "127.0.0.1:43110:43110"
volumes:
0net-data:
networks: networks:
0net-network: 0net-network:

9
docker/tor.Dockerfile Normal file
View file

@ -0,0 +1,9 @@
FROM alpine:3.18
RUN apk --update --no-cache --no-progress add tor
USER tor
CMD tor --SocksPort 0.0.0.0:${TOR_SOCKS_PORT} --ControlPort 0.0.0.0:${TOR_CONTROL_PORT} --HashedControlPassword $(tor --quiet --hash-password $TOR_CONTROL_PASSWD)
EXPOSE $TOR_SOCKS_PORT $TOR_CONTROL_PORT

31
docker/znctor.Dockerfile Normal file
View file

@ -0,0 +1,31 @@
FROM python:3.12-alpine
RUN apk --update --no-cache --no-progress add git gcc libffi-dev musl-dev make openssl g++ autoconf automake libtool
RUN apk add tor
RUN echo "ControlPort 9051" >> /etc/tor/torrc
RUN echo "CookieAuthentication 1" >> /etc/tor/torrc
RUN adduser -u 1600 -D service-0net
USER service-0net:service-0net
WORKDIR /home/service-0net
COPY requirements.txt .
RUN python3 -m pip install -r requirements.txt
RUN echo "tor &" > start.sh
RUN echo "python3 zeronet.py --ui_ip '*' --fileserver_port 26552" >> start.sh
RUN chmod +x start.sh
# the part below is updated with source updates
COPY . .
ENTRYPOINT ./start.sh
CMD main
EXPOSE 43110 26552

View file

@ -18,7 +18,7 @@ def grad(n):
def fancy_greet(version): def fancy_greet(version):
from rich.console import Console from rich.console import Console
from rich.text import Text from rich.text import Text
zc_msg = f''' zc_msg = fr'''
||| . . _ _._|_ _. . . _ .__ _.. _. . __.. _ __. . ||| . . _ _._|_ _. . . _ .__ _.. _. . __.. _ __. .
||| //\|/ |/_| | == / / \|/ |( /_||/ | | __||/ |/ \_| ||| //\|/ |/_| | == / / \|/ |( /_||/ | | __||/ |/ \_|
||| \_/| |\_ |. \__\_/| |_) \_ | \/ |__|| |\__ _/ ||| \_/| |\_ |. \__\_/| |_) \_ | \/ |__|| |\__ _/

View file

@ -45,7 +45,7 @@ class UiRequestPlugin(object):
file_obj = None file_obj = None
path_parts = self.parsePath(path) path_parts = self.parsePath(path)
file_path = "%s/%s/%s" % (config.data_dir, path_parts["address"], path_parts["inner_path"]) file_path = "%s/%s/%s" % (config.data_dir, path_parts["address"], path_parts["inner_path"])
match = re.match("^(.*\.(?:tar.gz|zip))/(.*)", file_path) match = re.match(r"^(.*\.(?:tar.gz|zip))/(.*)", file_path)
archive_path, path_within = match.groups() archive_path, path_within = match.groups()
if archive_path not in archive_cache: if archive_path not in archive_cache:
site = self.server.site_manager.get(path_parts["address"]) site = self.server.site_manager.get(path_parts["address"])
@ -99,7 +99,7 @@ class UiRequestPlugin(object):
class SiteStoragePlugin(object): class SiteStoragePlugin(object):
def isFile(self, inner_path): def isFile(self, inner_path):
if ".zip/" in inner_path or ".tar.gz/" in inner_path: if ".zip/" in inner_path or ".tar.gz/" in inner_path:
match = re.match("^(.*\.(?:tar.gz|zip))/(.*)", inner_path) match = re.match(r"^(.*\.(?:tar.gz|zip))/(.*)", inner_path)
archive_inner_path, path_within = match.groups() archive_inner_path, path_within = match.groups()
return super(SiteStoragePlugin, self).isFile(archive_inner_path) return super(SiteStoragePlugin, self).isFile(archive_inner_path)
else: else:
@ -127,7 +127,7 @@ class SiteStoragePlugin(object):
def walk(self, inner_path, *args, **kwags): def walk(self, inner_path, *args, **kwags):
if ".zip" in inner_path or ".tar.gz" in inner_path: if ".zip" in inner_path or ".tar.gz" in inner_path:
match = re.match("^(.*\.(?:tar.gz|zip))(.*)", inner_path) match = re.match(r"^(.*\.(?:tar.gz|zip))(.*)", inner_path)
archive_inner_path, path_within = match.groups() archive_inner_path, path_within = match.groups()
archive = self.openArchive(archive_inner_path) archive = self.openArchive(archive_inner_path)
path_within = path_within.lstrip("/") path_within = path_within.lstrip("/")
@ -151,7 +151,7 @@ class SiteStoragePlugin(object):
def list(self, inner_path, *args, **kwags): def list(self, inner_path, *args, **kwags):
if ".zip" in inner_path or ".tar.gz" in inner_path: if ".zip" in inner_path or ".tar.gz" in inner_path:
match = re.match("^(.*\.(?:tar.gz|zip))(.*)", inner_path) match = re.match(r"^(.*\.(?:tar.gz|zip))(.*)", inner_path)
archive_inner_path, path_within = match.groups() archive_inner_path, path_within = match.groups()
archive = self.openArchive(archive_inner_path) archive = self.openArchive(archive_inner_path)
path_within = path_within.lstrip("/") path_within = path_within.lstrip("/")
@ -178,7 +178,7 @@ class SiteStoragePlugin(object):
def read(self, inner_path, mode="rb", **kwargs): def read(self, inner_path, mode="rb", **kwargs):
if ".zip/" in inner_path or ".tar.gz/" in inner_path: if ".zip/" in inner_path or ".tar.gz/" in inner_path:
match = re.match("^(.*\.(?:tar.gz|zip))(.*)", inner_path) match = re.match(r"^(.*\.(?:tar.gz|zip))(.*)", inner_path)
archive_inner_path, path_within = match.groups() archive_inner_path, path_within = match.groups()
archive = self.openArchive(archive_inner_path) archive = self.openArchive(archive_inner_path)
path_within = path_within.lstrip("/") path_within = path_within.lstrip("/")

View file

@ -64,7 +64,7 @@ def pow2(x, p):
def inv(z): def inv(z):
"""$= z^{-1} \mod q$, for z != 0""" r"""$= z^{-1} \mod q$, for z != 0"""
# Adapted from curve25519_athlon.c in djb's Curve25519. # Adapted from curve25519_athlon.c in djb's Curve25519.
z2 = z * z % q # 2 z2 = z * z % q # 2
z9 = pow2(z2, 2) * z % q # 9 z9 = pow2(z2, 2) * z % q # 9

View file

@ -74,28 +74,30 @@ def importBundle(bundle):
def init_dirs(): def init_dirs():
data_dir = config.data_dir data_dir = config.data_dir
if not os.path.isdir(data_dir): has_data_dir = os.path.isdir(data_dir)
need_bootstrap = not config.disable_bootstrap and (not has_data_dir or not os.path.isfile(f'{data_dir}/sites.json')) and not config.offline
if not has_data_dir:
os.mkdir(data_dir) os.mkdir(data_dir)
try: try:
os.chmod(data_dir, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) os.chmod(data_dir, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
except Exception as err: except Exception as err:
startupError(f"Can't change permission of {data_dir}: {err}") startupError(f"Can't change permission of {data_dir}: {err}")
# download latest bootstrap bundle if need_bootstrap:
if not config.disable_bootstrap and not config.offline: import requests
import requests from io import BytesIO
from io import BytesIO
print(f'fetching {config.bootstrap_url}') print(f'fetching {config.bootstrap_url}')
response = requests.get(config.bootstrap_url) response = requests.get(config.bootstrap_url)
if response.status_code != 200: if response.status_code != 200:
startupError(f"Cannot load bootstrap bundle (response status: {response.status_code})") startupError(f"Cannot load bootstrap bundle (response status: {response.status_code})")
url = response.text url = response.text
print(f'got {url}') print(f'got {url}')
response = requests.get(url) response = requests.get(url)
if response.status_code < 200 or response.status_code >= 300: if response.status_code < 200 or response.status_code >= 300:
startupError(f"Cannot load boostrap bundle (response status: {response.status_code})") startupError(f"Cannot load boostrap bundle (response status: {response.status_code})")
importBundle(BytesIO(response.content)) importBundle(BytesIO(response.content))
sites_json = f"{data_dir}/sites.json" sites_json = f"{data_dir}/sites.json"
if not os.path.isfile(sites_json): if not os.path.isfile(sites_json):