Hi, just in the case you would find the configs useful.
Notes:
- The base image py4web_light. Individual projects on top of that.
- Developing on Linux, user with uid 1000 & gid 1000 on the local
machine => same uid and gid for py4web user in the docker images to
avoid permission issues with bind-style volumes.
- Debugging in the "attach" debugpy mode which works also within containers.
- VS Code extensions: Docker, Jupyter, Pylance, Python, Remote - Conteiners, Remote - SSH (the last one for debugging remotely deployed containers).
- Examples app is retained as a handy source of inspiration.
- Troubles with newer versions gevent (debuger was not stopping on breakpoints) => avoid GEVENT_SUPPORT=True.
- I have a customized scaffolding app which loads the .env variables, includes custom modules shared among more projects, scripts for pushing images to docker repositories, other deployment-related stuff such as SSL sidecar https://github.com/jwulf/letsencrypt-nginx-sidecar.git, etc. Not included below - goes beyond the basic py4web+Docker+VSCode+debugpy functionality.
./py4web_light/Dockerfile
FROM ubuntu:latest
ENV TZ=Europe/Prague
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update && apt-get install -y python3 python3-pip
ARG user=py4web uid=1000 gid=1000
RUN groupadd --system --gid $gid $user && useradd --create-home --system --gid $gid --uid $uid $user && usermod -a -G $user $user
USER $user
ENV PATH="/home/py4web/.local/bin:${PATH}"
RUN python3 -m pip install -U py4web psycopg2-binary bottle
# psycopg2-binary for Postgres
WORKDIR /home/$user/
RUN py4web setup --yes apps && rm -rf apps/_minimal; rm -rf apps/_default; rm -rf apps/_scaffold; rm -rf apps/_documentation
EXPOSE 8000
./app_name/DockerfileFROM py4web_light:latest
USER root
ARG app=app_name
ARG user=py4web
USER $user
# support for debugging (remove in production Dockerfile)
RUN python3 -m pip install debugpy
EXPOSE 5678
# app sources
USER $user
WORKDIR /home/$user/
COPY --chown=$user:$user ./files_copy .
RUN mkdir apps/$app && mkdir apps/$app/databases && mkdir apps/$app/uploads && chown $user apps/$app apps/$app/databases apps/$app/uploads
CMD ./mypy4web.py run --password_file /home/py4web/encrypted_password.txt --host 0.0.0.0 --port 8000 --watch=lazy apps
./app_name/mypy4web.py#!/usr/bin/python3
import debugpy
from py4web.core import cli
print("Debugpy launched ...")
debugpy.listen(("0.0.0.0", 5678))
print("Py4web starting ...")
cli()
./app_name/docker_compose.ymlversion: "3.4"
services:
app_name:
image: ${APP_NAME}:latest
build:
context: .
dockerfile: ./Dockerfile
ports:
- "127.0.0.1:${APP_EXP_PORT}:8000"
env_file:
- .env
stdin_open: true
tty: true
depends_on:
- postgres
volumes:
- app_source_vol:/home/py4web/apps/${APP_NAME}
- app_vscode_vol:/home/py4web/.vscode
- app_db_vol:/home/py4web/apps/${APP_NAME}/databases
- app_upload_vol:/home/py4web/apps/${APP_NAME}/uploads
# todo: logs
postgres:
#restart: always
image: postgres
env_file:
- .env
ports:
- "127.0.0.1:${POSTGRES_EXP_PORT}:5432"
volumes:
- postgresvol:/var/lib/postgresql/data
volumes:
postgresvol:
driver: local
app_source_vol:
driver: local
driver_opts:
type: none
o: bind
device: ${BASEDIR}/${APP_NAME}/files_src
app_vscode_vol:
driver: local
driver_opts:
type: none
o: bind
device: ${BASEDIR}/${APP_NAME}/.vscode_remote
app_db_vol:
driver: local
app_upload_vol:
driver: local
./app_name/.envAPP_NAME=app_name
APP_EXP_PORT=9901
APP_SESSION_SECRET_KEY=48fg7aaf-adac-11eb-b3d6-ffa44fa48733
POSTGRES_EXP_PORT=5901
POSTGRES_DB=app_name
APP_PYDAL_URI=postgres://db_user:db_pwd@postgres:5432/app_name
#appsettings
APP_USE_AUTH=False
APP_DB_POOL_SIZE=1
APP_DB_MIGRATE=True
APP_DB_FAKE_MIGRATE=False
APP_VERIFY_EMAIL=True
APP_REQUIRES_APPROVAL=False
APP_DEFAULT_LOGIN_ENABLED=False
APP_OAUTH2GOOGLE_CLIENT_ID=None
APP_OAUTH2GOOGLE_CLIENT_SECRET=None
APP_OAUTH2OKTA_CLIENT_ID=None
APP_OAUTH2OKTA_CLIENT_SECRET=None
APP_OAUTH2FACEBOOK_CLIENT_ID=None
APP_OAUTH2FACEBOOK_CLIENT_SECRET=None
APP_SESSION_TYPE=None
#APP_SESSION_TYPE = cookies / redis / memcache
#postgres
POSTGRES_USER=db_user
POSTGRES_PASSWORD=db_pwd
POSTGRES_PORT=5432
#main
SMTP_SERVER=
smtp.domain.xyz:25SMTP_LOGIN=mail_user:mail_pwd
SMTP_SENDER=
ad...@domain.xyzSMTP_TLS=False
SMTP_SSL=False
BASEDIR=/path/to/sources
./app_name/.vscode_remote/launch.json{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Remote Attach via 5678",
"type": "python",
"request": "attach",
"connect": {
"host": "127.0.0.1",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/home/py4web"
}
]
},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
]
}
David