From b7ed8205fcdc466ec09123b59b841e41ff649676 Mon Sep 17 00:00:00 2001 From: chrisjsimpson Date: Tue, 11 Oct 2022 22:39:13 +0100 Subject: [PATCH 1/6] wip Fix #73 containerisation of deployer components --- .dockerignore | 1 + README.md | 18 ++++++++++++++++++ run.sh | 7 ++++++- src/subscribie-deployer/Dockerfile | 9 +++++++++ app.skel => src/subscribie-deployer/app.skel | 0 main.py => src/subscribie-deployer/main.py | 0 .../subscribie-deployer/requirements.txt | 0 src/subscribie-server/Dockerfile | 15 +++++++++++++++ src/subscribie-server/requirements.txt | 1 + 9 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 src/subscribie-deployer/Dockerfile rename app.skel => src/subscribie-deployer/app.skel (100%) rename main.py => src/subscribie-deployer/main.py (100%) rename requirements.txt => src/subscribie-deployer/requirements.txt (100%) create mode 100644 src/subscribie-server/Dockerfile create mode 100644 src/subscribie-server/requirements.txt diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5ceb386 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +venv diff --git a/README.md b/README.md index 8fec474..665f0e2 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,24 @@ Responsible for building new subscribie sites. - Each site runs as a uwsgi 'vassal' which allows new sites to come online without having to restart the web server +# Local development using `podman-compose` + +1. [Install `podman`](https://podman.io/getting-started/installation) +2. Install `podman-compose`: + ``` + python3 -m venv venv; + . venv/bin/activate + pip install podman-compose + ``` + +Start `subscribie-deployer` & `subscribie-server` + +``` +./run.sh +``` + +`subscribie-server` is responsible for hosting shops. + ## Configuration #### Create virtual env & install requirements: diff --git a/run.sh b/run.sh index a85f89c..bf09144 100755 --- a/run.sh +++ b/run.sh @@ -1 +1,6 @@ -uvicorn --reload main:app --host 0.0.0.0 --port 5001 +#!/bin/bash + +set -euxo pipefail + +podman-compose up --build --force-recreate +#docker-compose -f compose.yaml up --build --force-recreate diff --git a/src/subscribie-deployer/Dockerfile b/src/subscribie-deployer/Dockerfile new file mode 100644 index 0000000..b198178 --- /dev/null +++ b/src/subscribie-deployer/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.10.7 +ENV PYTHONUNBUFFERED=1 + +WORKDIR /usr/src/app +COPY . . +RUN pip install -r requirements.txt + +#CMD ["python", "-m", "http.server", "8000"] +CMD uvicorn --reload main:app --host 0.0.0.0 --port 5001 diff --git a/app.skel b/src/subscribie-deployer/app.skel similarity index 100% rename from app.skel rename to src/subscribie-deployer/app.skel diff --git a/main.py b/src/subscribie-deployer/main.py similarity index 100% rename from main.py rename to src/subscribie-deployer/main.py diff --git a/requirements.txt b/src/subscribie-deployer/requirements.txt similarity index 100% rename from requirements.txt rename to src/subscribie-deployer/requirements.txt diff --git a/src/subscribie-server/Dockerfile b/src/subscribie-server/Dockerfile new file mode 100644 index 0000000..ef6bbc9 --- /dev/null +++ b/src/subscribie-server/Dockerfile @@ -0,0 +1,15 @@ +FROM httpd + +WORKDIR /usr/src/app + +COPY . . + +RUN apt-get update && apt-get install -y python3 python3-pip + +RUN pip install -r requirements.txt + +# Enable httpd mod_proxy_uwsgi +RUN sed -i \ + -e 's/^#\(LoadModule .*mod_proxy_uwsgi.so\)/\1/' \ + conf/httpd.conf + diff --git a/src/subscribie-server/requirements.txt b/src/subscribie-server/requirements.txt new file mode 100644 index 0000000..4b47465 --- /dev/null +++ b/src/subscribie-server/requirements.txt @@ -0,0 +1 @@ +uWSGI==2.0.20 From e0fdc46d4443de00cb4ed188a039fdc39f2ffa6b Mon Sep 17 00:00:00 2001 From: chrisjsimpson Date: Mon, 10 Oct 2022 22:17:14 +0100 Subject: [PATCH 2/6] wip Fix #71 .env.example -> .new-shop.env.example --- .env.example => .new-shop.env.example | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .env.example => .new-shop.env.example (100%) diff --git a/.env.example b/.new-shop.env.example similarity index 100% rename from .env.example rename to .new-shop.env.example From 2e7aa8adf9c5cb69ce4e1d03645e05bd8e46948d Mon Sep 17 00:00:00 2001 From: chrisjsimpson Date: Mon, 10 Oct 2022 22:23:29 +0100 Subject: [PATCH 3/6] #71 remove uneeded .new-shop.env.example because read from https://github.com/Subscribie/subscribie/blob/master/.envsubst.template --- .new-shop.env.example | 90 ------------------------------------------- 1 file changed, 90 deletions(-) delete mode 100644 .new-shop.env.example diff --git a/.new-shop.env.example b/.new-shop.env.example deleted file mode 100644 index 31e249f..0000000 --- a/.new-shop.env.example +++ /dev/null @@ -1,90 +0,0 @@ -#Only values in uppercase are actually stored in the config object later on. So make sure to use uppercase letters for your config keys. - -# Change FLASK_ENV=live for live -FLASK_ENV=${FLASK_ENV} - -# Software as a service (SAAS) -SAAS_URL=${SAAS_URL} -# SAAS_API_KEY is to allow subscribie platform to send authenticated -# api requests to subscribie shops created by the shop builder. -SAAS_API_KEY=${SAAS_API_KEY} -SAAS_ACTIVATE_ACCOUNT_PATH=${SAAS_ACTIVATE_ACCOUNT_PATH} - -# For testing this repo in isolation, SUBSCRIBIE_REPO_DIRECTORY can be './' -# for production, SUBSCRIBIE_REPO_DIRECTORY should be wherever the repo -# is cloned to -SUBSCRIBIE_REPO_DIRECTORY=${SUBSCRIBIE_REPO_DIRECTORY} -SQLALCHEMY_TRACK_MODIFICATIONS=False -SQLALCHEMY_DATABASE_URI=${SQLALCHEMY_DATABASE_URI} -SECRET_KEY="random string. e.g. echo -e 'from os import urandom\\nprint urandom(25)' | python" -DB_FULL_PATH=${DB_FULL_PATH} -MODULES_PATH="./modules/" -TEMPLATE_BASE_DIR=${TEMPLATE_BASE_DIR} -THEME_NAME="jesmond" -CUSTOM_PAGES_PATH=${CUSTOM_PAGES_PATH} -UPLOADED_IMAGES_DEST=${UPLOADED_IMAGES_DEST} -UPLOADED_FILES_DEST=${UPLOADED_FILES_DEST} -# Default 50Mb upload limit -MAX_CONTENT_LENGTH="52428800" -SUCCESS_REDIRECT_URL=${SUCCESS_REDIRECT_URL} -THANKYOU_URL=${THANKYOU_URL} -EMAIL_LOGIN_FROM=${EMAIL_LOGIN_FROM} -EMAIL_QUEUE_FOLDER=${EMAIL_QUEUE_FOLDER} - - -SERVER_NAME=${SERVER_NAME} - -# Cookie policies -#SESSION_COOKIE_SECURE=True -#SESSION_COOKIE_HTTPONLY=True -#SESSION_COOKIE_SAMESITE=None - -MAIL_DEFAULT_SENDER=${MAIL_DEFAULT_SENDER} - -STRIPE_LIVE_PUBLISHABLE_KEY=${STRIPE_LIVE_PUBLISHABLE_KEY} -STRIPE_LIVE_SECRET_KEY=${STRIPE_LIVE_SECRET_KEY} - -STRIPE_TEST_PUBLISHABLE_KEY=${STRIPE_TEST_PUBLISHABLE_KEY} -STRIPE_TEST_SECRET_KEY=${STRIPE_TEST_SECRET_KEY} - -# Internal server where shop should send its stripe connect account id to. See https://github.com/Subscribie/subscribie/issues/352 -STRIPE_CONNECT_ACCOUNT_ANNOUNCER_HOST=${STRIPE_CONNECT_ACCOUNT_ANNOUNCER_HOST} - -# Google oauth (signin / up with Google -GOOGLE_CLIENT_ID=???.apps.googleusercontent.com -GOOGLE_CLIENT_SECRET=??? -GOOGLE_REDIRECT_URI="http://127.0.0.1:5000/google-oauth2callback/" -GOOGLE_RESPONSE_TYPE=code -GOOGLE_SCOPE="email openid profile" - -# For development: - -HONEYCOMB_API_KEY= - -# Python log levels: DEBUG, INFO, WARNING, ERROR, CRITICAL -# See https://docs.python.org/3/howto/logging.html -PYTHON_LOG_LEVEL=DEBUG - -# Playwright testing -PLAYWRIGHT_HOST=http://127.0.0.1:5000/ -PLAYWRIGHT_HEADLESS=true - -#rename shop variables -PATH_TO_SITES=${PATH_TO_SITES} -PATH_TO_RENAME_SCRIPT=${PATH_TO_RENAME_SCRIPTS} -SUBSCRIBIE_DOMAIN="subscriby.shop" - -PRIVATE_KEY="/tmp/private.pem" -PUBLIC_KEY="/tmp/public.pem" - - -# Optional -TELEGRAM_TOKEN= -TELEGRAM_CHAT_ID= -TELEGRAM_PYTHON_LOG_LEVEL="ERROR" - - -# Environment Settings for tests -TEST_SHOP_OWNER_EMAIL_ISSUE_704=admin@example.com -TEST_SHOP_OWNER_LOGIN_URL=http://127.0.0.1:5000/auth/login - From daab3c908eb761186f1afc36d06f4f8b5c9e4572 Mon Sep 17 00:00:00 2001 From: chrisjsimpson Date: Tue, 11 Oct 2022 21:38:39 +0100 Subject: [PATCH 4/6] #71 bring back .env.example --- .env.example | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..31e249f --- /dev/null +++ b/.env.example @@ -0,0 +1,90 @@ +#Only values in uppercase are actually stored in the config object later on. So make sure to use uppercase letters for your config keys. + +# Change FLASK_ENV=live for live +FLASK_ENV=${FLASK_ENV} + +# Software as a service (SAAS) +SAAS_URL=${SAAS_URL} +# SAAS_API_KEY is to allow subscribie platform to send authenticated +# api requests to subscribie shops created by the shop builder. +SAAS_API_KEY=${SAAS_API_KEY} +SAAS_ACTIVATE_ACCOUNT_PATH=${SAAS_ACTIVATE_ACCOUNT_PATH} + +# For testing this repo in isolation, SUBSCRIBIE_REPO_DIRECTORY can be './' +# for production, SUBSCRIBIE_REPO_DIRECTORY should be wherever the repo +# is cloned to +SUBSCRIBIE_REPO_DIRECTORY=${SUBSCRIBIE_REPO_DIRECTORY} +SQLALCHEMY_TRACK_MODIFICATIONS=False +SQLALCHEMY_DATABASE_URI=${SQLALCHEMY_DATABASE_URI} +SECRET_KEY="random string. e.g. echo -e 'from os import urandom\\nprint urandom(25)' | python" +DB_FULL_PATH=${DB_FULL_PATH} +MODULES_PATH="./modules/" +TEMPLATE_BASE_DIR=${TEMPLATE_BASE_DIR} +THEME_NAME="jesmond" +CUSTOM_PAGES_PATH=${CUSTOM_PAGES_PATH} +UPLOADED_IMAGES_DEST=${UPLOADED_IMAGES_DEST} +UPLOADED_FILES_DEST=${UPLOADED_FILES_DEST} +# Default 50Mb upload limit +MAX_CONTENT_LENGTH="52428800" +SUCCESS_REDIRECT_URL=${SUCCESS_REDIRECT_URL} +THANKYOU_URL=${THANKYOU_URL} +EMAIL_LOGIN_FROM=${EMAIL_LOGIN_FROM} +EMAIL_QUEUE_FOLDER=${EMAIL_QUEUE_FOLDER} + + +SERVER_NAME=${SERVER_NAME} + +# Cookie policies +#SESSION_COOKIE_SECURE=True +#SESSION_COOKIE_HTTPONLY=True +#SESSION_COOKIE_SAMESITE=None + +MAIL_DEFAULT_SENDER=${MAIL_DEFAULT_SENDER} + +STRIPE_LIVE_PUBLISHABLE_KEY=${STRIPE_LIVE_PUBLISHABLE_KEY} +STRIPE_LIVE_SECRET_KEY=${STRIPE_LIVE_SECRET_KEY} + +STRIPE_TEST_PUBLISHABLE_KEY=${STRIPE_TEST_PUBLISHABLE_KEY} +STRIPE_TEST_SECRET_KEY=${STRIPE_TEST_SECRET_KEY} + +# Internal server where shop should send its stripe connect account id to. See https://github.com/Subscribie/subscribie/issues/352 +STRIPE_CONNECT_ACCOUNT_ANNOUNCER_HOST=${STRIPE_CONNECT_ACCOUNT_ANNOUNCER_HOST} + +# Google oauth (signin / up with Google +GOOGLE_CLIENT_ID=???.apps.googleusercontent.com +GOOGLE_CLIENT_SECRET=??? +GOOGLE_REDIRECT_URI="http://127.0.0.1:5000/google-oauth2callback/" +GOOGLE_RESPONSE_TYPE=code +GOOGLE_SCOPE="email openid profile" + +# For development: + +HONEYCOMB_API_KEY= + +# Python log levels: DEBUG, INFO, WARNING, ERROR, CRITICAL +# See https://docs.python.org/3/howto/logging.html +PYTHON_LOG_LEVEL=DEBUG + +# Playwright testing +PLAYWRIGHT_HOST=http://127.0.0.1:5000/ +PLAYWRIGHT_HEADLESS=true + +#rename shop variables +PATH_TO_SITES=${PATH_TO_SITES} +PATH_TO_RENAME_SCRIPT=${PATH_TO_RENAME_SCRIPTS} +SUBSCRIBIE_DOMAIN="subscriby.shop" + +PRIVATE_KEY="/tmp/private.pem" +PUBLIC_KEY="/tmp/public.pem" + + +# Optional +TELEGRAM_TOKEN= +TELEGRAM_CHAT_ID= +TELEGRAM_PYTHON_LOG_LEVEL="ERROR" + + +# Environment Settings for tests +TEST_SHOP_OWNER_EMAIL_ISSUE_704=admin@example.com +TEST_SHOP_OWNER_LOGIN_URL=http://127.0.0.1:5000/auth/login + From e05a2f2d57ba32aaf7d5a1efdeb850cf4de26943 Mon Sep 17 00:00:00 2001 From: chrisjsimpson Date: Tue, 11 Oct 2022 22:42:59 +0100 Subject: [PATCH 5/6] #73 add missing compose.yaml --- compose.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 compose.yaml diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..ad2b130 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,13 @@ +services: + subscribie-deployer: + image: subscribie/deployer + build: + context: ./src/subscribie-deployer + ports: + - "5001:5001" + subscribie-server: + image: subscribie/subscribie-server + build: + context: ./src/subscribie-server + ports: + - "8080:80" From bc5b27896b02b8582d669a7819ea2d1d406eddef Mon Sep 17 00:00:00 2001 From: chrisjsimpson Date: Tue, 11 Oct 2022 22:53:07 +0100 Subject: [PATCH 6/6] #73 bind mount deployer source into container for development --- compose.yaml | 5 +++++ src/subscribie-deployer/Dockerfile | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/compose.yaml b/compose.yaml index ad2b130..91942b2 100644 --- a/compose.yaml +++ b/compose.yaml @@ -5,6 +5,11 @@ services: context: ./src/subscribie-deployer ports: - "5001:5001" + # https://github.com/compose-spec/compose-spec/blob/master/spec.md#volumes + volumes: + - type: bind + source: ./src/subscribie-deployer + target: /usr/src/app subscribie-server: image: subscribie/subscribie-server build: diff --git a/src/subscribie-deployer/Dockerfile b/src/subscribie-deployer/Dockerfile index b198178..5d487e1 100644 --- a/src/subscribie-deployer/Dockerfile +++ b/src/subscribie-deployer/Dockerfile @@ -5,5 +5,4 @@ WORKDIR /usr/src/app COPY . . RUN pip install -r requirements.txt -#CMD ["python", "-m", "http.server", "8000"] CMD uvicorn --reload main:app --host 0.0.0.0 --port 5001