Skip to content

Commit

Permalink
Merge pull request #19 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 authored Mar 13, 2024
2 parents d58893e + 214b5c2 commit 624261b
Show file tree
Hide file tree
Showing 32 changed files with 1,500 additions and 344 deletions.
7 changes: 4 additions & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ RUN groupadd --gid $USER_GID $USERNAME \

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

ENV PORT 8080
EXPOSE $PORT
Expand Down
43 changes: 30 additions & 13 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,70 @@
// spell: disable
{
"name": "Kubernetes",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/app",
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
"remoteUser": "vscode",
"workspaceFolder": "/app",
"workspaceMount": "source=${localWorkspaceFolder},target=/app,type=bind,consistency=delegated",
"runArgs": ["-h","nyu", "--name", "lab-kubernetes"],
"remoteEnv": {
"FLASK_DEBUG:": "True",
"FLASK_APP": "wsgi:app",
"PORT": "8080",
"GUNICORN_BIND": "0.0.0.0:8080"
},
"customizations": {
"vscode": {
"settings": {
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
},
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"git.mergeEditor": 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,
"**/*.pyc": true,
"**/__pycache__": true,
"**/.pytest_cache": true
}
},
},
"extensions": [
"VisualStudioExptTeam.vscodeintellicode",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.pylint",
"ms-python.flake8",
"ms-python.vscode-pylance",
"ms-python.black-formatter",
"njpwerner.autodocstring",
"wholroyd.jinja",
"ms-vscode.makefile-tools",
"yzhang.markdown-all-in-one",
"DavidAnson.vscode-markdownlint",
"bierner.github-markdown-preview",
"hnw.vscode-auto-open-markdown-preview",
"bierner.markdown-preview-github-styles",
"davidanson.vscode-markdownlint",
"tamasfe.even-better-toml",
"donjayamanne.githistory",
"GitHub.vscode-pull-request-github",
"github.vscode-github-actions",
"hbenl.vscode-test-explorer",
"LittleFoxTeam.vscode-python-test-adapter",
"njpwerner.autodocstring",
"wholroyd.jinja",
"redhat.vscode-yaml",
"ms-azuretools.vscode-docker",
"ms-kubernetes-tools.vscode-kubernetes-tools",
"inercia.vscode-k3d",
"rangav.vscode-thunder-client",
"bbenoist.vagrant",
"streetsidesoftware.code-spell-checker"
"streetsidesoftware.code-spell-checker",
"bbenoist.vagrant"
]
}
},
Expand Down
38 changes: 0 additions & 38 deletions .devcontainer/docker-compose.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .devcontainer/scripts/setup-lab.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
echo "Setting up Docker lab environment..."
echo "Setting up Kubernetes lab environment..."
docker pull python:3.11-slim
docker run -d --name redis --restart always -p 6379:6379 -v redis:/data redis:6-alpine
echo Setting up registry.local...
sudo bash -c "echo '127.0.0.1 cluster-registry' >> /etc/hosts"
echo "Setup complete"
echo "Setup complete"
31 changes: 14 additions & 17 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ on:
branches:
- master
paths-ignore:
- 'README.md'
- '.vscode/**'
- '.devcontainers/**'
- 'README.md'
- '.vscode/**'
- '.devcontainers/**'

pull_request:
branches:
- master
paths-ignore:
- 'README.md'
- '.vscode/**'
- '.devcontainers/**'
- 'README.md'
- '.vscode/**'
- '.devcontainers/**'

jobs:
build:
Expand All @@ -24,35 +24,32 @@ jobs:
# Required services
services:
redis:
image: redis
image: redis:6-alpine
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Install Python dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel
pip install -r requirements.txt
python -m pip install 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
flake8 service tests --count --max-complexity=10 --max-line-length=127 --statistics
# Run pylint on the service and tests folders only
pylint service tests --max-line-length=127
- name: Run unit tests with green
run: green
- name: Run unit tests with PyTest
run: pytest
env:
DATABASE_URI: "redis://redis:6379/0"
RETRY_COUNT: 2

- name: Upload code coverage
uses: codecov/[email protected]
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "service:app",
"FLASK_APP": "wsgi:app",
"FLASK_ENV": "development"
},
"args": [
Expand Down
26 changes: 0 additions & 26 deletions .vscode/settings.json

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"label": "TDD tests",
"type": "shell",
"command": "nosetests",
"command": "pytest",
"group": {
"kind": "test",
"isDefault": true
Expand Down
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ FROM python:3.11-slim

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

# Copy the application contents
COPY wsgi.py .
COPY service/ ./service/

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

# Expose any ports the app is expecting in the environment
ENV FLASK_APP=service:app
ENV FLASK_APP=wsgi:app
ENV PORT 8080
EXPOSE $PORT

ENV GUNICORN_BIND 0.0.0.0:$PORT
ENTRYPOINT ["gunicorn"]
CMD ["--log-level=info", "service:app"]
CMD ["--log-level=info", "wsgi:app"]
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ clean: ## Removes all dangling build cache
.PHONY: venv
venv: ## Create a Python virtual environment
$(info Creating Python 3 virtual environment...)
python3 -m venv .venv
poetry config virtualenvs.in-project true
poetry shell

.PHONY: install
install: ## Install dependencies
$(info Installing dependencies...)
sudo python3 -m pip install --upgrade pip wheel
sudo pip install -r requirements.txt
sudo poetry config virtualenvs.create false
sudo poetry install

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

.PHONY: tests
tests: ## Run the unit tests
.PHONY: test
test: ## Run the unit tests
$(info Running tests...)
export RETRY_COUNT=1; green -vvv --processes=1 --run-coverage --termcolor --minimum-coverage=95
export RETRY_COUNT=1; pytest --pspec --cov=service --cov-fail-under=95

##@ Runtime

.PHONY: run
run: ## Run the service
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 --bind 0.0.0.0:$PORT --log-level=info wsgi:app
4 changes: 2 additions & 2 deletions k8s/pv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
- ReadWriteOnce
hostPath:
path: /data/pv0001
storageClassName: ""
storageClassName: "default"
6 changes: 3 additions & 3 deletions k8s/redis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
spec:
containers:
- name: redis
image: "redis:alpine"
image: "redis:6-alpine"
ports:
- containerPort: 6379
protocol: TCP
Expand All @@ -45,11 +45,11 @@ metadata:
name: redis-data
spec:
accessModes:
- ReadWriteMany
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: ""
storageClassName: "default"

---
apiVersion: v1
Expand Down
Empty file added lab/.gitkeep
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 624261b

Please sign in to comment.