Skip to content
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

Updates for Spring 2024 Semester #10

Merged
merged 7 commits into from
Feb 24, 2024
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
12 changes: 7 additions & 5 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FROM rofrano/nyu-devops-base:sp23
# Image for a NYU Lab development environment
FROM rofrano/nyu-devops-base:sp24

# Add Python package requiremnets to the dev environment
# Set up the Python development environment
WORKDIR /app
COPY requirements.txt .
RUN sudo pip install -U pip wheel && \
sudo pip install -r requirements.txt
COPY pyproject.toml poetry.lock ./
RUN sudo python -m pip install --upgrade pip poetry && \
sudo poetry config virtualenvs.create false && \
sudo poetry install
40 changes: 32 additions & 8 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,50 @@
"remoteUser": "vscode",
"customizations": {
"vscode": {
"settings": {
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": 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,
"**/*.pyc": true,
"**/__pycache__": true,
"**/.pytest_cache": true
}
},
"extensions": [
"VisualStudioExptTeam.vscodeintellicode",
"ms-python.python",
"ms-python.pylint",
"ms-python.vscode-pylance",
"alexkrechik.cucumberautocomplete",
"cstrap.flask-snippets",
"ms-python.flake8",
"ms-python.black-formatter",
"ms-vscode.makefile-tools",
"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",
"github.vscode-github-actions",
"hbenl.vscode-test-explorer",
"LittleFoxTeam.vscode-python-test-adapter",
"njpwerner.autodocstring",
"redhat.vscode-yaml",
"streetsidesoftware.code-spell-checker",
"wholroyd.jinja",
"bbenoist.vagrant"
"redhat.vscode-yaml",
"ms-azuretools.vscode-docker",
"rangav.vscode-thunder-client",
"bbenoist.vagrant",
"streetsidesoftware.code-spell-checker"
]
}
}
Expand Down
11 changes: 6 additions & 5 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@ services:
- ..:/app
command: sleep infinity
environment:
FLASK_APP: service:app
FLASK_DEBUG: "true"
PORT: 8000
FLASK_APP: wsgi:app
FLASK_DEBUG: "True"
GUNICORN_BIND: "0.0.0.0:8000"
DATABASE_URI: postgresql://postgres:postgres@postgres:5432/postgres
DATABASE_URI: postgresql+psycopg://postgres:pgs3cr3t@postgres:5432/postgres
networks:
- dev
depends_on:
- postgres

postgres:
image: postgres:alpine
image: postgres:15-alpine
# ports:
# - 5432:5432
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_PASSWORD: pgs3cr3t
volumes:
- postgres:/var/lib/postgresql/data
networks:
Expand Down
2 changes: 1 addition & 1 deletion .flaskenv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FLASK_RUN_PORT=8000
FLASK_APP=service:app
FLASK_APP=wsgi:app
8 changes: 5 additions & 3 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
**I need** ...
**So that** ...

**Assumptions:**
### Assumptions

* ...

**Acceptance Criteria:**
```
### Acceptance Criteria

```gherkin
Given ...
When ...
Then ...
Expand Down
33 changes: 12 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
build:
runs-on: ubuntu-latest
# use a known build environment
container: python:3.9-slim
container: python:3.11-slim

# Required services
services:
Expand All @@ -38,35 +38,26 @@ jobs:
# Steps for the build
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Install libraries for PostgreSQL
run: |
apt-get update
apt-get install -y gcc libpq-dev

- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
python -m pip install poetry
poetry config virtualenvs.create false
poetry install

- name: Linting
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 service --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 service --count --max-complexity=10 --max-line-length=127 --statistics
# Run pylint on the service
pylint service --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

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

- name: Upload code coverage
uses: codecov/codecov-action@v2
with:
version: "v0.1.13"
uses: codecov/[email protected]
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "service:app",
"FLASK_APP": "wsgi:app",
"FLASK_ENV": "development"
},
"args": [
Expand Down
29 changes: 5 additions & 24 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
{
"python.pythonPath": "/usr/local/bin/python",
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.testing.nosetestsEnabled": true,
"python.testing.nosetestArgs": ["-c=setup.cfg"],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true,
"python.testing.unittestArgs": [
"-v",
"-s",
"./tests",
"-p",
"test*.py"
],
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/*.pyc": true,
"**/__pycache__": true
}
}
"cSpell.words": [
"sqlalchemy",
"psycopg"
]
}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"label": "TDD tests",
"type": "shell",
"command": "nosetests",
"command": "pytest",
"group": {
"kind": "test",
"isDefault": true
Expand Down
39 changes: 30 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,49 @@
.PHONY: all help install venv test run
# These can be overidden with env vars.
CLUSTER ?= nyu-devops

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)
.SILENT:

.PHONY: help
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: ## Removes all dangling docker images
$(info Removing all dangling docker images..)
docker image prune -f

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

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

.PHONY: lint
lint: ## Run the linter
$(info Running linting...)
flake8 service --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 service --count --max-complexity=10 --max-line-length=127 --statistics
pylint service --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: tests
test: ## Run the unit tests
$(info Running tests...)
nosetests --with-spec --spec-color
pytest --pspec --cov=service --cov-fail-under=95

##@ Runtime

.PHONY: run
run: ## Run the service
$(info Starting service...)
honcho start
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: gunicorn --workers=1 --bind 0.0.0.0:$PORT --log-level=info service:app
web: gunicorn --workers=1 --bind 0.0.0.0:$PORT --log-level=info wsgi:app
2 changes: 1 addition & 1 deletion dot-env-example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Copy this file to .env to expose these environment variables
FLASK_APP=service:app
FLASK_APP=wsgi:app
Loading
Loading