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
19 changes: 10 additions & 9 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# cspell: disable
# Image for a Python 3 development environment
FROM python:3.11-slim

# Add any tools that are needed beyond Python 3.9
# Add any tools that are needed beyond Python 3.11
RUN apt-get update && \
apt-get install -y sudo vim make git zip tree curl wget jq && \
apt-get install -y sudo vim make git zip tree curl wget jq procps net-tools && \
apt-get autoremove -y && \
apt-get clean -y

Expand All @@ -12,21 +13,21 @@ ARG USERNAME=devops
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Create the user with passwordless sudo privileges
# Create the user with password-less sudo privileges
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME -s /bin/bash \
&& usermod -aG sudo $USERNAME \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME
&& chmod 0440 /etc/sudoers.d/$USERNAME \
&& chown -R $USERNAME:$USERNAME /home/$USERNAME

# Set up the Python development environment
WORKDIR /app
COPY pyproject.toml poetry.lock ./
RUN python -m pip install poetry && \
poetry config virtualenvs.create false && \
poetry install
COPY Pipfile Pipfile.lock ./
RUN python -m pip install -U pip pipenv && \
pipenv install --system --dev

ENV PORT 8000
ENV PORT=8000
EXPOSE $PORT

# Enable color terminal for docker exec bash
Expand Down
22 changes: 16 additions & 6 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
"customizations": {
"vscode": {
"settings": {
"cSpell.words": [
"wsgi",
"pytest",
"Redis",
"testdb"
],
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
Expand All @@ -33,21 +39,25 @@
"ms-python.pylint",
"ms-python.flake8",
"ms-python.black-formatter",
"njpwerner.autodocstring",
"wholroyd.jinja",
"ms-vscode.makefile-tools",
"yzhang.markdown-all-in-one",
"davidanson.vscode-markdownlint",
"bierner.github-markdown-preview",
"hnw.vscode-auto-open-markdown-preview",
"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",
"redhat.vscode-yaml",
"rangav.vscode-thunder-client",
"streetsidesoftware.code-spell-checker",
"wholroyd.jinja",
"ms-azuretools.vscode-docker"
"unjinjang.rest-api-client",
"ms-azuretools.vscode-docker",
"github.vscode-github-actions",
"streetsidesoftware.code-spell-checker",
"bbenoist.vagrant"
]
}
}
Expand Down
4 changes: 2 additions & 2 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ services:
environment:
FLASK_APP: wsgi:app
FLASK_DEBUG: "True"
GUNICORN_BIND: "0.0.0.0:8000"
PORT: 8000
GUNICORN_BIND: "0.0.0.0:8080"
PORT: 8080
DATABASE_URI: "redis://redis:6379"
networks:
- dev
Expand Down
16 changes: 7 additions & 9 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Install dependencies
- name: Install Python package dependencies
run: |
python -m pip install poetry
poetry config virtualenvs.create false
poetry install
python -m pip install -U pip pipenv
pipenv install --system --dev

- name: Linting
run: |
Expand All @@ -53,8 +52,7 @@ jobs:
# Create a CODECOV_TOKEN in Settings->Secrets and variables->Actions
# and then uncomment the CodeCov action during hands-on lab

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3.1.4
with:
token: ${{ secrets.CODECOV_TOKEN }}

# - name: Upload coverage reports to Codecov
# uses: codecov/codecov-action@v3.1.4
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
11 changes: 5 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ 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

# Establish dependencies without dev tools
COPY Pipfile Pipfile.lock ./
RUN python -m pip install -U pip pipenv && \
pipenv install --system

# Copy source files last because they change the most
COPY wsgi.py .
COPY service ./service
Expand Down
19 changes: 14 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
.PHONY: all help install venv test run

help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-\\.]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

.PHONY: all
all: help

##@ Development

.PHONY: clean
clean: ## Clean up test files
$(info Cleaning up test files...)
-rm .coverage coverage.xml unittests.xml
-rm -fr .pytest_cache dist build

.PHONY: venv
venv: ## Create a Python virtual environment
$(info Creating Python 3 virtual environment...)
poetry config virtualenvs.in-project true
poetry shell
PIPENV_VENV_IN_PROJECT=1 pipenv shell

.PHONY: install
install: ## Install dependencies
$(info Installing dependencies...)
poetry install
PIPENV_VENV_IN_PROJECT=1 pipenv install

.PHONY: lint
lint: ## Run the linter
$(info Running linting...)
flake8 service tests --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 service tests --count --max-complexity=10 --max-line-length=127 --statistics
pylint service tests --max-line-length=127

.PHONY: test
test: ## Run the unit tests
$(info Running tests...)
pytest --pspec --cov=service --cov-fail-under=95

##@ Runtime

.PHONY: run
run: ## Run the service
$(info Starting service...)
honcho start
27 changes: 27 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
flask = "==3.1.0"
retry2 = "==0.9.5"
python-dotenv = "==1.0.1"
gunicorn = "==23.0.0"
redis = "==5.2.1"
flask-redis = "==0.4.0"

[dev-packages]
honcho = "~=2.0.0"
pylint = "~=3.3.4"
flake8 = "~=7.1.1"
black = "~=25.1.0"
pytest = "~=8.3.4"
pytest-pspec = "~=0.0.4"
pytest-cov = "~=6.0.0"
factory-boy = "~=3.3.3"
coverage = "~=7.6.12"
httpie = "~=3.2.4"

[requires]
python_version = "3.11"
Loading