Skip to content

Updates for Spring 2025 Semester #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 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.11
RUN apt-get update && \
apt-get install -y sudo vim make git zip tree curl wget jq procps net-tools && \
apt-get install -y sudo vim make git zip tree curl wget jq procps net-tools iputils-ping && \
apt-get autoremove -y && \
apt-get clean -y

Expand All @@ -12,7 +12,7 @@ ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Create the user with passwordless sudo privileges
# Create the user with password-less sudo privileges
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME -s /bin/bash \
&& usermod -aG sudo $USERNAME \
Expand All @@ -22,10 +22,12 @@ RUN groupadd --gid $USER_GID $USERNAME \

# Set up the Python development environment
WORKDIR /app
COPY pyproject.toml poetry.lock ./
RUN sudo python -m pip install --upgrade pip poetry && \
sudo poetry config virtualenvs.create false && \
sudo poetry install
COPY Pipfile Pipfile.lock ./
RUN python -m pip install --upgrade pip pipenv && \
pipenv install --system --dev

ENV PORT=8080
EXPOSE $PORT

ENV PORT 8080
EXPOSE $PORT
Expand Down
15 changes: 11 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// spell: disable
{
"name": "Kubernetes",
"name": "Kubernetes Lab",
"build": {
"dockerfile": "Dockerfile",
"context": ".."
Expand All @@ -18,13 +18,20 @@
"customizations": {
"vscode": {
"settings": {
"cSpell.words": [
"pytest",
"pipenv",
"creds",
"virtualenvs"
],
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
},
"git.mergeEditor": true,
"markdown-preview-github-styles.colorTheme": "light",
"makefile.extensionOutputFolder": "/tmp",
"makefile.configureOnOpen": false,
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
Expand All @@ -44,6 +51,8 @@
"ms-python.pylint",
"ms-python.flake8",
"ms-python.black-formatter",
"njpwerner.autodocstring",
"wholroyd.jinja",
"ms-vscode.makefile-tools",
"yzhang.markdown-all-in-one",
"DavidAnson.vscode-markdownlint",
Expand All @@ -56,13 +65,11 @@
"github.vscode-github-actions",
"hbenl.vscode-test-explorer",
"LittleFoxTeam.vscode-python-test-adapter",
"njpwerner.autodocstring",
"wholroyd.jinja",
"redhat.vscode-yaml",
"unjinjang.rest-api-client",
"ms-azuretools.vscode-docker",
"ms-kubernetes-tools.vscode-kubernetes-tools",
"inercia.vscode-k3d",
"rangav.vscode-thunder-client",
"streetsidesoftware.code-spell-checker",
"bbenoist.vagrant"
]
Expand Down
6 changes: 5 additions & 1 deletion .devcontainer/scripts/install-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ sudo sh -c 'echo "127.0.0.1 cluster-registry" >> /etc/hosts'
echo "**********************************************************************"
echo "Installing K9s..."
echo "**********************************************************************"
curl -L -o k9s.tar.gz "https://github.com/derailed/k9s/releases/download/v0.32.5/k9s_Linux_$ARCH.tar.gz"
curl -L -o k9s.tar.gz "https://github.com/derailed/k9s/releases/download/v0.32.7/k9s_Linux_$ARCH.tar.gz"
tar xvzf k9s.tar.gz
sudo install -c -m 0755 k9s /usr/local/bin
rm k9s.tar.gz
Expand All @@ -40,3 +40,7 @@ echo "Installing DevSpace..."
echo "**********************************************************************"
curl -Lo devspace "https://github.com/loft-sh/devspace/releases/latest/download/devspace-linux-$ARCH"
sudo install -c -m 0755 devspace /usr/local/bin

echo "\n\n**********************************************************************"
echo "Tools Installation Complete!"
echo "**********************************************************************"
5 changes: 5 additions & 0 deletions .devcontainer/scripts/setup-lab.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash
echo "**********************************************************************"
echo "Setting up Kubernetes lab environment..."
echo "**********************************************************************\n"

docker pull python:3.11-slim
docker run -d --name redis --restart always -p 6379:6379 -v redis:/data redis:6-alpine

Expand All @@ -9,4 +12,6 @@ sudo bash -c "echo '127.0.0.1 cluster-registry' >> /etc/hosts"
echo "Make git stop complaining about unsafe folders..."
git config --global --add safe.directory /app

echo "\n**********************************************************************"
echo "Setup complete"
echo "**********************************************************************"
9 changes: 4 additions & 5 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Install dependencies
- name: Install Python package dependencies
run: |
python -m pip install poetry
poetry config virtualenvs.create false
poetry install
python -m pip install -U pip pipenv
pipenv install --system --dev

- name: Linting
run: |
Expand All @@ -47,7 +46,7 @@ jobs:
pylint service tests --max-line-length=127

- name: Run unit tests with PyTest
run: pytest
run: pytest --cov-report=xml
env:
DATABASE_URI: "redis://redis:6379/0"

Expand Down
19 changes: 11 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
##################################################
# Create production image
##################################################
FROM python:3.11-slim

# Create working folder and install dependencies
# Set up the Python production environment
WORKDIR /app
COPY pyproject.toml poetry.lock ./
RUN python -m pip install --upgrade pip poetry && \
poetry config virtualenvs.create false && \
poetry install --without dev
COPY Pipfile Pipfile.lock ./
RUN python -m pip install --upgrade pip pipenv && \
pipenv install --system --deploy

# 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
# Switch to a non-root user and set file ownership
RUN useradd --uid 1001 flask && \
chown -R flask /app
USER flask

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

Expand Down
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ clean: ## Removes all dangling build cache
.PHONY: venv
venv: ## Create a Python virtual environment
$(info Creating Python 3 virtual environment...)
poetry config virtualenvs.in-project true
poetry shell
pipenv shell

.PHONY: install
install: ## Install dependencies
$(info Installing dependencies...)
sudo poetry config virtualenvs.create false
sudo poetry install
sudo pipenv install --system --dev

.PHONY: lint
lint: ## Run the linter
Expand Down Expand Up @@ -69,8 +67,8 @@ cluster: ## Create a K3D Kubernetes cluster with load balancer and registry

.PHONY: cluster-rm
cluster-rm: ## Remove a K3D Kubernetes cluster
$(info Removing Kubernetes cluster...)
k3d cluster delete nyu-devops
$(info Removing Kubernetes cluster $(CLUSTER)...)
k3d cluster delete $(CLUSTER)

.PHONY: tekton
tekton: ## Install Tekton
Expand All @@ -95,7 +93,7 @@ knative: ## Install Knative
kubectl apply -f https://github.com/knative/eventing/releases/download/knative-v1.8.5/eventing-core.yaml

.PHONY: deploy
depoy: ## Deploy the service on local Kubernetes
deploy: ## Deploy the service on local Kubernetes
$(info Deploying service locally...)
kubectl apply -f k8s/

Expand All @@ -117,6 +115,11 @@ build: ## Build all of the project Docker images
$(info Building $(IMAGE) for $(PLATFORM)...)
docker build --rm --pull --tag $(IMAGE) .

.PHONY: push
push: ## Push the image to the container registry
$(info Pushing $(IMAGE)...)
docker push $(IMAGE)

.PHONY: buildx
buildx: ## Build multi-platform image with buildx
$(info Building multi-platform image $(IMAGE) for $(PLATFORM)...)
Expand Down
27 changes: 27 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
flask = "~=3.1.0"
redis = "~=5.0.0"
flask-redis = "~=0.4.0"
retry2 = "~=0.9.5"
python-dotenv = "~=1.0.1"
gunicorn = "~=23.0.0"

[dev-packages]
honcho = "~=2.0.0"
pylint = "~=3.3.4"
flake8 = "~=7.1.1"
black = "~=25.1.0"
pytest = "~=8.3.4"
pytest-pspec = "~=0.0.4"
pytest-cov = "~=6.0.0"
factory-boy = "~=3.3.3"
coverage = "~=7.6.12"
httpie = "~=3.2.4"

[requires]
python_version = "3.11"
Loading