Skip to content

Commit 107faf2

Browse files
authored
Merge pull request #6 from nyu-devops/su24-updates
Updates for Summer 2024 Semester
2 parents 6522d59 + b2d2940 commit 107faf2

28 files changed

+883
-812
lines changed

.devcontainer/devcontainer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"njpwerner.autodocstring",
4646
"wholroyd.jinja",
4747
"ms-vscode.makefile-tools",
48-
"tamasfe.even-better-toml",
4948
"yzhang.markdown-all-in-one",
5049
"DavidAnson.vscode-markdownlint",
5150
"bierner.github-markdown-preview",
@@ -57,12 +56,14 @@
5756
"hbenl.vscode-test-explorer",
5857
"LittleFoxTeam.vscode-python-test-adapter",
5958
"redhat.vscode-yaml",
59+
"rangav.vscode-thunder-client",
6060
"ms-azuretools.vscode-docker",
61-
"ms-kubernetes-tools.vscode-kubernetes-tools",
61+
"redhat.fabric8-analytics",
6262
"inercia.vscode-k3d",
63-
"rangav.vscode-thunder-client",
64-
"bbenoist.vagrant",
65-
"streetsidesoftware.code-spell-checker"
63+
"ms-kubernetes-tools.vscode-kubernetes-tools",
64+
"redhat.vscode-openshift-connector",
65+
"streetsidesoftware.code-spell-checker",
66+
"bbenoist.vagrant"
6667
]
6768
}
6869
},

.devcontainer/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ services:
1313
- ..:/app
1414
command: sleep infinity
1515
environment:
16-
FLASK_APP: service:app
16+
FLASK_APP: wsgi:app
1717
FLASK_DEBUG: "True"
1818
GUNICORN_BIND: "0.0.0.0:8000"
1919
DATABASE_URI: postgresql+psycopg://postgres:pgs3cr3t@postgres:5432/petstore

.devcontainer/scripts/install-tools.sh

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
######################################################################
33
# These scripts are meant to be run in user mode as they modify
44
# usr settings line .bashrc and .bash_aliases
5-
# Copyright 2022, 2023 John J. Rofrano All Rights Reserved.
5+
# Copyright 2022, 2024 John J. Rofrano All Rights Reserved.
66
######################################################################
77

88
echo "**********************************************************************"
@@ -24,7 +24,7 @@ sudo sh -c 'echo "127.0.0.1 cluster-registry" >> /etc/hosts'
2424
echo "**********************************************************************"
2525
echo "Installing K9s..."
2626
echo "**********************************************************************"
27-
curl -L -o k9s.tar.gz "https://github.com/derailed/k9s/releases/download/v0.27.3/k9s_Linux_$ARCH.tar.gz"
27+
curl -L -o k9s.tar.gz "https://github.com/derailed/k9s/releases/download/v0.32.4/k9s_Linux_$ARCH.tar.gz"
2828
tar xvzf k9s.tar.gz
2929
sudo install -c -m 0755 k9s /usr/local/bin
3030
rm k9s.tar.gz
@@ -44,40 +44,41 @@ sudo install -c -m 0755 devspace /usr/local/bin
4444
echo "**********************************************************************"
4545
echo "Installing Stern..."
4646
echo "**********************************************************************"
47-
curl -L -o stern.tar.gz "https://github.com/stern/stern/releases/download/v1.26.0/stern_1.26.0_linux_$ARCH.tar.gz"
47+
curl -L -o stern.tar.gz "https://github.com/stern/stern/releases/download/v1.28.0/stern_1.28.0_linux_$ARCH.tar.gz"
4848
tar xvzf stern.tar.gz
4949
sudo install -c -m 0755 stern /usr/local/bin
5050
rm stern.tar.gz LICENSE
5151

5252
echo "**********************************************************************"
5353
echo "Installing Knative CLI..."
5454
echo "**********************************************************************"
55-
curl -L -o kn "https://github.com/knative/client/releases/download/knative-v1.11.2/kn-darwin-$ARCH"
55+
curl -L -o kn "https://github.com/knative/client/releases/download/knative-v1.14.0/kn-linux-$ARCH"
5656
sudo install -c -m 0755 kn /usr/local/bin
5757
rm kn
5858

