Skip to content

Commit ea19423

Browse files
authored
Merge pull request #28 from nyu-devops/updates-sp24
Updates for Spring 2024 Semester
2 parents 293120a + f4186e0 commit ea19423

28 files changed

+1731
-359
lines changed

.devcontainer/Dockerfile

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
1-
FROM rofrano/nyu-devops-base:fa23
1+
# Image for a Python 3 development environment
2+
FROM python:3.11-slim
23

3-
# Add Python package requiremnets to the dev environment
4+
# Add any tools that are needed beyond Python 3.9
5+
RUN apt-get update && \
6+
apt-get install -y sudo vim make git zip tree curl wget jq && \
7+
apt-get autoremove -y && \
8+
apt-get clean -y
9+
10+
# Create a user for development
11+
ARG USERNAME=vscode
12+
ARG USER_UID=1000
13+
ARG USER_GID=$USER_UID
14+
15+
# Create the user with passwordless sudo privileges
16+
RUN groupadd --gid $USER_GID $USERNAME \
17+
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME -s /bin/bash \
18+
&& usermod -aG sudo $USERNAME \
19+
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
20+
&& chmod 0440 /etc/sudoers.d/$USERNAME
21+
22+
# Install poetry stand alone
23+
# RUN curl -sSL https://install.python-poetry.org | python3 -
24+
25+
# Set up the Python development environment
426
WORKDIR /app
5-
COPY requirements.txt .
6-
RUN sudo pip install -U pip wheel && \
7-
sudo pip install -r requirements.txt
27+
COPY pyproject.toml poetry.lock ./
28+
RUN python -m pip install -U pip poetry && \
29+
poetry config virtualenvs.create false && \
30+
poetry install
31+
32+
ENV PORT 8000
33+
EXPOSE $PORT
34+
35+
# Enable color terminal for docker exec bash
36+
ENV TERM=xterm-256color
37+
38+
# Become a regular user
39+
USER $USERNAME

.devcontainer/devcontainer.json

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// spell: disable
22
{
3-
"name": "Python 3 & PostgeSQL",
3+
"name": "Lab TDD",
44
"dockerComposeFile": "docker-compose.yml",
55
"service": "app",
66
"workspaceFolder": "/app",
@@ -12,9 +12,13 @@
1212
"editor.defaultFormatter": "ms-python.black-formatter",
1313
"editor.formatOnSave": true
1414
},
15-
"python.linting.enabled": true,
16-
"python.linting.pylintEnabled": true,
1715
"markdown-preview-github-styles.colorTheme": "light",
16+
"makefile.extensionOutputFolder": "/tmp",
17+
"python.testing.unittestEnabled": false,
18+
"python.testing.pytestEnabled": true,
19+
"python.testing.pytestArgs": [
20+
"tests"
21+
],
1822
"files.exclude": {
1923
"**/.git": true,
2024
"**/.DS_Store": true,
@@ -24,27 +28,33 @@
2428
}
2529
},
2630
"extensions": [
27-
"VisualStudioExptTeam.vscodeintellicode",
2831
"ms-python.python",
29-
"ms-python.pylint",
3032
"ms-python.vscode-pylance",
31-
"cstrap.flask-snippets",
33+
"VisualStudioExptTeam.vscodeintellicode",
34+
"ms-python.pylint",
35+
"ms-python.flake8",
36+
"ms-python.black-formatter",
37+
"ms-vscode.makefile-tools",
3238
"yzhang.markdown-all-in-one",
33-
"bierner.github-markdown-preview",
3439
"hnw.vscode-auto-open-markdown-preview",
35-
"DavidAnson.vscode-markdownlint",
40+
"davidanson.vscode-markdownlint",
41+
"bierner.markdown-preview-github-styles",
42+
"tamasfe.even-better-toml",
3643
"donjayamanne.githistory",
3744
"GitHub.vscode-pull-request-github",
3845
"hbenl.vscode-test-explorer",
3946
"LittleFoxTeam.vscode-python-test-adapter",
4047
"njpwerner.autodocstring",
41-
"github.vscode-github-actions",
42-
"rangav.vscode-thunder-client",
48+
"wholroyd.jinja",
4349
"redhat.vscode-yaml",
50+
"rangav.vscode-thunder-client",
51+
"redhat.fabric8-analytics",
4452
"streetsidesoftware.code-spell-checker",
45-
"wholroyd.jinja",
53+
"ms-azuretools.vscode-docker",
54+
"github.vscode-github-actions",
55+
"streetsidesoftware.code-spell-checker",
4656
"bbenoist.vagrant"
47-
]
57+
]
4858
}
4959
}
5060
//"forwardPorts": [8000],

