From dc9511a252d98296eb2b3efd73466a31f6a7dd31 Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 10 Oct 2023 00:01:02 -0400 Subject: [PATCH 1/4] wip #23 containerization --- .env.example | 2 +- .gitignore | 1 + app/.env.example | 10 ++++++++ app/.tif-to-COG.sh.swp | Bin 0 -> 12288 bytes app/Dockerfile | 23 ++++++++++++++++++ app.py => app/app.py | 0 app/ecw-to-COG.sh | 10 ++++++++ emails.py => app/emails.py | 0 app/entrypoint.sh | 4 +++ requirements.txt => app/requirements.txt | 1 + run.sh => app/run.sh | 0 tasks.py => app/tasks.py | 0 {templates => app/templates}/homepage.html | 0 .../templates}/upload_complete.html | 0 app/tif-to-COG.sh | 11 +++++++++ app/uploads/.gitkeep | 0 docker-compose.yml | 12 +++++++++ ecw-to-COG.sh | 10 -------- tif-to-COG.sh | 11 --------- 19 files changed, 73 insertions(+), 22 deletions(-) create mode 100755 app/.env.example create mode 100755 app/.tif-to-COG.sh.swp create mode 100755 app/Dockerfile rename app.py => app/app.py (100%) mode change 100644 => 100755 create mode 100755 app/ecw-to-COG.sh rename emails.py => app/emails.py (100%) mode change 100644 => 100755 create mode 100755 app/entrypoint.sh rename requirements.txt => app/requirements.txt (68%) mode change 100644 => 100755 rename run.sh => app/run.sh (100%) rename tasks.py => app/tasks.py (100%) mode change 100644 => 100755 rename {templates => app/templates}/homepage.html (100%) mode change 100644 => 100755 rename {templates => app/templates}/upload_complete.html (100%) mode change 100644 => 100755 create mode 100755 app/tif-to-COG.sh create mode 100644 app/uploads/.gitkeep create mode 100644 docker-compose.yml delete mode 100755 ecw-to-COG.sh delete mode 100755 tif-to-COG.sh diff --git a/.env.example b/.env.example index 61ed3dc..5ebd637 100644 --- a/.env.example +++ b/.env.example @@ -2,7 +2,7 @@ SECRET_KEY=changeme DEBUG=True UPLOAD_FOLDER="/path/to/upload/folder" PORT=25 -DOMAIN=127.0.0.1:5000 +DOMAIN=127.0.0.1:8888 SMTP_SERVER=email.example.com SENDER_EMAIL=admin@example.com PASSWORD=changeme diff --git a/.gitignore b/.gitignore index f312cd9..6b23f88 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ __pycache__ venv/ .env src/uploads +app/uploads diff --git a/app/.env.example b/app/.env.example new file mode 100755 index 0000000..89b4f7b --- /dev/null +++ b/app/.env.example @@ -0,0 +1,10 @@ +SECRET_KEY="ASDSADASDASDASDadsf" +DEBUG="True" +UPLOAD_FOLDER="/code/uploads" +DOMAIN=127.0.0.1:5000 +PORT=25 +SMTP_SERVER=email.subscribie.co.uk +SENDER_EMAIL=test@subscribie.co.uk +PASSWORD="badness handoff disabled figure" +receiver_email_1="joeltejeda21@gmail.com" +receiver_email_2="joel@subscribie.co.uk" diff --git a/app/.tif-to-COG.sh.swp b/app/.tif-to-COG.sh.swp new file mode 100755 index 0000000000000000000000000000000000000000..d4815844e27f3dfbb0ce61f834f2e400e7427f89 GIT binary patch literal 12288 zcmeI&&2G~`5CGsQSHzFt1*VRrfP~{FTp-AYG;vBKr;ZXQ5?ri}y>3iX+ltqvl@Q#x za_3Rt+#AmTFTn#a8v;^#Nw1(;X|(a|>_+?DEYJL4HW=cwMiXe<2l)8OlvkH+czp%% zCYMW{-ZiRum8oi16~KFapj}+5MV{F*dTXiNQfZP{QJ$U4Rhd#+6opMWz0~!O8s%d5 zv0T9dEN~-%JMgsCJkX^zV;>(rnBHg?7qI{fumB6N01L1H3$OqS{2v0U*nw0De$> zr}#$kmEsGNwXxp(+0`u}j=JrV}mhGibvQ%i#)6AZWa)DNaMiis2dx5$n zR4b8{x(=;8LFyl;njDX(!!UR`c00X^)A78pJDN^#z2dnu*K?k)e|P=iXzWfVPS5Ro zoxoiu4+lrVpx<|1xs&xXRrChkz#ls;G>4s082Dk=Kc2bc08RS8kaG3#cRRb1aYJ{v z*A0Npl4CxS(IThIZtpel9Y&QxE5>@Gj#h%r$56vSoTk|c=Cq;~66J-GnQoHDOq@x8 iEilJy!S Date: Tue, 10 Oct 2023 23:27:21 -0400 Subject: [PATCH 2/4] adding the readme, env example and volume mount for DinD --- .env.example | 27 ++++++++++++++++----------- README.md | 6 ++---- app/app.py | 20 ++++++++++++-------- app/requirements.txt | 1 + uploads/.gitkeep | 0 5 files changed, 31 insertions(+), 23 deletions(-) delete mode 100644 uploads/.gitkeep diff --git a/.env.example b/.env.example index 8764b8a..a96f27b 100644 --- a/.env.example +++ b/.env.example @@ -1,11 +1,16 @@ -SECRET_KEY=changeme -DEBUG=True -UPLOAD_FOLDER="/path/to/upload/folder" -PORT=25 -DOMAIN=127.0.0.1:8888 -SERVER_NAME=example.com -SMTP_SERVER=email.example.com -SENDER_EMAIL=admin@example.com -PASSWORD=changeme -receiver_email_1=admin@example.com -STRIPE_SECRET_KEY=changeme +SECRET_KEY="ASDSADASDASDASDadsf" +DEBUG="True" +APP_UPLOAD_FOLDER="/ecw-to-tiff/uploads" + +# change to absolute path where your upload folder inside the app folder is. +UPLOAD_FOLDER_MOUNT_PATH="/path/to/ecw-to-tiff-conversion/app/uploads" +SEND_EMAIL="False" + +# remove the comments below only if SEND_EMAIL="TRUE" +#DOMAIN=127.0.0.1:8888 +#PORT=25 +#SMTP_SERVER=email.example.com +#SENDER_EMAIL=test@example.com +#PASSWORD="changeme" +#receiver_email_1="admin1@example.com" +#receiver_email_2="admin2@example.com" diff --git a/README.md b/README.md index 1018488..0cb59d2 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,7 @@ ## How to run it ``` -python3 -m venv venv -. venv/bin/activate -pip install -r requirements.txt +# change UPLOAD_FOLDER_MOUNT_PATH to the right setting cp .env.example .env -FLASK_DEBUG=1 flask run +docker-compose up --build ``` diff --git a/app/app.py b/app/app.py index d4cceb2..2c0ce88 100755 --- a/app/app.py +++ b/app/app.py @@ -1,5 +1,6 @@ import os import hashlib +import stripe from flask import ( render_template, Flask, @@ -20,15 +21,16 @@ send_notification_upload_email, send_email_to_admin, ) # noqa: E501 -import stripe load_dotenv() SERVER_NAME = os.getenv("SERVER_NAME") -UPLOAD_FOLDER = os.getenv("UPLOAD_FOLDER") +UPLOAD_FOLDER = os.getenv("APP_UPLOAD_FOLDER") +UPLOAD_FOLDER_MOUNT_PATH = os.getenv("UPLOAD_FOLDER_MOUNT_PATH") STRIPE_SECRET_KEY = os.getenv("STRIPE_SECRET_KEY") ALLOWED_EXTENSIONS_TIFF = {".tiff", ".tif"} ALLOWED_EXTENSIONS_ECW = {".ecw"} +SEND_EMAIL = os.getenv("SEND_EMAIL") app = Flask(__name__) app.config["SECRET_KEY"] = os.getenv("SECRET_KEY") @@ -175,11 +177,12 @@ def convert_ecw_to_cog(app=None, filename=None, email=None): print(f"Running background ecw to cog on {filename}") with app.app_context(): subprocess.run( - f"./ecw-to-COG.sh {filename} {UPLOAD_FOLDER}", + f"./ecw-to-COG.sh {filename} {UPLOAD_FOLDER_MOUNT_PATH}", shell=True, ) - send_email(email, filename) - send_email_to_admin(email, filename) + if SEND_EMAIL == "True": + send_email(email, filename) + send_email_to_admin(email, filename) @background_task @@ -187,8 +190,9 @@ def convert_tif_to_cog(app=None, filename=None, email=None): print(f"Running background tif to cog on {filename}") with app.app_context(): subprocess.run( - f"./tif-to-COG.sh {filename} {UPLOAD_FOLDER}", + f"./tif-to-COG.sh {filename} {UPLOAD_FOLDER_MOUNT_PATH}", shell=True, ) - send_email(email, filename) - send_email_to_admin(email, filename) + if SEND_EMAIL == "True": + send_email(email, filename) + send_email_to_admin(email, filename) diff --git a/app/requirements.txt b/app/requirements.txt index 7e3c2e4..ea15f91 100755 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -1,3 +1,4 @@ Flask==2.2.2 python-dotenv==0.21.0 Werkzeug==2.2.2 +stripe diff --git a/uploads/.gitkeep b/uploads/.gitkeep deleted file mode 100644 index e69de29..0000000 From d3f069556e6b1d8949d622eae47929e364b0e0ef Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 10 Oct 2023 23:33:46 -0400 Subject: [PATCH 3/4] reorganizing --- .env.example | 3 ++- app/.env.example | 10 ---------- app/run.sh | 3 --- docker-compose.yml | 8 ++++---- 4 files changed, 6 insertions(+), 18 deletions(-) delete mode 100755 app/.env.example delete mode 100755 app/run.sh diff --git a/.env.example b/.env.example index a96f27b..81a19ad 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,8 @@ SECRET_KEY="ASDSADASDASDASDadsf" DEBUG="True" APP_UPLOAD_FOLDER="/ecw-to-tiff/uploads" - +DOCKER_SOCKET="/var/run/docker.sock" +DOCKER_LIB="/usr/bin/docker" # change to absolute path where your upload folder inside the app folder is. UPLOAD_FOLDER_MOUNT_PATH="/path/to/ecw-to-tiff-conversion/app/uploads" SEND_EMAIL="False" diff --git a/app/.env.example b/app/.env.example deleted file mode 100755 index 89b4f7b..0000000 --- a/app/.env.example +++ /dev/null @@ -1,10 +0,0 @@ -SECRET_KEY="ASDSADASDASDASDadsf" -DEBUG="True" -UPLOAD_FOLDER="/code/uploads" -DOMAIN=127.0.0.1:5000 -PORT=25 -SMTP_SERVER=email.subscribie.co.uk -SENDER_EMAIL=test@subscribie.co.uk -PASSWORD="badness handoff disabled figure" -receiver_email_1="joeltejeda21@gmail.com" -receiver_email_2="joel@subscribie.co.uk" diff --git a/app/run.sh b/app/run.sh deleted file mode 100755 index 8a9586a..0000000 --- a/app/run.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -flask run --host 0.0.0.0 --port 8888 diff --git a/docker-compose.yml b/docker-compose.yml index 25aa8c5..8630567 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,10 +3,10 @@ services: ecw-to-tiff: build: ./app volumes: - - "./app:/ecw-to-tiff/" - - "/var/run/docker.sock:/var/run/docker.sock" - - "/usr/bin/docker:/usr/local/bin/docker" + - "${UPLOAD_FOLDER_MOUNT_PATH}:/ecw-to-tiff/uploads" + - "${DOCKER_SOCKET}:/var/run/docker.sock" + - "${DOCKER_LIB}:/usr/local/bin/docker" ports: - 8888:8888 env_file: - - ./app/.env + - .env From 440c3b3921c7e8631e76e0878766a9964f26af53 Mon Sep 17 00:00:00 2001 From: Joel Tejeda Date: Wed, 11 Oct 2023 11:52:41 -0400 Subject: [PATCH 4/4] adding windows compatibility --- app/.dockerignore | 1 + app/.tif-to-COG.sh.swp | Bin 12288 -> 0 bytes app/Dockerfile | 6 +----- app/app.py | 4 ++-- docker-compose.yml | 2 +- 5 files changed, 5 insertions(+), 8 deletions(-) create mode 100644 app/.dockerignore delete mode 100755 app/.tif-to-COG.sh.swp diff --git a/app/.dockerignore b/app/.dockerignore new file mode 100644 index 0000000..dc6e631 --- /dev/null +++ b/app/.dockerignore @@ -0,0 +1 @@ +uploads/* diff --git a/app/.tif-to-COG.sh.swp b/app/.tif-to-COG.sh.swp deleted file mode 100755 index d4815844e27f3dfbb0ce61f834f2e400e7427f89..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI&&2G~`5CGsQSHzFt1*VRrfP~{FTp-AYG;vBKr;ZXQ5?ri}y>3iX+ltqvl@Q#x za_3Rt+#AmTFTn#a8v;^#Nw1(;X|(a|>_+?DEYJL4HW=cwMiXe<2l)8OlvkH+czp%% zCYMW{-ZiRum8oi16~KFapj}+5MV{F*dTXiNQfZP{QJ$U4Rhd#+6opMWz0~!O8s%d5 zv0T9dEN~-%JMgsCJkX^zV;>(rnBHg?7qI{fumB6N01L1H3$OqS{2v0U*nw0De$> zr}#$kmEsGNwXxp(+0`u}j=JrV}mhGibvQ%i#)6AZWa)DNaMiis2dx5$n zR4b8{x(=;8LFyl;njDX(!!UR`c00X^)A78pJDN^#z2dnu*K?k)e|P=iXzWfVPS5Ro zoxoiu4+lrVpx<|1xs&xXRrChkz#ls;G>4s082Dk=Kc2bc08RS8kaG3#cRRb1aYJ{v z*A0Npl4CxS(IThIZtpel9Y&QxE5>@Gj#h%r$56vSoTk|c=Cq;~66J-GnQoHDOq@x8 iEilJy!S