Skip to content

Updates for Spring 2025 #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Mar 15, 2025
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: 3 additions & 4 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ RUN cd /tmp; bash ./install-tools.sh

# Set up the Python development environment
WORKDIR /app
COPY pyproject.toml poetry.lock ./
RUN sudo python -m pip install -U pip poetry && \
sudo poetry config virtualenvs.create false && \
sudo poetry install
COPY Pipfile Pipfile.lock ./
RUN python -m pip install --upgrade pip pipenv && \
pipenv install --system --dev
11 changes: 7 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"Rofrano",
"sqlalchemy",
"psycopg",
"wsgi",
"dotenv",
"pytest",
"tekton",
"creds",
Expand All @@ -24,6 +26,7 @@
"git.mergeEditor": true,
"markdown-preview-github-styles.colorTheme": "light",
"makefile.extensionOutputFolder": "/tmp",
"makefile.configureOnOpen": false,
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
Expand All @@ -49,6 +52,8 @@
"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",
Expand All @@ -61,14 +66,11 @@
"github.vscode-github-actions",
"hbenl.vscode-test-explorer",
"LittleFoxTeam.vscode-python-test-adapter",
"njpwerner.autodocstring",
"wholroyd.jinja",
"redhat.vscode-yaml",
"redhat.fabric8-analytics",
"unjinjang.rest-api-client",
"ms-azuretools.vscode-docker",
"ms-kubernetes-tools.vscode-kubernetes-tools",
"inercia.vscode-k3d",
"rangav.vscode-thunder-client",
"alexkrechik.cucumberautocomplete",
"Zignd.html-css-class-completion",
"streetsidesoftware.code-spell-checker",
Expand All @@ -77,6 +79,7 @@
}
},
// Setup the lab environment after container is created
"forwardPorts": [8080],
"postCreateCommand": "bash /app/.devcontainer/scripts/setup-lab.sh",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
Expand Down
4 changes: 4 additions & 0 deletions .devcontainer/scripts/setup-lab.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# Setup the lab environment after container is started using:
# "postCreateCommand": "bash /app/.devcontainer/scripts/setup-lab.sh"
#
echo "**********************************************************************"
echo "Setting up Flask BDD lab environment..."
echo "**********************************************************************\n"

# Create .env file if it doesn't exist
if [ ! -f .env ]; then
Expand All @@ -20,4 +22,6 @@ sudo bash -c "echo '127.0.0.1 cluster-registry' >> /etc/hosts"
# Make git stop complaining about unsafe folders
git config --global --add safe.directory /app

echo "\n**********************************************************************"
echo "Setup complete"
echo "**********************************************************************"
7 changes: 3 additions & 4 deletions .github/workflows/bdd-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ on:
jobs:
build:
runs-on: ubuntu-latest
container: rofrano/pipeline-selenium:latest
container: quay.io/rofrano/pipeline-selenium:sp25

services:
postgres:
Expand All @@ -41,9 +41,8 @@ jobs:

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

- name: Run the service locally
run: |
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/tdd-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ jobs:

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

- name: Run Code Quality Checks
run: |
Expand All @@ -57,10 +56,12 @@ jobs:

- name: Run unit tests with pytest
run: |
pytest --pspec --cov=service --cov-fail-under=95 --disable-warnings
pytest --pspec --cov=service --cov-fail-under=95 --disable-warnings --cov-report=xml
env:
FLASK_APP: "wsgi:app"
DATABASE_URI: "postgresql+psycopg://postgres:pgs3cr3t@postgres:5432/testdb"

- name: Upload code coverage
uses: codecov/codecov-action@v3.1.4
with:
token: ${{ secrets.CODECOV_TOKEN }}
20 changes: 9 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
##################################################
# Create production image
##################################################
FROM python:3.11-slim
# cSpell: disable
FROM quay.io/rofrano/python:3.11-slim

# Establish a working folder
# Set up the Python production environment
WORKDIR /app
COPY Pipfile Pipfile.lock ./
RUN python -m pip install --upgrade pip pipenv && \
pipenv install --system --deploy

# 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 the application contents
COPY wsgi.py .
COPY service ./service

Expand All @@ -23,9 +21,9 @@ USER flask

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

ENV GUNICORN_BIND 0.0.0.0:$PORT
ENV GUNICORN_BIND=0.0.0.0:$PORT
ENTRYPOINT ["gunicorn"]
CMD ["--log-level=info", "wsgi:app"]
15 changes: 7 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,18 @@ clean: ## Removes all dangling build cache

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

install: ## Install Python dependencies
$(info Installing dependencies...)
poetry config virtualenvs.create false
poetry install
sudo pipenv install --system --dev

.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
-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
Expand All @@ -61,12 +60,12 @@ secret: ## Generate a secret hex key
.PHONY: cluster
cluster: ## Create a K3D Kubernetes cluster with load balancer and registry
$(info Creating Kubernetes cluster with a registry and 1 node...)
k3d cluster create nyu-devops --agents 1 --registry-create cluster-registry:0.0.0.0:5000 --port '8080:80@loadbalancer'
k3d cluster create $(CLUSTER) --agents 1 --registry-create cluster-registry:0.0.0.0:5000 --port '8080:80@loadbalancer'

.PHONY: cluster-rm
cluster-rm: ## Remove a K3D Kubernetes cluster
$(info Removing Kubernetes cluster...)
k3d cluster delete nyu-devops
k3d cluster delete $(CLUSTER)

##@ Deploy

Expand Down
37 changes: 37 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
flask = "~=3.1.0"
flask-sqlalchemy = "~=3.1.1"
psycopg = {extras = ["binary"], version = "~=3.2.4"}
retry2 = "~=0.9.5"
python-dotenv = "~=1.0.1"
gunicorn = "~=23.0.0"

[dev-packages]
honcho = "~=2.0.0"
httpie = "~=3.2.4"

# Code Quality
pylint = "~=3.3.4"
flake8 = "~=7.1.1"
black = "~=25.1.0"

# Test-Driven Development
pytest = "~=8.3.4"
pytest-pspec = "~=0.0.4"
pytest-cov = "~=6.0.0"
factory-boy = "~=3.3.3"
coverage = "~=7.6.12"

# Behavior-Driven Development
behave = "~=1.2.6"
selenium = "==4.16.0" # newer versions do not work
requests = "~=2.31.0"
compare3 = "~=1.0.4"

[requires]
python_version = "3.11"
Loading