Skip to content

Commit

Permalink
Merge pull request #28 from nyu-devops/updates-sp24
Browse files Browse the repository at this point in the history
Updates for Spring 2024 Semester
  • Loading branch information
rofrano committed Feb 4, 2024
2 parents 293120a + f4186e0 commit ea19423
Show file tree
Hide file tree
Showing 28 changed files with 1,731 additions and 359 deletions.
42 changes: 37 additions & 5 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
FROM rofrano/nyu-devops-base:fa23
# Image for a Python 3 development environment
FROM python:3.11-slim

# Add Python package requiremnets to the dev environment
# Add any tools that are needed beyond Python 3.9
RUN apt-get update && \
apt-get install -y sudo vim make git zip tree curl wget jq && \
apt-get autoremove -y && \
apt-get clean -y

# Create a user for development
ARG USERNAME=vscode
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

# Install poetry stand alone
# RUN curl -sSL https://install.python-poetry.org | python3 -

# 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 python -m pip install -U pip poetry && \
poetry config virtualenvs.create false && \
poetry install

ENV PORT 8000
EXPOSE $PORT

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

# Become a regular user
USER $USERNAME
34 changes: 22 additions & 12 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// spell: disable
{
"name": "Python 3 & PostgeSQL",
"name": "Lab TDD",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/app",
Expand All @@ -12,9 +12,13 @@
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
},
"python.linting.enabled": true,
"python.linting.pylintEnabled": 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 @@ -24,27 +28,33 @@
}
},
"extensions": [
"VisualStudioExptTeam.vscodeintellicode",
"ms-python.python",
"ms-python.pylint",
"ms-python.vscode-pylance",
"cstrap.flask-snippets",
"VisualStudioExptTeam.vscodeintellicode",
"ms-python.pylint",
"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",
"hbenl.vscode-test-explorer",
"LittleFoxTeam.vscode-python-test-adapter",
"njpwerner.autodocstring",
"github.vscode-github-actions",
"rangav.vscode-thunder-client",
"wholroyd.jinja",
"redhat.vscode-yaml",
"rangav.vscode-thunder-client",
"redhat.fabric8-analytics",
"streetsidesoftware.code-spell-checker",
"wholroyd.jinja",
"ms-azuretools.vscode-docker",
"github.vscode-github-actions",
"streetsidesoftware.code-spell-checker",
"bbenoist.vagrant"
]
]
}
}
//"forwardPorts": [8000],
Expand Down
6 changes: 3 additions & 3 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ services:
FLASK_APP: service: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
20 changes: 8 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
services:
# Label used to access the service container
postgres:
image: postgres
image: postgres:15-alpine
env:
POSTGRES_PASSWORD: pgs3cr3t
POSTGRES_DB: testdb
Expand All @@ -40,23 +40,19 @@ jobs:
# Steps for the build
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install libraries for PostgreSQL
run: |
apt-get update
apt-get install -y gcc libpq-dev
uses: actions/checkout@v3

- 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 -U pip 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 tests --count --select=E9,F63,F7,F82 --show-source --statistics
# check for omplexity. The GitHub editor is 127 chars wide
# 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
Expand All @@ -66,7 +62,7 @@ jobs:
export FLASK_APP=service:app
pytest --pspec --cov=service --cov-fail-under=95 --disable-warnings
env:
DATABASE_URI: "postgresql://postgres:pgs3cr3t@postgres:5432/testdb"
DATABASE_URI: "postgresql+psycopg://postgres:pgs3cr3t@postgres:5432/testdb"

- name: Upload code coverage
uses: codecov/[email protected]
20 changes: 0 additions & 20 deletions .vscode/launch.json

This file was deleted.

15 changes: 0 additions & 15 deletions .vscode/settings.json

This file was deleted.

22 changes: 0 additions & 22 deletions .vscode/tasks.json

This file was deleted.

23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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

# Become non-root user
RUN useradd -m -r service && \
chown -R service:service /app
USER service

# Run the service on port 8080
EXPOSE 8080
CMD ["gunicorn", "wsgi:app", "--bind", "0.0.0.0:8080"]
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 --disable-warnings

##@ 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 --log-file=- --workers=1 --bind=0.0.0.0:$PORT wsgi:app
Loading

0 comments on commit ea19423

Please sign in to comment.