First prototype of Dockerfile

main
Jef Roosens 2021-12-30 22:28:24 +01:00
parent 26b2745e9b
commit 63af040a38
Signed by: Jef Roosens
GPG Key ID: 955C0660072F691F
8 changed files with 97 additions and 1 deletions

2
.dockerignore 100644
View File

@ -0,0 +1,2 @@
data/
.venv/

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
__pycache__/
.venv/
data/

33
Dockerfile 100644
View File

@ -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"]

View File

@ -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

2
app.py
View File

@ -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()

42
nginx.conf 100644
View File

@ -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;
}
}
}

View File

@ -0,0 +1,3 @@
#!/usr/bin/execlineb -S0
s6-svscanctl -t /var/run/s6/services

View File

@ -0,0 +1,3 @@
#!/usr/bin/with-contenv sh
exec /usr/bin/gunicorn --chdir /usr/src/app app:app