5959
echo "**********************************************************************"
6060
echo "Installing Tekton CLI..."
6161
echo "**********************************************************************"
6262
if [ $ARCH == amd64 ]; then
63-
curl -LO https://github.com/tektoncd/cli/releases/download/v0.32.2/tkn_0.32.2_Linux_x86_64.tar.gz
64-
sudo tar xvzf tkn_0.32.2_Linux_x86_64.tar.gz -C /usr/local/bin/ tkn
63+
curl -L https://github.com/tektoncd/cli/releases/download/v0.36.0/tkn_0.36.0_Linux_x86_64.tar.gz --output tekton.tar.gz
6564
else
66-
curl -LO https://github.com/tektoncd/cli/releases/download/v0.32.2/tkn_0.32.2_Linux_aarch64.tar.gz
67-
sudo tar xvzf tkn_0.32.2_Linux_aarch64.tar.gz -C /usr/local/bin/ tkn
68-
rm tkn_0.32.2_Linux_aarch64.tar.gz
65+
curl -L https://github.com/tektoncd/cli/releases/download/v0.36.0/tkn_0.36.0_Linux_aarch64.tar.gz --output tekton.tar.gz
6966
fi;
67+
tar xvzf tekton.tar.gz tkn
68+
sudo install -c -m 0755 tkn /usr/local/bin
69+
rm tekton.tar.gz tkn
70+
7071

7172
echo "**********************************************************************"
7273
echo "Install OpenShift 4 CLI..."
7374
echo "**********************************************************************"
7475
# OpenShift CLI has platform specific installs
7576
if [ $ARCH == amd64 ]; then
7677
echo "Installing OpenShift for Intel..."
77-
curl https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux.tar.gz --output oc.tar.gz
78+
curl -L https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux.tar.gz --output oc.tar.gz
7879
else
7980
echo "Installing OpenShift for $ARCH ..."
80-
curl https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux-$ARCH.tar.gz --output oc.tar.gz
81+
curl -L https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux-$ARCH.tar.gz --output oc.tar.gz
8182
fi;
8283
sudo tar xvzf oc.tar.gz -C /usr/local/bin/ oc
8384
sudo ln -s /usr/local/bin/oc /usr/bin/oc

.tekton/pipeline.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ spec:
7373
value: service
7474
- name: args
7575
value: []
76-
- name: requirements_file
76+
- name: requirements-file
7777
value: requirements.txt
7878
runAfter:
7979
- git-clone
@@ -85,14 +85,14 @@ spec:
8585
workspace: pipeline-workspace
8686
- name: testing
8787
params:
88-
- name: PYTEST_ARGS
88+
- name: pytest-args
8989
value:
9090
- '--pspec'
9191
- '--cov=service'
9292
- '--cov-fail-under=95'
93-
- name: SECRET_NAME
93+
- name: secret-name
9494
value: postgres-creds
95-
- name: SECRET_KEY
95+
- name: secret-key
9696
value: database_uri
9797
runAfter:
9898
- git-clone
@@ -135,9 +135,9 @@ spec:
135135
workspace: pipeline-workspace
136136
- name: deploy-image
137137
params:
138-
- name: image_name
138+
- name: IMAGE_NAME
139139
value: $(params.IMAGE_NAME)
140-
- name: manifest_dir
140+
- name: manifest-dir
141141
value: k8s
142142
runAfter:
143143
- buildah

.tekton/tasks.yaml

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ spec:
3131
description: The arguments to pass to the pylint CLI.
3232
type: array
3333
default: []
34-
- name: requirements_file
34+
- name: requirements-file
3535
description: The name of the requirements file inside the source location
3636
default: "requirements.txt"
3737
steps:
@@ -49,8 +49,8 @@ spec:
4949
python -m pip install poetry poetry-plugin-export
5050
poetry export --with=dev -f requirements.txt --output requirements.txt
5151
python -m pip install --user -r requirements.txt
52-
elif [ -n "$(params.requirements_file)" ] && [ -e "$(params.requirements_file)" ]; then
53-
python -m pip install --user -r "$(params.requirements_file)"
52+
elif [ -n "$(params.requirements-file)" ] && [ -e "$(params.requirements-file)" ]; then
53+
python -m pip install --user -r "$(params.requirements-file)"
5454
fi
5555
5656
# Make sure pylint is installed
@@ -85,15 +85,15 @@ spec:
8585
that is sourced from a Secret. This allows you to define
8686
credentials that can be used to connect to a test database.
8787
params:
88-
- name: PYTEST_ARGS
88+
- name: pytest-args
8989
description: The arguments to pass to the pytest CLI.
9090
type: array
9191
default: []
92-
- name: SECRET_NAME
92+
- name: secret-name
9393
description: The name of the secret containing a database_uri key
9494
type: string
9595
default: "postgres-creds"
96-
- name: SECRET_KEY
96+
- name: secret-key
9797
description: The name of the key that contains the database uri
9898
type: string
9999
default: "database_uri"
@@ -105,8 +105,8 @@ spec:
105105
- name: DATABASE_URI
106106
valueFrom:
107107
secretKeyRef:
108-
name: $(params.SECRET_NAME)
109-
key: $(params.SECRET_KEY)
108+
name: $(params.secret-name)
109+
key: $(params.secret-key)
110110
script: |
111111
#!/bin/bash
112112
set -e
@@ -129,7 +129,7 @@ spec:
129129
pytest --version
130130
pytest
131131
args:
132-
- "$(params.PYTEST_ARGS)"
132+
- "$(params.pytest-args)"
133133

