diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e89bf3b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +data/ +.venv/ diff --git a/.gitignore b/.gitignore index 670a936..481d1cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ __pycache__/ .venv/ +data/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d3b01b5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM archlinux:latest + +ADD https://github.com/just-containers/s6-overlay/releases/download/v2.2.0.3/s6-overlay-amd64-installer /tmp + + +# Install the s6 overlay, nginx +RUN chmod +x /tmp/s6-overlay-amd64-installer && \ + /tmp/s6-overlay-amd64-installer / && \ + pacman \ + -Syu \ + --noconfirm \ + --needed \ + python python-pip nginx && \ + useradd -s /bin/false nginx && \ + mkdir /data + +ENV REPO_DIR=/data + +# Install Python app +WORKDIR /usr/src/app +COPY requirements.txt app.py ./ +RUN pip install -r requirements.txt && \ + pacman -Rs --noconfirm python-pip + +# Copy over s6 services files +COPY s6/services /etc/services.d + +# Copy over nginx config file +COPY nginx.conf /etc/nginx/nginx.conf + +# The entrypoint is the init script for s6 +ENTRYPOINT ["/init"] +CMD ["nginx"] diff --git a/Makefile b/Makefile index 28a244a..581ecd5 100644 --- a/Makefile +++ b/Makefile @@ -16,3 +16,15 @@ venv: $(VENV)/bin/activate clean: @ rm -rf '$(VENV)' .PHONY: clean + +run: + @ API_KEY=test REPO_DIR=data '$(VENV)/bin/flask' run +.PHONY: run + +gunicorn: + @ API_KEY=test REPO_DIR=data '$(VENV)/bin/gunicorn' app:app +.PHONY: gunicorn + +image: + @ docker build -t chewingbever/arch-repo . +.PHONY: image diff --git a/app.py b/app.py index 82664c0..789b8fa 100644 --- a/app.py +++ b/app.py @@ -57,7 +57,7 @@ def upload_file(): file.save(path) # Run repo-add on the file - res = subprocess.run(["repo-add", path.parent / "repo.db.tar.gz", path]) + res = subprocess.run(["repo-add", path.parent.parent / "repo.db.tar.gz", path]) if res.returncode != 0: path.unlink() diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..43be09f --- /dev/null +++ b/nginx.conf @@ -0,0 +1,42 @@ +user nginx; +worker_processes auto; +daemon off; + +error_log /var/log/nginx/error.log notice; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + + keepalive_timeout 65; + + client_max_body_size 0; + + server { + listen 80; + listen [::]:80; + + location /api { + proxy_pass http://localhost:8000/; + } + + location / { + root /data; + } + } +} diff --git a/s6/services/gunicorn/finish b/s6/services/gunicorn/finish new file mode 100644 index 0000000..b6531b3 --- /dev/null +++ b/s6/services/gunicorn/finish @@ -0,0 +1,3 @@ +#!/usr/bin/execlineb -S0 + +s6-svscanctl -t /var/run/s6/services diff --git a/s6/services/gunicorn/run b/s6/services/gunicorn/run new file mode 100644 index 0000000..d884bb1 --- /dev/null +++ b/s6/services/gunicorn/run @@ -0,0 +1,3 @@ +#!/usr/bin/with-contenv sh + +exec /usr/bin/gunicorn --chdir /usr/src/app app:app