Skip to content

Commit 624261b

Browse files
authored
Merge pull request #19 from nyu-devops/updates-sp24
Updates for Spring 2024 Semester
2 parents d58893e + 214b5c2 commit 624261b

32 files changed

+1500
-344
lines changed

.devcontainer/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ RUN groupadd --gid $USER_GID $USERNAME \
2222

2323
# Set up the Python development environment
2424
WORKDIR /app
25-
COPY requirements.txt .
26-
RUN python -m pip install --upgrade pip wheel && \
27-
pip install -r requirements.txt
25+
COPY pyproject.toml poetry.lock ./
26+
RUN sudo python -m pip install --upgrade pip poetry && \
27+
sudo poetry config virtualenvs.create false && \
28+
sudo poetry install
2829

2930
ENV PORT 8080
3031
EXPOSE $PORT

.devcontainer/devcontainer.json

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,70 @@
11
// spell: disable
22
{
33
"name": "Kubernetes",
4-
"dockerComposeFile": "docker-compose.yml",
5-
"service": "app",
6-
"workspaceFolder": "/app",
4+
"build": {
5+
"dockerfile": "Dockerfile",
6+
"context": ".."
7+
},
78
"remoteUser": "vscode",
9+
"workspaceFolder": "/app",
10+
"workspaceMount": "source=${localWorkspaceFolder},target=/app,type=bind,consistency=delegated",
11+
"runArgs": ["-h","nyu", "--name", "lab-kubernetes"],
12+
"remoteEnv": {
13+
"FLASK_DEBUG:": "True",
14+
"FLASK_APP": "wsgi:app",
15+
"PORT": "8080",
16+
"GUNICORN_BIND": "0.0.0.0:8080"
17+
},
818
"customizations": {
919
"vscode": {
1020
"settings": {
1121
"[python]": {
1222
"editor.defaultFormatter": "ms-python.black-formatter",
1323
"editor.formatOnSave": true
1424
},
15-
"python.linting.enabled": true,
16-
"python.linting.pylintEnabled": true,
25+
"git.mergeEditor": true,
1726
"markdown-preview-github-styles.colorTheme": "light",
27+
"makefile.extensionOutputFolder": "/tmp",
28+
"python.testing.unittestEnabled": false,
29+
"python.testing.pytestEnabled": true,
30+
"python.testing.pytestArgs": [
31+
"tests"
32+
],
1833
"files.exclude": {
1934
"**/.git": true,
2035
"**/.DS_Store": true,
2136
"**/*.pyc": true,
2237
"**/__pycache__": true,
2338
"**/.pytest_cache": true
2439
}
25-
},
40+
},
2641
"extensions": [
27-
"VisualStudioExptTeam.vscodeintellicode",
2842
"ms-python.python",
43+
"ms-python.vscode-pylance",
2944
"ms-python.pylint",
3045
"ms-python.flake8",
31-
"ms-python.vscode-pylance",
3246
"ms-python.black-formatter",
33-
"njpwerner.autodocstring",
34-
"wholroyd.jinja",
47+
"ms-vscode.makefile-tools",
3548
"yzhang.markdown-all-in-one",
49+
"DavidAnson.vscode-markdownlint",
50+
"bierner.github-markdown-preview",
3651
"hnw.vscode-auto-open-markdown-preview",
3752
"bierner.markdown-preview-github-styles",
38-
"davidanson.vscode-markdownlint",
3953
"tamasfe.even-better-toml",
4054
"donjayamanne.githistory",
4155
"GitHub.vscode-pull-request-github",
56+
"github.vscode-github-actions",
4257
"hbenl.vscode-test-explorer",
4358
"LittleFoxTeam.vscode-python-test-adapter",
59+
"njpwerner.autodocstring",
60+
"wholroyd.jinja",
4461
"redhat.vscode-yaml",
4562
"ms-azuretools.vscode-docker",
4663
"ms-kubernetes-tools.vscode-kubernetes-tools",
4764
"inercia.vscode-k3d",
4865
"rangav.vscode-thunder-client",
49-
"bbenoist.vagrant",
50-
"streetsidesoftware.code-spell-checker"
66+
"streetsidesoftware.code-spell-checker",
67+
"bbenoist.vagrant"
5168
]
5269
}
5370
},

.devcontainer/docker-compose.yml

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

.devcontainer/scripts/setup-lab.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
2-
echo "Setting up Docker lab environment..."
2+
echo "Setting up Kubernetes lab environment..."
33
docker pull python:3.11-slim
44
docker run -d --name redis --restart always -p 6379:6379 -v redis:/data redis:6-alpine
55
echo Setting up registry.local...
66
sudo bash -c "echo '127.0.0.1 cluster-registry' >> /etc/hosts"
7-
echo "Setup complete"
7+
echo "Setup complete"

.github/workflows/workflow.yaml

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ on:
44
branches:
55
- master
66
paths-ignore:
7-
- 'README.md'
8-
- '.vscode/**'
9-
- '.devcontainers/**'
7+
- 'README.md'
8+
- '.vscode/**'
9+
- '.devcontainers/**'
1010

