Skip to content

Commit

Permalink
Merge pull request #36 from nyu-devops/su24-updates
Browse files Browse the repository at this point in the history
Updates for Summer 2024 Semester
  • Loading branch information
rofrano authored Jun 16, 2024
2 parents bd0d253 + 93937a2 commit a118eef
Show file tree
Hide file tree
Showing 14 changed files with 553 additions and 421 deletions.
8 changes: 5 additions & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM python:3.11-slim

# 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 install -y sudo vim make git zip tree curl wget jq procps net-tools && \
apt-get autoremove -y && \
apt-get clean -y

Expand All @@ -17,10 +17,12 @@ 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

# Install poetry stand alone
# RUN curl -sSL https://install.python-poetry.org | python3 -
# RUN curl -sSL https://install.python-poetry.org | python3 - && \
# poetry config virtualenvs.create false

# Set up the Python development environment
WORKDIR /app
Expand Down
18 changes: 12 additions & 6 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
"customizations": {
"vscode": {
"settings": {
"cSpell.words": [
"sqlalchemy",
"psycopg",
"pytest",
"onupdate",
"testdb"
],
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
Expand All @@ -30,27 +37,26 @@
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"VisualStudioExptTeam.vscodeintellicode",
"ms-python.pylint",
"ms-python.flake8",
"ms-python.black-formatter",
"njpwerner.autodocstring",
"wholroyd.jinja",
"ms-vscode.makefile-tools",
"yzhang.markdown-all-in-one",
"hnw.vscode-auto-open-markdown-preview",
"davidanson.vscode-markdownlint",
"bierner.github-markdown-preview",
"hnw.vscode-auto-open-markdown-preview",
"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",
"wholroyd.jinja",
"redhat.vscode-yaml",
"rangav.vscode-thunder-client",
"redhat.fabric8-analytics",
"streetsidesoftware.code-spell-checker",
"ms-azuretools.vscode-docker",
"redhat.fabric8-analytics",
"github.vscode-github-actions",
"streetsidesoftware.code-spell-checker",
"bbenoist.vagrant"
Expand Down
3 changes: 2 additions & 1 deletion .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
FLASK_APP: wsgi:app
FLASK_DEBUG: "True"
GUNICORN_BIND: "0.0.0.0:8000"
DATABASE_URI: postgresql+psycopg://postgres:pgs3cr3t@postgres:5432/postgres
DATABASE_URI: postgresql+psycopg://postgres:pgs3cr3t@postgres:5432/petstore
networks:
- dev
depends_on:
Expand All @@ -28,6 +28,7 @@ services:
# - 5432:5432
environment:
POSTGRES_PASSWORD: pgs3cr3t
POSTGRES_DB: petstore
volumes:
- postgres:/var/lib/postgresql/data
networks:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
poetry config virtualenvs.create false
poetry install
- name: Linting
- name: Run Code Quality Checks
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
Expand All @@ -57,11 +57,11 @@ jobs:
# Run pylint on the service
pylint service tests --max-line-length=127
- name: Run unit tests with green
- name: Run unit tests with pytest
run: |
export FLASK_APP=service:app
pytest --pspec --cov=service --cov-fail-under=95 --disable-warnings
env:
FLASK_APP: "wsgi:app"
DATABASE_URI: "postgresql+psycopg://postgres:pgs3cr3t@postgres:5432/testdb"

- name: Upload code coverage
Expand Down
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,37 @@ all: help

##@ Development

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

.PHONY: install
install: ## Install Python dependencies
$(info Installing dependencies...)
poetry config virtualenvs.create false
poetry 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 --disable-warnings
export RETRY_COUNT=1; pytest --pspec --cov=service --cov-fail-under=95 --disable-warnings

db-create: ## Creates the database tables
.PHONY: db-init
db-init: ## Initializes the database tables
$(info Creating database tables...)
@flask db-create

##@ Runtime

.PHONY: run
run: ## Run the service
$(info Starting service...)
honcho start
5 changes: 4 additions & 1 deletion lab/status.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# HTTP status codes
"""
HTTP status codes
"""

HTTP_200_OK = 200
HTTP_201_CREATED = 201
HTTP_204_NO_CONTENT = 204
Expand Down
1 change: 1 addition & 0 deletions lab/test_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- The API must be RESTful.
- The endpoint must be called `/counters`.
- When creating a counter, you must specify the name in the path.
- The data returned should be this {"name":"some_name", "counter:0}
- Duplicate names must return a 409 conflict error code.
- The service must be able to update a counter by name.
- The service must be able to get a counter's current value.
Expand Down
Loading

0 comments on commit a118eef

Please sign in to comment.