Add Docker dev environment and initial code

This commit is contained in:
Lexi / Zoe 2022-03-25 20:03:33 +01:00
parent 484b0210bb
commit 0be947b3d1
Signed by: binaryDiv
GPG Key ID: F8D4956E224DA232
10 changed files with 173 additions and 150 deletions

164
.gitignore vendored
View File

@ -1,154 +1,22 @@
# ---> Python # IDEs / editors
# Byte-compiled / optimized / DLL files .idea/
.vscode/
# General
/tmp
/_tmp
.cache
# Python
__pycache__/ __pycache__/
*.py[cod] *.py[cod]
*$py.class
# C extensions # Python packaging and dev environments
*.so /.pip
/venv
# Distribution / packaging # Python testing
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage .coverage
.coverage.* .coverage.*
.cache .pytest_cache
nosetests.xml .tox/
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

22
Dockerfile.dev Normal file
View File

@ -0,0 +1,22 @@
FROM python:3.10
# Install pipenv container-wide as root
RUN pip install pipenv
# Create unprivileged user with UID as specified by the build argument DEV_USER_UID, defaulting to 1000.
# (This should match the UID of your local user. If it doesn't, use an ".env" file to overwrite this variable.)
ARG DEV_USER_UID=1000
RUN echo Creating dev user with UID $DEV_USER_UID && \
useradd -m -u $DEV_USER_UID dev
USER dev
## Create virtual environment using pipenv
WORKDIR /app
COPY Pipfile Pipfile.lock ./
RUN pipenv install --dev --deploy
# Set entrypoint to always run commands inside virtual environment
ENTRYPOINT ["pipenv", "run"]
# Set default command
CMD ["bash"]

View File

47
Makefile Normal file
View File

@ -0,0 +1,47 @@
# Define variables
DOCKER_COMPOSE = docker-compose
DOCKER_RUN = $(DOCKER_COMPOSE) run --rm backend
# Default target
.PHONY: all
all: docker-up
# Container management
# --------------------
.PHONY: docker-up
docker-up:
$(DOCKER_COMPOSE) up --build
.PHONY: docker-down
docker-down:
$(DOCKER_COMPOSE) down
.PHONY: docker-build
docker-build:
$(DOCKER_COMPOSE) build
.PHONY: docker-rebuild
docker-rebuild:
$(DOCKER_COMPOSE) build --pull --no-cache
.PHONY: docker-purge
docker-purge:
$(DOCKER_COMPOSE) down --volumes
.PHONY: docker-restart
docker-restart:
$(DOCKER_COMPOSE) restart $(SERVICE)
.PHONY: docker-logs
docker-logs:
$(DOCKER_COMPOSE) logs -f $(SERVICE) || true
.PHONY: docker-run
docker-run:
$(DOCKER_RUN) "$(CMD)"
.PHONY: docker-shell
docker-shell:
$(DOCKER_RUN) bash

13
Pipfile Normal file
View File

@ -0,0 +1,13 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
gunicorn = "~=20.1"
werkzeug = "~=2.0"
[dev-packages]
[requires]
python_version = "3.10"

45
Pipfile.lock generated Normal file
View File

@ -0,0 +1,45 @@
{
"_meta": {
"hash": {
"sha256": "574b2898e332128ecb874d71081cf7a8c62e4e219a603d0d76a5d9afb3ac164c"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.10"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {
"gunicorn": {
"hashes": [
"sha256:9dcc4547dbb1cb284accfb15ab5667a0e5d1881cc443e0677b4882a4067a807e",
"sha256:e0a968b5ba15f8a328fdfd7ab1fcb5af4470c28aaf7e55df02a99bc13138e6e8"
],
"index": "pypi",
"version": "==20.1.0"
},
"setuptools": {
"hashes": [
"sha256:6221e37dc86fcdc9dad9d9eb2002e9f9798fe4aca1bf18f280e66e50c0eb7fca",
"sha256:ad88b13f3dc60420259c9877486908ddad12c7befaff0d624c7190f742abd64f"
],
"markers": "python_version >= '3.7'",
"version": "==61.0.0"
},
"werkzeug": {
"hashes": [
"sha256:1421ebfc7648a39a5c58c601b154165d05cf47a3cd0ccb70857cbdacf6c8f2b8",
"sha256:b863f8ff057c522164b6067c9e28b041161b4be5ba4d0daceeaa50a163822d3c"
],
"index": "pypi",
"version": "==2.0.3"
}
},
"develop": {}
}

View File

@ -1,3 +1,3 @@
# tofu-api # Tofu - REST API
REST API backend for Tofu - a to-do list app with a twist. REST API backend for Tofu - a to-do list app with a twist.

18
docker-compose.yml Normal file
View File

@ -0,0 +1,18 @@
version: '3'
services:
backend:
build:
context: .
dockerfile: Dockerfile.dev
args:
# Use an ".env" file to overwrite this variable if your local user's UID is not 1000.
DEV_USER_UID: ${DEV_USER_UID:-1000}
ports:
- '8080:8080'
volumes:
- ./:/app/
command: gunicorn --bind=0.0.0.0:8080 --reload tofu_api.app:app
volumes:
mariadb_data:

0
tofu_api/__init__.py Normal file
View File

10
tofu_api/app.py Normal file
View File

@ -0,0 +1,10 @@
def app(environ, start_response):
"""Simplest possible application object"""
data = b'Hello, wooorld!\n'
status = '200 OK'
response_headers = [
('Content-type', 'text/plain'),
('Content-Length', str(len(data)))
]
start_response(status, response_headers)
return iter([data])