134134
---
135135
apiVersion: tekton.dev/v1beta1
@@ -151,10 +151,10 @@ spec:
151151
This task will update the deployment.yaml with the latest image name
152152
and then apply that yaml file and it's service file.
153153
params:
154-
- name: image_name
154+
- name: image-name
155155
description: The fully qualified name of the new image to deploy
156156
type: string
157-
- name: manifest_dir
157+
- name: manifest-dir
158158
description: The directory in source that contains yaml manifests
159159
type: string
160160
default: "k8s"
@@ -168,7 +168,7 @@ spec:
168168
#!/bin/bash
169169
set -e
170170
171-
echo Applying manifests in $(inputs.params.manifest_dir) directory
171+
echo Applying manifests in $(inputs.params.manifest-dir) directory
172172
173173
echo "**********************************************************************"
174174
echo "Installing YQ..."
@@ -177,16 +177,15 @@ spec:
177177
chmod a+x /usr/bin/yq
178178
179179
echo "********************* DEPLOYMENT ***********************"
180-
echo "Deploying $(inputs.params.image_name) ..."
180+
echo "Deploying $(inputs.params.image-name) ..."
181181
182-
yq -e -i '.spec.template.spec.containers[0].image="$(inputs.params.image_name)"' $(inputs.params.manifest_dir)/deployment.yaml
183-
# sed -i 's|'"$(inputs.params.old_image_name)"'|'"$(inputs.params.image_name)"'|g' $(inputs.params.manifest_dir)/deployment.yaml
184-
cat $(inputs.params.manifest_dir)/deployment.yaml
182+
yq -e -i '.spec.template.spec.containers[0].image="$(inputs.params.image-name)"' $(inputs.params.manifest-dir)/deployment.yaml
183+
cat $(inputs.params.manifest-dir)/deployment.yaml
185184
186185
echo "************************************************************"
187186
echo "OC APPLY..."
188-
oc apply -f $(inputs.params.manifest_dir)/deployment.yaml
189-
oc apply -f $(inputs.params.manifest_dir)/service.yaml
187+
oc apply -f $(inputs.params.manifest-dir)/deployment.yaml
188+
oc apply -f $(inputs.params.manifest-dir)/service.yaml
190189
191190
echo "************************************************************"
192191
sleep 3
@@ -213,7 +212,7 @@ spec:
213212
description: >-
214213
This task will deploy all of the yaml files in the manifest folder.
215214
params:
216-
- name: manifest_dir
215+
- name: manifest-dir
217216
description: The directory in source that contains yaml manifests
218217
type: string
219218
default: "k8s"
@@ -224,8 +223,8 @@ spec:
224223
command: ["/bin/bash", "-c"]
225224
args:
226225
- |-
227-
echo Applying manifests in $(inputs.params.manifest_dir) directory
228-
oc apply -f $(inputs.params.manifest_dir)
226+
echo Applying manifests in $(inputs.params.manifest-dir) directory
227+
oc apply -f $(inputs.params.manifest-dir)
229228
echo -----------------------------------
230229
231230
---
@@ -247,14 +246,14 @@ spec:
247246
description: >-
248247
This task can be used to perform bdd tests with behave.
249248
params:
250-
- name: BASE_URL
249+
- name: base-url
251250
description: The url of the application to test
252251
type: string
253-
- name: WAIT_SECONDS
252+
- name: wait-seconds
254253
description: The number of seconds to wait for a reply
255254
type: string
256255
default: "60"
257-
- name: DRIVER
256+
- name: driver
258257
description: The web driver to use (chrome or firefox)
259258
type: string
260259
default: "chrome"
@@ -264,11 +263,11 @@ spec:
264263
workingDir: $(workspaces.source.path)
265264
env:
266265
- name: BASE_URL
267-
value: $(params.BASE_URL)
266+
value: $(params.base-url)
268267
- name: WAIT_SECONDS
269-
value: $(params.WAIT_SECONDS)
268+
value: $(params.wait-seconds)
270269
- name: DRIVER
271-
value: $(params.DRIVER)
270+
value: $(params.driver)
272271
script: |
273272
#!/bin/bash
274273
set -e

Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,27 @@
33
##################################################
44
FROM quay.io/rofrano/python:3.11-slim
55

