Skip to content

Commit

Permalink
Fix chaos enviromnent (#897)
Browse files Browse the repository at this point in the history
* chore: add chaos setup

* chore add files to ignore

* chore: diferentiate linux from macos

* negate linux aarch64

* fix: chaos env
  • Loading branch information
renancloudwalk authored May 22, 2024
1 parent 7e28bc7 commit 95f1fe4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 32 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
!docker/
!docker/Dockerfile.run_with_importer
!src/
!.cargo/
!Cargo.toml
!Cargo.lock
!static/
Expand Down
57 changes: 33 additions & 24 deletions chaos/install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
#!/bin/sh

echo "Checking OS and installing dependencies..."

if [ "$(uname)" = "Darwin" ]; then
echo "Installing dependencies for macOS..."
if ! [ -x "$(command -v kind)" ]; then
brew install kind
fi
if ! [ -x "$(command -v kubectl)" ]; then
brew install kubectl
fi
#!/bin/bash

set -e

echo "Checking if Kind cluster exists..."
if ! kind get clusters | grep -q local-testing; then
echo "Setting up Kind cluster..."
kind create cluster --name local-testing
kind get kubeconfig --name local-testing > kubeconfig.yaml
else
echo "Installing dependencies for Linux..."
if ! [ -x "$(command -v kind)" ]; then
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
fi
if ! [ -x "$(command -v kubectl)" ]; then
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
fi
echo "Kind cluster already exists."
fi

echo "Dependencies installed"
echo "Configuring kubectl to use Kind cluster..."
export KUBECONFIG=$(pwd)/kubeconfig.yaml

echo "Checking if Docker image is already built..."
if ! docker images | grep -q local/run_with_importer; then
echo "Building Docker image..."
docker build -t local/run_with_importer -f ./docker/Dockerfile.run_with_importer .
else
echo "Docker image already built."
fi

echo "Loading Docker image into Kind..."
kind load docker-image local/run_with_importer --name local-testing

echo "Deploying application..."
kubectl apply -f chaos/local-deployment.yaml
kubectl apply -f chaos/local-service.yaml

echo "Waiting for pods to be ready..."
kubectl wait --for=condition=ready pod -l app=stratus-api --timeout=180s

echo "Deployment complete. Checking pod status..."
kubectl get pods -o wide
1 change: 1 addition & 0 deletions docker/Dockerfile.run_with_importer
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ COPY .sqlx /app/.sqlx
COPY build.rs /app/build.rs
COPY Cargo.toml /app/Cargo.toml
COPY Cargo.lock /app/Cargo.lock
COPY .cargo .cargo

RUN apt update
RUN apt-get install -y libclang-dev cmake
Expand Down
23 changes: 15 additions & 8 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -450,15 +450,23 @@ local-chaos-setup:
@echo $(pwd)
@echo "Installing dependencies..."
./chaos/install-dependencies.sh
@echo "Cleaning up any existing Kind cluster..."
kind delete cluster --name local-testing || true
@echo "Setting up Kind cluster..."
kind create cluster --name local-testing
@echo "Checking if Kind cluster exists..."
if ! kind get clusters | grep -q local-testing; then \
echo "Setting up Kind cluster..."; \
kind create cluster --name local-testing; \
kind get kubeconfig --name local-testing > kubeconfig.yaml; \
else \
echo "Kind cluster already exists."; \
fi
@echo "Configuring kubectl to use Kind cluster..."
kind get kubeconfig --name local-testing > kubeconfig.yaml
export KUBECONFIG=$(pwd)/kubeconfig.yaml
@echo "Building Docker image..."
docker build -t local/run_with_importer -f ./docker/Dockerfile.run_with_importer .
@echo "Checking if Docker image is already built..."
if ! docker images | grep -q local/run_with_importer; then \
echo "Building Docker image..."; \
docker build -t local/run_with_importer -f ./docker/Dockerfile.run_with_importer .; \
else \
echo "Docker image already built."; \
fi
@echo "Loading Docker image into Kind..."
kind load docker-image local/run_with_importer --name local-testing
@echo "Deploying application..."
Expand All @@ -475,7 +483,6 @@ local-chaos-cleanup:
kind delete cluster --name local-testing
@echo "Cleanup complete."


# Chaos Testing: Run chaos test
local-chaos-test:
just local-chaos-setup
Expand Down

0 comments on commit 95f1fe4

Please sign in to comment.