Skip to content

Updates for the Spring 2025 Semester #33

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 6 commits into from
Mar 22, 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
35 changes: 5 additions & 30 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,11 @@
# Image for a Python 3 development environment
FROM python:3.11-slim

# 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 procps net-tools && \
apt-get autoremove -y && \
apt-get clean -y

# Create a user for development
ARG USERNAME=devops
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Create the user with passwordless 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
FROM rofrano/nyu-devops-base:sp25

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

ENV PORT 8080
ENV PORT=8080
EXPOSE $PORT

# Enable color terminal for docker exec bash
ENV TERM=xterm-256color

# Become a regular user
USER $USERNAME
17 changes: 12 additions & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/app",
"remoteUser": "devops",
"remoteUser": "vscode",
"customizations": {
"vscode": {
"settings": {
"cSpell.words": [
"sqlalchemy",
"psycopg",
"wsgi",
"Coudant",
"CLOUDANT",
"DBNAME",
"petshop",
"pytest",
"restplus",
"RESTX",
"CSCI",
"pipenv",
"virtualenvs"
],
"[python]": {
Expand Down Expand Up @@ -47,8 +54,8 @@
"cstrap.flask-snippets",
"ms-vscode.makefile-tools",
"yzhang.markdown-all-in-one",
"bierner.github-markdown-preview",
"davidanson.vscode-markdownlint",
"bierner.github-markdown-preview",
"hnw.vscode-auto-open-markdown-preview",
"bierner.markdown-preview-github-styles",
"tamasfe.even-better-toml",
Expand All @@ -57,7 +64,7 @@
"hbenl.vscode-test-explorer",
"LittleFoxTeam.vscode-python-test-adapter",
"redhat.vscode-yaml",
"rangav.vscode-thunder-client",
"unjinjang.rest-api-client",
"ms-azuretools.vscode-docker",
"github.vscode-github-actions",
"streetsidesoftware.code-spell-checker",
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
depends_on:
- couchdb

# CouchDB Dashboard: http://127.0.0.1:5984/_utils"
# The CouchDB Dashboard is at: http://127.0.0.1:5984/_utils"
couchdb:
image: couchdb:latest
hostname: couchdb
Expand Down
30 changes: 22 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,22 @@ jobs:
--health-retries 5

steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v3

- name: Install Python package dependencies
run: |
python -m pip install -U pip pipenv
pipenv install --system --dev

- name: Install dependencies
- name: Run Code Quality Checks
run: |
python -m pip install -U pip poetry
poetry config virtualenvs.create false
poetry install
# stop the build if there are Python syntax errors or undefined names
flake8 service tests --count --select=E9,F63,F7,F82 --show-source --statistics
# check for complexity. The GitHub editor is 127 chars wide
flake8 service tests --count --max-complexity=10 --max-line-length=127 --statistics
# Run pylint on the service
pylint service tests --max-line-length=127

- name: Create the test database
run: |
Expand All @@ -49,11 +58,16 @@ jobs:
curl -X PUT http://admin:pass@couchdb:5984/test

- name: Run unit tests with pytest
run: pytest --pspec --cov=service --cov-fail-under=95 --disable-warnings
run: pytest --pspec --cov=service --cov-fail-under=95 --disable-warnings --cov-report=xml
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
- name: Install packages required by Codecov
run: apt-get update && apt-get install -y git curl gpg

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: nyu-devops/lab-flask-restplus-swagger
11 changes: 5 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ 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 .
Expand All @@ -23,7 +22,7 @@ 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
Expand Down
28 changes: 28 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
flask = "==3.1.0"
flask-restx = "==1.3.0"
cloudant = "==2.15.0"
urllib3 = "==1.26.19" # DO NOT upgrade this!
retry2 = "==0.9.5"
python-dotenv = "==1.0.1"
gunicorn = "==23.0.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