From 5bd0596281ec03f8a1ed4059e9620c9f156b604f Mon Sep 17 00:00:00 2001 From: mco-system Date: Sat, 22 Apr 2023 17:07:56 +1100 Subject: [PATCH] build: Docker version --- Makefile | 33 +++++++++++++++++++-------------- docker-compose.yml | 10 ++++++++++ thsf.Dockerfile | 14 ++++++++++++++ thsf.net.code-workspace | 8 ++++++++ 4 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 docker-compose.yml create mode 100644 thsf.Dockerfile create mode 100644 thsf.net.code-workspace diff --git a/Makefile b/Makefile index 5f27d87..cefd1a6 100644 --- a/Makefile +++ b/Makefile @@ -1,45 +1,50 @@ -.PHONY: clean distclean install run stop +.PHONY: clean distclean install run stop all docker-build docker-run docker-stop docker-all install: set -e ;\ - THSF_DIR=$$(pwd); \ - echo [+] Déploiement dans $$THSF_DIR; \ - python3 -m venv thsf_venv; \ + python -m venv thsf_venv; \ . thsf_venv/bin/activate; \ - pip3 install -r requirements.txt ;\ - pip3 install . ;\ - pip3 install gunicorn; \ + pip install -r requirements.txt ;\ + pip install . ;\ + pip install gunicorn; \ run: set -e ;\ THSF_DIR=$$(pwd); \ - echo [+] Démarrage dans $$THSF_DIR; \ . thsf_venv/bin/activate; \ - thsf_venv/bin/gunicorn -D -p thsf.pid -w 4 -b 127.0.0.1:8042 'thsf:app' + thsf_venv/bin/gunicorn -p thsf.pid -w 4 -b 0.0.0.0:8042 'thsf:app' debug: set -e ;\ THSF_DIR=$$(pwd); \ - echo [+] Démarrage dans $$THSF_DIR; \ . thsf_venv/bin/activate; \ - thsf_venv/bin/gunicorn -p thsf.pid -w 4 -b 127.0.0.1:8042 'thsf:app' + thsf_venv/bin/gunicorn -p thsf.pid -w 4 -b 0.0.0.0:8042 'thsf:app' stop: -set -e;\ THSF_DIR=$$(pwd); \ - echo [+] Arrêt dans $$THSF_DIR; \ kill -15 $$(cat $$THSF_DIR/thsf.pid); \ rm thsf.pid clean: -set -e ;\ THSF_DIR=$$(pwd); \ - echo [+] Nettoyage dans $$THSF_DIR; \ rm -Rf ./build ./src/thsf.egg-info ./thsf.pid ./thsf.log; \ . thsf_venv/bin/activate; \ - pip3 uninstall thsf -y + pip uninstall thsf -y distclean: clean rm -Rf thsf_venv/ all: stop clean install run + +docker-build: + docker-compose build + +docker-run: + docker-compose up -d + +docker-stop: + -docker-compose down + +docker-all: docker-stop docker-build docker-run diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..516474c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +version: "2" +services: + thsf: + build: + dockerfile: thsf.Dockerfile + context: . + ports: + - "127.0.0.1:8042:8042" + image: thsf:latest + container_name: thsf diff --git a/thsf.Dockerfile b/thsf.Dockerfile new file mode 100644 index 0000000..4b41b31 --- /dev/null +++ b/thsf.Dockerfile @@ -0,0 +1,14 @@ +FROM python:3.9.16-bullseye as thsf_base +RUN apt-get update -y && \ + apt-get install -y bash make python3-pip && \ + useradd -m -d /home/thsf -s /bin/bash thsf + +from thsf_base as thsf_build +COPY . /home/thsf/ +RUN chown -R thsf:thsf /home/thsf/ +USER thsf +WORKDIR /home/thsf/ + +from thsf_build +RUN make install +CMD ["make", "run"] diff --git a/thsf.net.code-workspace b/thsf.net.code-workspace new file mode 100644 index 0000000..5709732 --- /dev/null +++ b/thsf.net.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": {} +}