.devcontainer/docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ services:
1616
FLASK_APP: service:app
1717
FLASK_DEBUG: "True"
1818
GUNICORN_BIND: "0.0.0.0:8000"
19-
DATABASE_URI: postgresql://postgres:postgres@postgres:5432/postgres
19+
DATABASE_URI: postgresql+psycopg://postgres:pgs3cr3t@postgres:5432/postgres
2020
networks:
2121
- dev
2222
depends_on:
2323
- postgres
2424

2525
postgres:
26-
image: postgres:alpine
26+
image: postgres:15-alpine
2727
# ports:
2828
# - 5432:5432
2929
environment:
30-
POSTGRES_PASSWORD: postgres
30+
POSTGRES_PASSWORD: pgs3cr3t
3131
volumes:
3232
- postgres:/var/lib/postgresql/data
3333
networks:

.github/workflows/ci.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
services:
2525
# Label used to access the service container
2626
postgres:
27-
image: postgres
27+
image: postgres:15-alpine
2828
env:
2929
POSTGRES_PASSWORD: pgs3cr3t
3030
POSTGRES_DB: testdb
@@ -40,23 +40,19 @@ jobs:
4040
# Steps for the build
4141
steps:
4242
- name: Checkout
43-
uses: actions/checkout@v2
44-
45-
- name: Install libraries for PostgreSQL
46-
run: |
47-
apt-get update
48-
apt-get install -y gcc libpq-dev
49-
43+
uses: actions/checkout@v3
44+
5045
- name: Install dependencies
5146
run: |
52-
python -m pip install --upgrade pip wheel
53-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
47+
python -m pip install -U pip poetry
48+
poetry config virtualenvs.create false
49+
poetry install
5450
5551
- name: Linting
5652
run: |
5753
# stop the build if there are Python syntax errors or undefined names
5854
flake8 service tests --count --select=E9,F63,F7,F82 --show-source --statistics
59-
# check for omplexity. The GitHub editor is 127 chars wide
55+
# check for complexity. The GitHub editor is 127 chars wide
6056
flake8 service tests --count --max-complexity=10 --max-line-length=127 --statistics
6157
# Run pylint on the service
6258
pylint service tests --max-line-length=127
@@ -66,7 +62,7 @@ jobs:
6662
export FLASK_APP=service:app
6763
pytest --pspec --cov=service --cov-fail-under=95 --disable-warnings
6864
env:
69-
DATABASE_URI: "postgresql://postgres:pgs3cr3t@postgres:5432/testdb"
65+
DATABASE_URI: "postgresql+psycopg://postgres:pgs3cr3t@postgres:5432/testdb"
7066

7167
- name: Upload code coverage
7268
uses: codecov/[email protected]

.vscode/launch.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

.vscode/tasks.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM python:3.11-slim
2+
3+
# Establish a working folder
4+
WORKDIR /app
5+
6+
# Establish dependencies
7+
COPY pyproject.toml poetry.lock ./
8+
RUN python -m pip install poetry && \
9+
poetry config virtualenvs.create false && \
10+
poetry install --without dev
11+
12+
# Copy source files last because they change the most
13+
COPY wsgi.py .
14+
COPY service ./service
15+
16+
# Become non-root user
17+
RUN useradd -m -r service && \
18+
chown -R service:service /app
19+
USER service
20+
21+
# Run the service on port 8080
22+
EXPOSE 8080
23+
CMD ["gunicorn", "wsgi:app", "--bind", "0.0.0.0:8080"]

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ all: help
1212

1313
venv: ## Create a Python virtual environment
1414
$(info Creating Python 3 virtual environment...)
15-
python3 -m venv .venv
15+
poetry shell
1616

1717
install: ## Install Python dependencies
1818
$(info Installing dependencies...)
19-
sudo pip install -r requirements.txt
19+
poetry config virtualenvs.create false
20+
poetry install
2021

2122
lint: ## Run the linter
2223
$(info Running linting...)
@@ -26,7 +27,7 @@ lint: ## Run the linter
2627

2728
test: ## Run the unit tests
2829
$(info Running tests...)
29-
green -vvv --processes=1 --run-coverage --termcolor --minimum-coverage=95
30+
pytest --disable-warnings
3031

3132
##@ Runtime
3233

Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
web: gunicorn --bind 0.0.0.0:$PORT --log-level=info service:app
1+
web: gunicorn --log-file=- --workers=1 --bind=0.0.0.0:$PORT wsgi:app

0 commit comments

Comments
 (0)