1111
pull_request:
1212
branches:
1313
- master
1414
paths-ignore:
15-
- 'README.md'
16-
- '.vscode/**'
17-
- '.devcontainers/**'
15+
- 'README.md'
16+
- '.vscode/**'
17+
- '.devcontainers/**'
1818

1919
jobs:
2020
build:
@@ -24,35 +24,32 @@ jobs:
2424
# Required services
2525
services:
2626
redis:
27-
image: redis
27+
image: redis:6-alpine
2828
options: >-
2929
--health-cmd "redis-cli ping"
3030
--health-interval 10s
3131
--health-timeout 5s
3232
--health-retries 5
3333
3434
steps:
35-
- uses: actions/checkout@v2
35+
- uses: actions/checkout@v3
3636

37-
- name: Install Python dependencies
37+
- name: Install dependencies
3838
run: |
39-
python -m pip install --upgrade pip wheel
40-
pip install -r requirements.txt
39+
python -m pip install poetry
40+
poetry config virtualenvs.create false
41+
poetry install
4142
4243
- name: Linting
4344
run: |
44-
# stop the build if there are Python syntax errors or undefined names
4545
flake8 service tests --count --select=E9,F63,F7,F82 --show-source --statistics
46-
# check for omplexity. The GitHub editor is 127 chars wide
4746
flake8 service tests --count --max-complexity=10 --max-line-length=127 --statistics
48-
# Run pylint on the service and tests folders only
4947
pylint service tests --max-line-length=127
5048
51-
- name: Run unit tests with green
52-
run: green
49+
- name: Run unit tests with PyTest
50+
run: pytest
5351
env:
5452
DATABASE_URI: "redis://redis:6379/0"
55-
RETRY_COUNT: 2
5653

5754
- name: Upload code coverage
5855
uses: codecov/codecov-action@v3.1.4

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"request": "launch",
77
"module": "flask",
88
"env": {
9-
"FLASK_APP": "service:app",
9+
"FLASK_APP": "wsgi:app",
1010
"FLASK_ENV": "development"
1111
},
1212
"args": [

.vscode/settings.json

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

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{
77
"label": "TDD tests",
88
"type": "shell",
9-
"command": "nosetests",
9+
"command": "pytest",
1010
"group": {
1111
"kind": "test",
1212
"isDefault": true

Dockerfile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@ FROM python:3.11-slim
22

33
# Create working folder and install dependencies
44
WORKDIR /app
5-
COPY requirements.txt .
6-
RUN pip install -U pip wheel && \
7-
pip install --no-cache-dir -r requirements.txt
5+
COPY pyproject.toml poetry.lock ./
6+
RUN python -m pip install --upgrade pip poetry && \
7+
poetry config virtualenvs.create false && \
8+
poetry install --without dev
89

910
# Copy the application contents
11+
COPY wsgi.py .
1012
COPY service/ ./service/
1113

1214
# Switch to a non-root user
1315
RUN useradd --uid 1000 flask && chown -R flask /app
1416
USER flask
1517

1618
# Expose any ports the app is expecting in the environment
17-
ENV FLASK_APP=service:app
19+
ENV FLASK_APP=wsgi:app
1820
ENV PORT 8080
1921
EXPOSE $PORT
2022

2123
ENV GUNICORN_BIND 0.0.0.0:$PORT
2224
ENTRYPOINT ["gunicorn"]
23-
CMD ["--log-level=info", "service:app"]
25+
CMD ["--log-level=info", "wsgi:app"]

Makefile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ clean: ## Removes all dangling build cache
2727
.PHONY: venv
2828
venv: ## Create a Python virtual environment
2929
$(info Creating Python 3 virtual environment...)
30-
python3 -m venv .venv
30+
poetry config virtualenvs.in-project true
31+
poetry shell
3132

3233
.PHONY: install
3334
install: ## Install dependencies
3435
$(info Installing dependencies...)
35-
sudo python3 -m pip install --upgrade pip wheel
36-
sudo pip install -r requirements.txt
36+
sudo poetry config virtualenvs.create false
37+
sudo poetry install
3738

3839
.PHONY: lint
3940
lint: ## Run the linter
@@ -42,10 +43,12 @@ lint: ## Run the linter
4243
flake8 service tests --count --max-complexity=10 --max-line-length=127 --statistics
4344
pylint service tests --max-line-length=127
4445

45-
.PHONY: tests
46-
tests: ## Run the unit tests
46+
.PHONY: test
47+
test: ## Run the unit tests
4748
$(info Running tests...)
48-
export RETRY_COUNT=1; green -vvv --processes=1 --run-coverage --termcolor --minimum-coverage=95
49+
export RETRY_COUNT=1; pytest --pspec --cov=service --cov-fail-under=95
50+
51+
##@ Runtime
4952

5053
.PHONY: run
5154
run: ## Run the service

0 commit comments

Comments
 (0)