Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ RUN groupadd --gid $USER_GID $USERNAME \

# Set up the Python development environment
WORKDIR /app
COPY requirements.txt .
RUN python -m pip install --upgrade pip wheel && \
pip install -r requirements.txt
COPY pyproject.toml poetry.lock ./
RUN python -m pip install -U pip poetry && \
poetry config virtualenvs.create false && \
poetry install

ENV PORT 8080
EXPOSE $PORT
Expand Down
23 changes: 19 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
},
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true,
"pylint.lintOnChange": true,
"markdown-preview-github-styles.colorTheme": "light",
"makefile.extensionOutputFolder": "/tmp",
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"tests"
],
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
Expand All @@ -28,17 +31,29 @@
"VisualStudioExptTeam.vscodeintellicode",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.pylint",
"ms-python.flake8",
"ms-python.black-formatter",
"cstrap.flask-snippets",
"yzhang.markdown-all-in-one",
"bierner.github-markdown-preview",
"hnw.vscode-auto-open-markdown-preview",
"DavidAnson.vscode-markdownlint",
"davidanson.vscode-markdownlint",
"bierner.markdown-preview-github-styles",
"tamasfe.even-better-toml",
"donjayamanne.githistory",
"GitHub.vscode-pull-request-github",
"hbenl.vscode-test-explorer",
"LittleFoxTeam.vscode-python-test-adapter",
"njpwerner.autodocstring",
"wholroyd.jinja",
"redhat.vscode-yaml",
"rangav.vscode-thunder-client",
"redhat.fabric8-analytics",
"streetsidesoftware.code-spell-checker",
"ms-azuretools.vscode-docker",
"github.vscode-github-actions",
"streetsidesoftware.code-spell-checker",
"bbenoist.vagrant"
]
}
Expand Down
2 changes: 2 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ services:
- ..:/app
command: sleep infinity
environment:
FLASK_APP: wsgi:app
FLASK_DEBUG: "True"
CLOUDANT_HOST: couchdb
CLOUDANT_PORT: 5984
CLOUDANT_USERNAME: ${CLOUDANT_USERNAME:-admin}
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,22 @@ jobs:

- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel
pip install -r requirements.txt
python -m pip install -U pip poetry
poetry config virtualenvs.create false
poetry install

- name: Create the test database
run: |
apt-get update
apt-get install -y curl
curl -X PUT http://admin:pass@couchdb:5984/test

- name: Run unit tests with green
run: green
- name: Run unit tests with pytest
run: pytest --pspec --cov=service --cov-fail-under=95 --disable-warnings
env:
FLASK_APP: "wsgi:app"
BINDING_CLOUDANT: '{"username":"admin","password":"pass","host":"couchdb","port":5984,"url":"http://admin:pass@couchdb:5984"}'

- name: Upload code coverage
uses: codecov/codecov-action@v3.1.4

4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "service:app",
"FLASK_ENV": "development"
"FLASK_APP": "wsgi:app",
"FLASK_DEBUG": "True"
},
"args": [
"run",
Expand Down
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
##################################################
# Create production image
##################################################
FROM python:3.11-slim

# Establish a working folder
WORKDIR /app

# Establish dependencies
COPY pyproject.toml poetry.lock ./
RUN python -m pip install poetry && \
poetry config virtualenvs.create false && \
poetry install --without dev

# Copy source files last because they change the most
COPY wsgi.py .
COPY service ./service

# Switch to a non-root user and set file ownership
RUN useradd --uid 1001 flask && \
chown -R flask:flask /app
USER flask

# Expose any ports the app is expecting in the environment
ENV FLASK_APP=wsgi:app
ENV PORT 8080
EXPOSE $PORT

ENV GUNICORN_BIND 0.0.0.0:$PORT
ENTRYPOINT ["gunicorn"]
CMD ["--log-level=info", "wsgi:app"]
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ all: help

venv: ## Create a Python virtual environment
$(info Creating Python 3 virtual environment...)
python3 -m venv .venv
poetry shell

install: ## Install Python dependencies
$(info Installing dependencies...)
sudo pip install -r requirements.txt
poetry config virtualenvs.create false
poetry install

lint: ## Run the linter
$(info Running linting...)
Expand All @@ -26,7 +27,7 @@ lint: ## Run the linter

test: ## Run the unit tests
$(info Running tests...)
green -vvv --processes=1 --run-coverage --termcolor --minimum-coverage=95
pytest

##@ Runtime

Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: gunicorn --bind 0.0.0.0:$PORT --log-level=info service:app
web: gunicorn --bind 0.0.0.0:$PORT --log-level=info wsgi:app
Loading