6-
# Create working folder and install dependencies
6+
# Create working folder and install dependencies without dev
77
WORKDIR /app
88
COPY pyproject.toml poetry.lock ./
99
RUN python -m pip install --upgrade pip poetry && \
1010
poetry config virtualenvs.create false && \
11-
poetry install --without dev
11+
poetry install --no-root --without dev
1212

1313
# Copy the application contents
14-
COPY service/ ./service/
14+
COPY wsgi.py .
15+
COPY service ./service
1516

1617
# Switch to a non-root user and set file ownership
1718
RUN useradd --uid 1001 flask && \
1819
chown -R flask /app
1920
USER flask
2021

2122
# Expose any ports the app is expecting in the environment
22-
ENV FLASK_APP=service:app
23+
ENV FLASK_APP=wsgi:app
2324
ENV PORT 8080
2425
EXPOSE $PORT
2526

2627
ENV GUNICORN_BIND 0.0.0.0:$PORT
2728
ENTRYPOINT ["gunicorn"]
28-
CMD ["--log-level=info", "service:app"]
29+
CMD ["--log-level=info", "wsgi:app"]

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ 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 shell
3131

3232
.PHONY: install
33-
install: ## Install dependencies
33+
install: ## Install Python dependencies
3434
$(info Installing dependencies...)
35-
sudo python3 -m pip install --upgrade pip wheel
36-
sudo pip install -r requirements.txt
35+
poetry config virtualenvs.create false
36+
poetry install
3737

3838
.PHONY: lint
3939
lint: ## Run the linter
@@ -42,8 +42,8 @@ lint: ## Run the linter
4242
flake8 service tests --count --max-complexity=10 --max-line-length=127 --statistics
4343
pylint service tests --max-line-length=127
4444

45-
.PHONY: tests
46-
tests: ## Run the unit tests
45+
.PHONY: test
46+
test: ## Run the unit tests
4747
$(info Running tests...)
4848
export RETRY_COUNT=1; pytest --pspec --cov=service --cov-fail-under=95 --disable-warnings
4949

@@ -62,7 +62,7 @@ secret: ## Generate a secret hex key
6262
.PHONY: cluster
6363
cluster: ## Create a K3D Kubernetes cluster with load balancer and registry
6464
$(info Creating Kubernetes cluster with a registry and 2 worker nodes...)
65-
k3d cluster create nyu-devops --agents 2 --registry-create cluster-registry:0.0.0.0:32000 --port '8080:80@loadbalancer'
65+
k3d cluster create nyu-devops --agents 2 --registry-create cluster-registry:0.0.0.0:5000 --port '8080:80@loadbalancer'
6666

6767
.PHONY: cluster-rm
6868
cluster-rm: ## Remove a K3D Kubernetes cluster

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

k8s/deployment.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ spec:
1919
labels:
2020
app: petshop
2121
spec:
22-
# imagePullSecrets:
23-
# - name: all-icr-io
2422
restartPolicy: Always
2523
containers:
2624
- name: petshop
27-
image: cluster-registry:32000/petshop:1.0
25+
image: cluster-registry:5000/petshop:1.0
2826
imagePullPolicy: IfNotPresent
2927
ports:
3028
- containerPort: 8080

k8s/postgresql/configmap.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: postgres-config
5+
data:
6+
postgres_user: postgres
7+
postgres_db: petstore

0 commit comments

Comments
 (0)