Skip to content

Commit

Permalink
chore: refactor some scripts (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
avtakkar authored Mar 21, 2024
1 parent 15f56dd commit 8c53c30
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ BIN_DIR = $(ROOT_DIR)/bin
TEST_PKGS = $(shell go list ./...)
TESTS_BIN_DIR = $(BIN_DIR)/tests
COVERAGE_DIR=$(BIN_DIR)/coverage
SCRIPTS_DIR=$(ROOT_DIR)/scripts
SCRIPTS_DIR=$(ROOT_DIR)/build/ci/scripts

# Docker image variables.
REGISTRY ?= localhost
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ The `peerd` container image is available at `ghcr.io/azure/acr/peerd`. To deploy
CLUSTER_CONTEXT=<your-cluster-context> && \
TAG=v0.0.2-alpha && \
HELM_RELEASE_NAME=peerd && \
HELM_CHART_DIR=./build/ci/k8s/peerd-helm && \
HELM_CHART_DIR=./build/package/peerd-helm && \
helm --kube-context=$CLUSTER_CONTEXT install --wait $HELM_RELEASE_NAME $HELM_CHART_DIR \
--set peerd.image.ref=ghcr.io/azure/acr/dev/peerd:$TAG
```
Expand All @@ -71,7 +71,7 @@ as well, run the following.
CLUSTER_CONTEXT=<your-cluster-context> && \
TAG=v0.0.2-alpha && \
HELM_RELEASE_NAME=peerd && \
HELM_CHART_DIR=./build/ci/k8s/peerd-helm && \
HELM_CHART_DIR=./build/package/peerd-helm && \
helm --kube-context=$CLUSTER_CONTEXT install --wait $HELM_RELEASE_NAME $HELM_CHART_DIR \
--set peerd.image.ref=ghcr.io/azure/acr/dev/peerd:$TAG
--set peerd.hosts="mcr.microsoft.com ghcr.io docker.io"
Expand Down Expand Up @@ -279,7 +279,7 @@ integration with [Overlaybd].
[DADI P2P Proxy]: https://github.com/data-accelerator/dadi-p2proxy
[containerd hosts]: https://github.com/containerd/containerd/blob/main/docs/hosts.md
[containerd-mirror]: ./internal/containerd/mirror.go
[helm chart]: ./build/ci/k8s/peerd-helm
[helm chart]: ./build/package/peerd-helm
[CodeQL]: https://github.com/Azure/peerd/actions/workflows/github-code-scanning/codeql/badge.svg?branch=main
[code-ql]: https://github.com/Azure/peerd/actions/workflows/github-code-scanning/codeql
[Azure Blob]: https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blobs-introduction
Expand Down
28 changes: 21 additions & 7 deletions build/ci/Makefile
Original file line number Diff line number Diff line change
@@ -1,40 +1,54 @@
.PHONY: tests-deps-install
tests-deps-install: ## Install dependencies for testing (supported only on Ubuntu)
@echo "+ $@"
sudo $(ROOT_DIR)/build/ci/scripts/install-deps.sh
sudo $(SCRIPTS_DIR)/install-deps.sh

.PHONY: kind-create
kind-create: ## Creates a kind cluster
@echo "+ $@"
@( $(ROOT_DIR)/build/ci/scripts/kind.sh cluster create -y )
@( $(SCRIPTS_DIR)/kind.sh cluster create -y )

.PHONY: kind-get
kind-get: ## Shows the current kind cluster
@echo "+ $@"
@( $(ROOT_DIR)/build/ci/scripts/kind.sh cluster get -y )
@( $(SCRIPTS_DIR)/kind.sh cluster get -y )

.PHONY: kind-delete
kind-delete: ## Deletes kind cluster
@echo "+ $@"
@( $(ROOT_DIR)/build/ci/scripts/kind.sh cluster delete -y )
@( $(SCRIPTS_DIR)/kind.sh cluster delete -y )

.PHONY: kind-deploy
kind-deploy: ## Deploys the p2p application to kind cluster
@echo "+ $@"
ifndef CONTAINER_REGISTRY
$(eval CONTAINER_REGISTRY := $(shell echo "localhost"))
endif
@( $(ROOT_DIR)/build/ci/scripts/kind.sh app deploy -y $(CONTAINER_REGISTRY)/peerd:dev )
@( $(SCRIPTS_DIR)/kind.sh app deploy -y $(CONTAINER_REGISTRY)/peerd:dev )

.PHONY: kind-test-ctr
kind-test-ctr: ## Deploys test 'ctr' to the kind cluster
@echo "+ $@"
@( $(ROOT_DIR)/build/ci/scripts/kind.sh test ctr -y )
@( $(SCRIPTS_DIR)/kind.sh test ctr -y )

.PHONY: kind-test-random
kind-test-random: ## Deploys test 'random' to the kind cluster
@echo "+ $@"
ifndef CONTAINER_REGISTRY
$(eval CONTAINER_REGISTRY := $(shell echo "localhost"))
endif
@( $(ROOT_DIR)/build/ci/scripts/kind.sh test random -y $(CONTAINER_REGISTRY)/random:dev )
@( $(SCRIPTS_DIR)/kind.sh test random -y $(CONTAINER_REGISTRY)/random:dev )

.PHONY: tests-ci-aks
tests-ci-aks: ## Run CI in AKS
@echo "+ $@"
ifndef NODEPOOL
$(eval NODEPOOL := $(shell date +"p2p%y%m%d"))
endif
ifndef PEERD_IMAGE_TAG
$(eval PEERD_IMAGE_TAG := "dev")
endif
@echo "\033[92mRunning CI NODEPOOL: $(NODEPOOL)\033[0m"
@( PEERD_IMAGE_TAG=$(PEERD_IMAGE_TAG) $(SCRIPTS_DIR)/azure.sh nodepool up -y $(NODEPOOL) )
@( $(SCRIPTS_DIR)/azure.sh test ctr -y $(NODEPOOL) )
@( $(SCRIPTS_DIR)/azure.sh nodepool delete -y $(NODEPOOL) )
9 changes: 0 additions & 9 deletions build/ci/k8s/test-random.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ spec:
labels:
app: *name
spec:
# affinity:
# nodeAffinity:
# requiredDuringSchedulingIgnoredDuringExecution:
# nodeSelectorTerms:
# - matchExpressions:
# - key: p2p-nodepool
# operator: In
# values:
# - 'true'
containers:
- image: $TEST_RANDOM_CONTAINER_IMAGE
imagePullPolicy: Never
Expand Down
6 changes: 3 additions & 3 deletions scripts/azure.sh → build/ci/scripts/azure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/env.sh

PEERD_HELM_CHART="$SCRIPT_DIR/../build/ci/k8s/peerd-helm"
PEERD_HELM_CHART="$SCRIPT_DIR/../build/package/peerd-helm"
TESTS_AZURE_CLI_DEPLOY_TEMPLATE=$SCRIPT_DIR/../build/ci/k8s/azure-cli.yml

show_help() {
Expand Down Expand Up @@ -112,7 +112,7 @@ wait_for_peerd_pods() {
fi

# Loop until all pods are connected or an error occurs.
for ((i=1; i<=100; i++)); do
for ((i=1; i<=10; i++)); do
# Initialize a counter for connected pods.
found=0

Expand All @@ -131,7 +131,7 @@ wait_for_peerd_pods() {
echo "Success: All pods have event '$event'."
break
else
echo "Waiting: $found out of $total pods have event '$event'. Attempt $i of 100."
echo "Waiting: $found out of $total pods have event '$event'. Attempt $i of 10."
sleep 15
fi
done
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion build/ci/scripts/kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
KIND_CLUSTER_NAME="p2p"
KIND_CLUSTER_CONTEXT="kind-$KIND_CLUSTER_NAME"
CLUSTER_CONFIG_FILE="$SCRIPT_DIR/../k8s/kind-cluster.yml"
HELM_CHART_DIR="$SCRIPT_DIR/../k8s/peerd-helm"
HELM_CHART_DIR="$SCRIPT_DIR/../../package/peerd-helm"
HELM_RELEASE_NAME="peerd"
export GIT_ROOT="$(git rev-parse --show-toplevel)"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 0 additions & 14 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,3 @@ ifndef CONTAINER_REGISTRY
$(eval CONTAINER_REGISTRY := localhost)
endif
$(call build-image-internal,$(ROOT_DIR)/tests/dockerfiles/random.Dockerfile,random,$(ROOT_DIR))

.PHONY: tests-ci-aks
tests-ci-aks: ## Run CI in AKS
@echo "+ $@"
ifndef NODEPOOL
$(eval NODEPOOL := $(shell date +"p2p%y%m%d"))
endif
ifndef PEERD_IMAGE_TAG
$(eval PEERD_IMAGE_TAG := "dev")
endif
@echo "\033[92mRunning CI NODEPOOL: $(NODEPOOL)\033[0m"
@( PEERD_IMAGE_TAG=$(PEERD_IMAGE_TAG) $(ROOT_DIR)/scripts/azure.sh nodepool up -y $(NODEPOOL) )
@( $(ROOT_DIR)/scripts/azure.sh test ctr -y $(NODEPOOL) )
@( $(ROOT_DIR)/scripts/azure.sh nodepool delete -y $(NODEPOOL) )

0 comments on commit 8c53c30

Please sign in to comment.