From 1a406ebf82ae05de70c49a29ad246cc48b1eaef2 Mon Sep 17 00:00:00 2001 From: John Rofrano Date: Tue, 31 Oct 2023 03:04:21 +0000 Subject: [PATCH 1/4] Updated registry name in dev environment --- .devcontainer/devcontainer.json | 1 + .devcontainer/scripts/install-tools.sh | 20 -------------------- .devcontainer/scripts/setup-lab.sh | 2 +- 3 files changed, 2 insertions(+), 21 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 5f425c5..4b5b303 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -36,6 +36,7 @@ "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", "hbenl.vscode-test-explorer", diff --git a/.devcontainer/scripts/install-tools.sh b/.devcontainer/scripts/install-tools.sh index cd703bf..c9b9b9c 100644 --- a/.devcontainer/scripts/install-tools.sh +++ b/.devcontainer/scripts/install-tools.sh @@ -29,28 +29,8 @@ tar xvzf k9s.tar.gz sudo install -c -m 0755 k9s /usr/local/bin rm k9s.tar.gz -echo "**********************************************************************" -echo "Install Kustomize CLI..." -echo "**********************************************************************" -curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash -sudo mv kustomize /usr/local/bin/kustomize -echo "Creating ku alias for kustomize..." -echo "alias ku='/usr/local/bin/kustomize'" >> $HOME/.bash_aliases - echo "**********************************************************************" echo "Installing Skaffold..." echo "**********************************************************************" curl -Lo skaffold "https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-$ARCH" sudo install skaffold /usr/local/bin/ - -# echo "**********************************************************************" -# echo "Installing Knative for $ARCH..." -# echo "**********************************************************************" -# curl -Lo kn "https://github.com/knative/client/releases/download/knative-v1.11.0/kn-linux-$ARCH" -# sudo install kn /usr/local/bin/ - -echo "**********************************************************************" -echo "Installing YQ..." -echo "**********************************************************************" -sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_$ARCH -sudo chmod a+x /usr/local/bin/yq diff --git a/.devcontainer/scripts/setup-lab.sh b/.devcontainer/scripts/setup-lab.sh index 1f600ea..945862d 100644 --- a/.devcontainer/scripts/setup-lab.sh +++ b/.devcontainer/scripts/setup-lab.sh @@ -3,5 +3,5 @@ echo "Setting up Docker lab environment..." docker pull python:3.11-slim docker run -d --name redis -p 6379:6379 -v redis:/data redis:6-alpine echo Setting up registry.local... -sudo bash -c "echo '127.0.0.1 k3d-registry.local' >> /etc/hosts" +sudo bash -c "echo '127.0.0.1 cluster-registry' >> /etc/hosts" echo "Setup complete" \ No newline at end of file From 3cb833630a745f0c3ac4d0ada0444600c364a9a7 Mon Sep 17 00:00:00 2001 From: John Rofrano Date: Tue, 31 Oct 2023 03:05:20 +0000 Subject: [PATCH 2/4] Updated cluster registry name --- Makefile | 22 +++++++++++++++------- k8s/deployment.yaml | 4 ++-- skaffold.env | 2 +- skaffold.yaml | 2 +- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 1b4e38e..e121c88 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,13 @@ # These can be overidden with env vars. -REGISTRY ?= rofrano +REGISTRY ?= cluster-registry:32000 IMAGE_NAME ?= hitcounter IMAGE_TAG ?= 1.0 IMAGE ?= $(REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG) PLATFORM ?= "linux/amd64,linux/arm64" CLUSTER ?= nyu-devops +.SILENT: + .PHONY: help help: ## Display this help. @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) @@ -50,19 +52,25 @@ run: ## Run the service $(info Starting service...) honcho start +.PHONY: secret +secret: ## Generate a secret hex key + $(info Generating a new secret key...) + python3 -c 'import secrets; print(secrets.token_hex())' + ##@ Kubernetes +# k3d registry create registry.local --port 5000 +# k3d cluster create devops --agents 1 --registry-use k3d-registry.local:5000 --port '8080:80@loadbalancer' + .PHONY: cluster cluster: ## Create a K3D Kubernetes cluster with load balancer and registry $(info Creating Kubernetes cluster with a registry and 1 worker node...) - k3d registry create registry.local --port 5000 - k3d cluster create devops --agents 1 --registry-use k3d-registry.local:5000 --port '8080:80@loadbalancer' + k3d cluster create nyu-devops --agents 1 --registry-create cluster-registry:0.0.0.0:32000 --port '8080:80@loadbalancer' .PHONY: cluster-rm cluster-rm: ## Remove a K3D Kubernetes cluster $(info Removing Kubernetes cluster...) - k3d cluster delete devops - k3d registry delete registry.local + k3d cluster delete nyu-devops .PHONY: tekton tekton: ## Install Tekton @@ -89,7 +97,7 @@ knative: ## Install Knative .PHONY: deploy depoy: ## Deploy the service on local Kubernetes $(info Deploying service locally...) - kubectl apply -k kustomize/overlay/local + kubectl apply -f k8s/ ############################################################ # COMMANDS FOR BUILDING THE IMAGE @@ -112,7 +120,7 @@ build: ## Build all of the project Docker images .PHONY: buildx buildx: ## Build multi-platform image with buildx $(info Building multi-platform image $(IMAGE) for $(PLATFORM)...) - docker buildx build --file Dockerfile --pull --platform=$(PLATFORM) --tag $(IMAGE) --load . + docker buildx build --file Dockerfile --pull --platform=$(PLATFORM) --tag $(IMAGE) --push . .PHONY: remove remove: ## Stop and remove the buildx builder diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml index 2124574..0b595be 100644 --- a/k8s/deployment.yaml +++ b/k8s/deployment.yaml @@ -22,8 +22,8 @@ spec: restartPolicy: Always containers: - name: hitcounter - # image: k3d-registry.local:5000/hitcounter:1.0 - image: hitcounter + image: cluster-registry:32000/hitcounter:1.0 + # image: hitcounter imagePullPolicy: IfNotPresent ports: - containerPort: 8080 diff --git a/skaffold.env b/skaffold.env index ed4e658..d0d4942 100644 --- a/skaffold.env +++ b/skaffold.env @@ -1 +1 @@ -SKAFFOLD_DEFAULT_REPO=k3d-registry.local:5000 +SKAFFOLD_DEFAULT_REPO=cluster-registry:32000 diff --git a/skaffold.yaml b/skaffold.yaml index f5781ad..2d448e8 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -14,7 +14,7 @@ test: - context: . image: hitcounter custom: - - command: export DATABASE_URI=redis://localhost:6379/0 green + - command: export RETRY_COUNT=1; DATABASE_URI=redis://localhost:6379/0 green manifests: rawYaml: - k8s/deployment.yaml From 3eec66a72c196fe4a1430c5fa8d9d495403e9ddc Mon Sep 17 00:00:00 2001 From: John Rofrano Date: Tue, 31 Oct 2023 03:05:35 +0000 Subject: [PATCH 3/4] Updated packages --- requirements.txt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/requirements.txt b/requirements.txt index 8243705..3310384 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,24 +1,27 @@ # Pinned dependencies that cause breakage -Werkzeug==2.3.3 +Werkzeug==2.3.7 # Runtime dependencies -Flask==2.3.2 +Flask==2.3.3 redis==4.5.4 retry2==0.9.5 -python-dotenv==0.21.1 +python-dotenv==1.0.0 # Runtime dependencies -gunicorn==20.1.0 +gunicorn==21.2.0 honcho==1.1.0 # Code quality -pylint==2.16.2 -flake8==6.0.0 -black==23.1.0 +pylint==2.17.5 +flake8==6.1.0 +black==23.7.0 # Testing dependencies +pytest==7.4.0 +pytest-pspec==0.0.4 +pytest-cov==4.1.0 +coverage==7.3.0 green==3.4.3 -coverage==7.1.0 # Utilities httpie==3.2.2 From c9fbdbf617a4e8a0a84454eae1c4f8c47efeb41c Mon Sep 17 00:00:00 2001 From: John Rofrano Date: Tue, 31 Oct 2023 03:15:46 +0000 Subject: [PATCH 4/4] Changed registry name --- Makefile | 3 --- k3d-config.yaml | 11 ++++++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index e121c88..9effa91 100644 --- a/Makefile +++ b/Makefile @@ -59,9 +59,6 @@ secret: ## Generate a secret hex key ##@ Kubernetes -# k3d registry create registry.local --port 5000 -# k3d cluster create devops --agents 1 --registry-use k3d-registry.local:5000 --port '8080:80@loadbalancer' - .PHONY: cluster cluster: ## Create a K3D Kubernetes cluster with load balancer and registry $(info Creating Kubernetes cluster with a registry and 1 worker node...) diff --git a/k3d-config.yaml b/k3d-config.yaml index cf716bc..5d839cb 100644 --- a/k3d-config.yaml +++ b/k3d-config.yaml @@ -1,5 +1,6 @@ -apiVersion: k3d.io/v1alpha5 +apiVersion: k3d.io/v1alpha3 kind: Simple +name: devops servers: 1 agents: 1 ports: @@ -7,8 +8,12 @@ ports: nodeFilters: - loadbalancer registries: + create: + name: cluster-registry + host: "0.0.0.0" + hostPort: "32000" config: | mirrors: - "k3d-registry.local:5000": + "cluster-registry:32000": endpoint: - - http://k3d-registry.local:5000 + - http://cluster-registry:32000