From 7a28024ccde6aefd8ca22a8f231342b6379b5136 Mon Sep 17 00:00:00 2001 From: H4CK3R-01 Date: Tue, 8 Mar 2022 15:19:19 +0100 Subject: [PATCH] Added Dockerfile, deploy settings and pipeline config --- .drone.yml | 27 +++++++++++++++++++++++++++ Dockerfile | 19 +++++++++++++++++++ deploy/healthcheck.sh | 2 ++ deploy/nginx.conf | 41 +++++++++++++++++++++++++++++++++++++++++ deploy/start.sh | 3 +++ deploy/uwsgi.ini | 12 ++++++++++++ requirements.txt | 0 7 files changed, 104 insertions(+) create mode 100644 .drone.yml create mode 100644 Dockerfile create mode 100644 deploy/healthcheck.sh create mode 100644 deploy/nginx.conf create mode 100644 deploy/start.sh create mode 100644 deploy/uwsgi.ini create mode 100644 requirements.txt diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..5dcc952 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,27 @@ +kind: pipeline +type: docker +name: linux-amd64 + +platform: + arch: amd64 + os: linux + +steps: +- name: generate_tag + image: golang + commands: + - echo -n "${DRONE_BRANCH//\//-}-${DRONE_COMMIT_SHA:0:8}, latest" > .tags + + +- name: publish + image: plugins/docker + settings: + username: + from_secret: username + password: + from_secret: password + registry: + from_secret: registry + repo: + from_secret: repo + dockerfile: Dockerfile \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e6d8352 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM python:3.10-alpine + +WORKDIR /srv/flask_app +RUN apk add nginx build-base libffi-dev curl + +COPY requirements.txt /srv/flask_app/ + +RUN pip install -r requirements.txt --src /usr/local/src --no-warn-script-location + +COPY . /srv/flask_app +COPY deploy/nginx.conf /etc/nginx +RUN chmod +x ./deploy/start.sh +RUN chmod +x ./deploy/healthcheck.sh + +HEALTHCHECK --interval=15s --timeout=2s CMD ["./deploy/healthcheck.sh"] + +EXPOSE 80 + +CMD ["./deploy/start.sh"] \ No newline at end of file diff --git a/deploy/healthcheck.sh b/deploy/healthcheck.sh new file mode 100644 index 0000000..390f507 --- /dev/null +++ b/deploy/healthcheck.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +curl -s http://localhost:80/ -o /dev/null || exit 1 diff --git a/deploy/nginx.conf b/deploy/nginx.conf new file mode 100644 index 0000000..8a75026 --- /dev/null +++ b/deploy/nginx.conf @@ -0,0 +1,41 @@ +user root; +worker_processes auto; +pid /run/nginx.pid; + +events { + worker_connections 1024; + use epoll; + multi_accept on; +} + +http { + access_log /dev/stdout; + error_log /dev/stdout; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + index index.html index.htm; + + server { + listen 80 default_server; + listen [::]:80 default_server; + server_name homeserver.flokaiser.com; + root /var/www/html; + + location / { + include uwsgi_params; + uwsgi_pass unix:/tmp/uwsgi.socket; + uwsgi_read_timeout 1h; + uwsgi_send_timeout 1h; + proxy_send_timeout 1h; + proxy_read_timeout 1h; + } + } +} \ No newline at end of file diff --git a/deploy/start.sh b/deploy/start.sh new file mode 100644 index 0000000..77fb780 --- /dev/null +++ b/deploy/start.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh +nginx -g "daemon off;" & +uwsgi --ini deploy/uwsgi.ini \ No newline at end of file diff --git a/deploy/uwsgi.ini b/deploy/uwsgi.ini new file mode 100644 index 0000000..fea5325 --- /dev/null +++ b/deploy/uwsgi.ini @@ -0,0 +1,12 @@ +[uwsgi] +module = app:app +uid = root +gid = root +master = true +processes = 5 + +socket = /tmp/uwsgi.socket +chmod-sock = 664 +vacuum = true + +die-on-term = true \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e69de29