From 5f5cadd54f830856534c4078d8054b68114f9b47 Mon Sep 17 00:00:00 2001 From: John Rofrano Date: Sun, 9 Mar 2025 11:26:54 -0400 Subject: [PATCH 1/2] Minor fixups --- .devcontainer/Dockerfile | 2 +- .devcontainer/devcontainer.json | 4 +++- .devcontainer/scripts/setup-lab.sh | 6 +++--- Makefile | 10 ++-------- Pipfile | 10 +++++----- setup.cfg | 6 ++++-- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 4d35db4..f0ad6dd 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -3,7 +3,7 @@ FROM quay.io/rofrano/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 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4294701..77660b4 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -55,12 +55,14 @@ "tamasfe.even-better-toml", "donjayamanne.githistory", "GitHub.vscode-pull-request-github", + "github.vscode-github-actions", "hbenl.vscode-test-explorer", "LittleFoxTeam.vscode-python-test-adapter", "redhat.vscode-yaml", + "unjinjang.rest-api-client", "ms-azuretools.vscode-docker", - "inercia.vscode-k3d", "ms-kubernetes-tools.vscode-kubernetes-tools", + "inercia.vscode-k3d", "redhat.vscode-openshift-connector", "streetsidesoftware.code-spell-checker", "bbenoist.vagrant" diff --git a/.devcontainer/scripts/setup-lab.sh b/.devcontainer/scripts/setup-lab.sh index 60d3e68..9f3d2ca 100644 --- a/.devcontainer/scripts/setup-lab.sh +++ b/.devcontainer/scripts/setup-lab.sh @@ -1,7 +1,7 @@ #!/bin/bash echo "**********************************************************************" -echo "Setting up Docker lab environment..." -echo "**********************************************************************" +echo "Setting up OpenShift lab environment..." +echo "**********************************************************************\n" echo "Pulling custom Python:3.11-slim image from quay.io..." docker pull quay.io/rofrano/python:3.11-slim @@ -13,6 +13,6 @@ sudo bash -c "echo '127.0.0.1 cluster-registry' >> /etc/hosts" echo "Making git stop complaining about unsafe folders" git config --global --add safe.directory /app -echo "**********************************************************************" +echo "\n**********************************************************************" echo "Setup complete" echo "**********************************************************************" diff --git a/Makefile b/Makefile index 89787db..37abe0d 100644 --- a/Makefile +++ b/Makefile @@ -24,16 +24,10 @@ clean: ## Removes all dangling build cache docker image prune -f docker buildx prune -f -.PHONY: venv -venv: ## Create a Python virtual environment - $(info Creating Python 3 virtual environment...) - poetry shell - .PHONY: install install: ## Install Python dependencies $(info Installing dependencies...) - poetry config virtualenvs.create false - poetry install + sudo pipenv install --system --dev .PHONY: lint lint: ## Run the linter @@ -67,7 +61,7 @@ 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 + k3d cluster delete $(CLUSTER) .PHONY: tekton tekton: ## Install Tekton diff --git a/Pipfile b/Pipfile index f84de48..af80d8d 100644 --- a/Pipfile +++ b/Pipfile @@ -12,15 +12,15 @@ python-dotenv = "~=1.0.1" gunicorn = "~=23.0.0" [dev-packages] -black = "~=25.1.0" -coverage = "~=7.6.10" -flake8 = "~=7.1.1" +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.1" -honcho = "~=2.0.0" +factory-boy = "~=3.3.3" +coverage = "~=7.6.12" httpie = "~=3.2.4" [requires] diff --git a/setup.cfg b/setup.cfg index a7f013d..149327f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,7 +16,7 @@ testpaths = max-line-length = 127 [pylint.'MESSAGES CONTROL'] -disable = "no-member,protected-access,global-statement" +disable = no-member,protected-access,global-statement # setup Flake8 configuration [flake8] @@ -32,7 +32,9 @@ line-length = 127 # Setup Coverage configuration [coverage:run] source = service -omit = venv/* +omit = + venv/* + .venv/* [coverage:report] show_missing = true From 6dfd620827c00bb5d8110e4ecff3ca10b5c0a976 Mon Sep 17 00:00:00 2001 From: John Rofrano Date: Wed, 9 Apr 2025 07:25:06 -0400 Subject: [PATCH 2/2] Removed old pipeline with buildah --- .tekton/pipeline.yaml | 149 ------------------------------------------ .tekton/tasks.yaml | 21 ++++-- Makefile | 6 +- setup.cfg | 1 + 4 files changed, 21 insertions(+), 156 deletions(-) delete mode 100644 .tekton/pipeline.yaml diff --git a/.tekton/pipeline.yaml b/.tekton/pipeline.yaml deleted file mode 100644 index 00a5117..0000000 --- a/.tekton/pipeline.yaml +++ /dev/null @@ -1,149 +0,0 @@ -# Completed cd-pipeline from the OpenShift lab ---- -apiVersion: tekton.dev/v1 -kind: Pipeline -metadata: - name: cd-pipeline -spec: - workspaces: - - name: pipeline-workspace - params: - - name: GIT_REPO - description: The URL to the git repo - type: string - - name: GIT_REF - description: The reference (branch or ref) - type: string - default: master - - name: APP_NAME - description: Name of the application - type: string - default: petshop - - name: IMAGE_NAME - description: The name of the image to build - type: string - default: 'image-registry.openshift-image-registry.svc:5000/$(context.pipelineRun.namespace)/$(params.APP_NAME):latest' - tasks: - - name: git-clone - params: - - name: url - value: $(params.GIT_REPO) - - name: revision - value: $(params.GIT_REF) - - name: refspec - value: '' - - name: submodules - value: 'true' - - name: depth - value: '1' - - name: sslVerify - value: 'true' - - name: crtFileName - value: ca-bundle.crt - - name: subdirectory - value: '' - - name: sparseCheckoutDirectories - value: '' - - name: deleteExisting - value: 'true' - - name: httpProxy - value: '' - - name: httpsProxy - value: '' - - name: noProxy - value: '' - - name: verbose - value: 'true' - - name: gitInitImage - value: >- - registry.redhat.io/openshift-pipelines/pipelines-git-init-rhel8@sha256:1a50511583fc02a27012d17d942e247813404104ddd282d7e26f99765174392c - - name: userHome - value: /home/git - taskRef: - kind: ClusterTask - name: git-clone - workspaces: - - name: output - workspace: pipeline-workspace - - name: linting - params: - - name: image - value: 'docker.io/python:3.11-slim' - - name: path - value: service - - name: args - value: [] - - name: requirements-file - value: requirements.txt - runAfter: - - git-clone - taskRef: - kind: Task - name: pylint - workspaces: - - name: source - workspace: pipeline-workspace - - name: testing - params: - - name: pytest-args - value: - - '--pspec' - - '--cov=service' - - '--cov-fail-under=95' - - name: secret-name - value: postgres-creds - - name: secret-key - value: database_uri - runAfter: - - git-clone - taskRef: - kind: Task - name: pytest-env - workspaces: - - name: source - workspace: pipeline-workspace - - name: buildah - params: - - name: IMAGE - value: $(params.IMAGE_NAME) - - name: BUILDER_IMAGE - value: 'registry.redhat.io/rhel8/buildah@sha256:b48f410efa0ff8ab0db6ead420a5d8d866d64af846fece5efb185230d7ecf591' - - name: STORAGE_DRIVER - value: vfs - - name: DOCKERFILE - value: ./Dockerfile - - name: CONTEXT - value: . - - name: TLSVERIFY - value: 'true' - - name: FORMAT - value: oci - - name: BUILD_EXTRA_ARGS - value: '' - - name: PUSH_EXTRA_ARGS - value: '' - - name: SKIP_PUSH - value: 'false' - runAfter: - - linting - - testing - taskRef: - kind: ClusterTask - name: buildah - workspaces: - - name: source - workspace: pipeline-workspace - - name: deploy-image - params: - - name: IMAGE_NAME - value: $(params.IMAGE_NAME) - - name: manifest-dir - value: k8s - runAfter: - - buildah - taskRef: - kind: Task - name: deploy-image - workspaces: - - name: source - workspace: pipeline-workspace diff --git a/.tekton/tasks.yaml b/.tekton/tasks.yaml index 3bf665b..3ce5443 100644 --- a/.tekton/tasks.yaml +++ b/.tekton/tasks.yaml @@ -17,8 +17,9 @@ spec: - name: source description: The workspace with the source code. description: >- - Use to run pylint on the provided input source. If Poetry is being used - it will detect the poetry.lock file and install via requirements export. + Use to run pylint on the provided input source. + If Poetry or Pipenv is being used it will detect + the poetry.lock and Pipfile file and install using them. params: - name: image description: The container image with pylint @@ -49,6 +50,10 @@ spec: python -m pip install --upgrade pip poetry poetry config virtualenvs.create false poetry install + elif [ -e "Pipfile" ]; then + echo "Found Pipfile file: using pipenv ..." + python -m pip install --upgrade pip pipenv + pipenv install --system --dev elif [ -n "$(params.requirements-file)" ] && [ -e "$(params.requirements-file)" ]; then python -m pip install --user -r "$(params.requirements-file)" fi @@ -79,7 +84,7 @@ spec: - name: source description: >- This task can be used to perform unit tests with pytest. - It supports both requirements.txt and poetry.lock files. + It supports both requirements.txt, Pipfile, & poetry.lock files. It also has the ability to create an environment variable that is sourced from a Secret. This allows you to define @@ -118,6 +123,10 @@ spec: python -m pip install --upgrade pip poetry poetry config virtualenvs.create false poetry install + elif [ -e "Pipfile" ]; then + echo "Found Pipfile file: using pipenv ..." + python -m pip install --upgrade pip pipenv + pipenv install --system --dev elif -e "requirements.txt" ]; then python -m pip install --user -r requirements.txt fi @@ -259,7 +268,7 @@ spec: default: "chrome" steps: - name: behave - image: rofrano/pipeline-selenium + image: quay.io/rofrano/pipeline-selenium workingDir: $(workspaces.source.path) env: - name: BASE_URL @@ -278,6 +287,10 @@ spec: echo "Found poetry.lock file: using poetry" python -m pip install poetry poetry-plugin-export poetry export --with=dev -f requirements.txt --output requirements.txt + elif [ -e "Pipfile" ]; then + echo "Found Pipfile file: using pipenv ..." + python -m pip install --upgrade pip pipenv + pipenv requirements --dev > requirements.txt fi python -m pip install --user -r requirements.txt diff --git a/Makefile b/Makefile index 37abe0d..bbf77f4 100644 --- a/Makefile +++ b/Makefile @@ -32,9 +32,9 @@ install: ## Install Python dependencies .PHONY: lint lint: ## Run the linter $(info Running linting...) - flake8 service tests --count --select=E9,F63,F7,F82 --show-source --statistics - flake8 service tests --count --max-complexity=10 --max-line-length=127 --statistics - pylint service tests --max-line-length=127 + -flake8 service tests --count --select=E9,F63,F7,F82 --show-source --statistics + -flake8 service tests --count --max-complexity=10 --max-line-length=127 --statistics + -pylint service tests --max-line-length=127 .PHONY: test test: ## Run the unit tests diff --git a/setup.cfg b/setup.cfg index 149327f..43852e9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -49,3 +49,4 @@ ignore_errors = true [coverage:html] title = 'Test Coverage Report' +directory = 'coverage_report'