Skip to content

Commit 1f58b2c

Browse files
authored
Merge pull request #18 from nyu-devops/update-sp24
Updates for Spring 2024 Semester
2 parents 03ab27a + be7e804 commit 1f58b2c

19 files changed

+1638
-218
lines changed

.devcontainer/Dockerfile

+4-3
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 python -m pip install -U pip poetry && \
27+
poetry config virtualenvs.create false && \
28+
poetry install
2829

2930
ENV PORT 8080
3031
EXPOSE $PORT

.devcontainer/devcontainer.json

+19-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
"editor.defaultFormatter": "ms-python.black-formatter",
1313
"editor.formatOnSave": true
1414
},
15-
"python.testing.pytestEnabled": false,
16-
"python.testing.unittestEnabled": true,
17-
"pylint.lintOnChange": true,
1815
"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+
],
1922
"files.exclude": {
2023
"**/.git": true,
2124
"**/.DS_Store": true,
@@ -28,17 +31,29 @@
2831
"VisualStudioExptTeam.vscodeintellicode",
2932
"ms-python.python",
3033
"ms-python.vscode-pylance",
34+
"ms-python.pylint",
35+
"ms-python.flake8",
36+
"ms-python.black-formatter",
3137
"cstrap.flask-snippets",
3238
"yzhang.markdown-all-in-one",
3339
"bierner.github-markdown-preview",
3440
"hnw.vscode-auto-open-markdown-preview",
35-
"DavidAnson.vscode-markdownlint",
41+
"davidanson.vscode-markdownlint",
42+
"bierner.markdown-preview-github-styles",
43+
"tamasfe.even-better-toml",
3644
"donjayamanne.githistory",
3745
"GitHub.vscode-pull-request-github",
3846
"hbenl.vscode-test-explorer",
3947
"LittleFoxTeam.vscode-python-test-adapter",
4048
"njpwerner.autodocstring",
49+
"wholroyd.jinja",
4150
"redhat.vscode-yaml",
51+
"rangav.vscode-thunder-client",
52+
"redhat.fabric8-analytics",
53+
"streetsidesoftware.code-spell-checker",
54+
"ms-azuretools.vscode-docker",
55+
"github.vscode-github-actions",
56+
"streetsidesoftware.code-spell-checker",
4257
"bbenoist.vagrant"
4358
]
4459
}

.devcontainer/docker-compose.yml

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ services:
1111
- ..:/app
1212
command: sleep infinity
1313
environment:
14+
FLASK_APP: wsgi:app
15+
FLASK_DEBUG: "True"
1416
CLOUDANT_HOST: couchdb
1517
CLOUDANT_PORT: 5984
1618
CLOUDANT_USERNAME: ${CLOUDANT_USERNAME:-admin}

.github/workflows/build.yml

+7-4
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,22 @@ jobs:
3838

3939
- name: Install dependencies
4040
run: |
41-
python -m pip install --upgrade pip wheel
42-
pip install -r requirements.txt
41+
python -m pip install -U pip poetry
42+
poetry config virtualenvs.create false
43+
poetry install
4344
4445
- name: Create the test database
4546
run: |
4647
apt-get update
4748
apt-get install -y curl
4849
curl -X PUT http://admin:pass@couchdb:5984/test
4950
50-
- name: Run unit tests with green
51-
run: green
51+
- name: Run unit tests with pytest
52+
run: pytest --pspec --cov=service --cov-fail-under=95 --disable-warnings
5253
env:
54+
FLASK_APP: "wsgi:app"
5355
BINDING_CLOUDANT: '{"username":"admin","password":"pass","host":"couchdb","port":5984,"url":"http://admin:pass@couchdb:5984"}'
5456

5557
- name: Upload code coverage
5658
uses: codecov/codecov-action@v3.1.4
59+

.vscode/launch.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"request": "launch",
77
"module": "flask",
88
"env": {
9-
"FLASK_APP": "service:app",
10-
"FLASK_ENV": "development"
9+
"FLASK_APP": "wsgi:app",
10+
"FLASK_DEBUG": "True"
1111
},
1212
"args": [
1313
"run",

Dockerfile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
##################################################
2+
# Create production image
3+
##################################################
4+
FROM python:3.11-slim
5+
6+
# Establish a working folder
7+
WORKDIR /app
8+
9+
# Establish dependencies
10+
COPY pyproject.toml poetry.lock ./
11+
RUN python -m pip install poetry && \
12+
poetry config virtualenvs.create false && \
13+
poetry install --without dev
14+
15+
# Copy source files last because they change the most
16+
COPY wsgi.py .
17+
COPY service ./service
18+
19+
# Switch to a non-root user and set file ownership
20+
RUN useradd --uid 1001 flask && \
21+
chown -R flask:flask /app
22+
USER flask
23+
24+
# Expose any ports the app is expecting in the environment
25+
ENV FLASK_APP=wsgi:app
26+
ENV PORT 8080
27+
EXPOSE $PORT
28+
29+
ENV GUNICORN_BIND 0.0.0.0:$PORT
30+
ENTRYPOINT ["gunicorn"]
31+
CMD ["--log-level=info", "wsgi:app"]

Makefile

+4-3
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
3031

3132
##@ Runtime
3233

Procfile

+1-1
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 --bind 0.0.0.0:$PORT --log-level=info wsgi:app

0 commit comments

Comments
 (0)