Skip to content

Commit

Permalink
Merge pull request #18 from nyu-devops/update-fa23
Browse files Browse the repository at this point in the history
More updates for Fall 2023 Semester
  • Loading branch information
rofrano authored Oct 31, 2023
2 parents b669d7a + c9fbdbf commit 2f3fbc8
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 43 deletions.
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 0 additions & 20 deletions .devcontainer/scripts/install-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .devcontainer/scripts/setup-lab.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
19 changes: 12 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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<target>\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)
Expand Down Expand Up @@ -50,19 +52,22 @@ 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

.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
Expand All @@ -89,7 +94,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
Expand All @@ -112,7 +117,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
Expand Down
11 changes: 8 additions & 3 deletions k3d-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
apiVersion: k3d.io/v1alpha5
apiVersion: k3d.io/v1alpha3
kind: Simple
name: devops
servers: 1
agents: 1
ports:
- port: 8080:80
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
4 changes: 2 additions & 2 deletions k8s/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 11 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion skaffold.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SKAFFOLD_DEFAULT_REPO=k3d-registry.local:5000
SKAFFOLD_DEFAULT_REPO=cluster-registry:32000
2 changes: 1 addition & 1 deletion skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2f3fbc8

Please sign in to comment.