-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sandbox): basic-ci-setup (#298)
- Loading branch information
1 parent
3b09e1f
commit f33ee62
Showing
14 changed files
with
217 additions
and
27 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
pipeline { | ||
agent { label 'jenkins-dynamic-slave' } | ||
stages { | ||
stage('Build') { | ||
steps { | ||
dir("sandbox"){ | ||
sh "chmod +x ./ci_build.sh" | ||
withCredentials([usernamePassword('credentialsId': 'sf-reference-arch-dockerhub', 'usernameVariable': 'DOCKER_USERNAME', 'passwordVariable': 'DOCKER_PASSWORD')]) { | ||
sh "./ci_build.sh ${env.WORKSPACE}/sandbox true" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#!/bin/bash | ||
CURRENT_DIR=$1 | ||
INSTALL_MICROK8S=$2 | ||
LOCAL_REGISTRY='localhost:32000' | ||
|
||
install_kubectl() { | ||
sudo apt-get update -y | ||
sudo apt-get install -y apt-transport-https ca-certificates curl | ||
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg | ||
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list | ||
sudo apt-get update -y | ||
sudo apt-get install -y kubectl | ||
kubectl cluster-info | ||
} | ||
|
||
install_microk8s() { | ||
sudo snap install microk8s --classic | ||
microk8s status --wait-ready | ||
microk8s enable dns registry ingress | ||
microk8s kubectl get all --all-namespaces | ||
pushd $HOME | ||
mkdir -p .kube | ||
microk8s config >.kube/config | ||
popd | ||
} | ||
|
||
local_docker_push() { | ||
docker push ${LOCAL_REGISTRY}/auth-multitenant-example | ||
docker push ${LOCAL_REGISTRY}/notification-socket-example | ||
docker push ${LOCAL_REGISTRY}/workflow-ms-example | ||
docker push ${LOCAL_REGISTRY}/audit-ms-example | ||
docker push ${LOCAL_REGISTRY}/scheduler-example | ||
docker push ${LOCAL_REGISTRY}/video-conferencing-ms-example | ||
docker push ${LOCAL_REGISTRY}/in-mail-example | ||
} | ||
|
||
docker_push() { | ||
docker tag ${LOCAL_REGISTRY}/auth-multitenant-example ${DOCKER_USERNAME}/auth-multitenant-example | ||
docker tag ${LOCAL_REGISTRY}/notification-socket-example ${DOCKER_USERNAME}/notification-socket-example | ||
docker tag ${LOCAL_REGISTRY}/workflow-ms-example ${DOCKER_USERNAME}/workflow-ms-example | ||
docker tag ${LOCAL_REGISTRY}/audit-ms-example ${DOCKER_USERNAME}/audit-ms-example | ||
docker tag ${LOCAL_REGISTRY}/scheduler-example ${DOCKER_USERNAME}/scheduler-example | ||
docker tag ${LOCAL_REGISTRY}/video-conferencing-ms-example ${DOCKER_USERNAME}/video-conferencing-ms-example | ||
docker tag ${LOCAL_REGISTRY}/in-mail-example ${DOCKER_USERNAME}/in-mail-example | ||
|
||
docker push ${DOCKER_USERNAME}/auth-multitenant-example | ||
docker push ${DOCKER_USERNAME}/notification-socket-example | ||
docker push ${DOCKER_USERNAME}/workflow-ms-example | ||
docker push ${DOCKER_USERNAME}/audit-ms-example | ||
docker push ${DOCKER_USERNAME}/scheduler-example | ||
docker push ${DOCKER_USERNAME}/video-conferencing-ms-example | ||
docker push ${DOCKER_USERNAME}/in-mail-example | ||
|
||
# TODO: should we clean up after build? Since agent is ephemeral, some caching may be helpful after an initial run | ||
# TODO: remove specific images and cache | ||
# docker system prune -a -f | ||
} | ||
|
||
terraform_apply() { | ||
pushd ${CURRENT_DIR}/k8s/tf-sourceloop-sandbox | ||
terraform init | ||
terraform apply -auto-approve | ||
popd | ||
} | ||
|
||
terraform_destroy() { | ||
pushd ${CURRENT_DIR}/k8s/tf-sourceloop-sandbox | ||
terraform destroy -auto-approve | ||
popd | ||
} | ||
|
||
run_tests() { | ||
echo "Sleeping to wait for services to come online." | ||
sleep 180 | ||
${CURRENT_DIR}/health_check.sh sourceloop.local true | ||
} | ||
|
||
if [ ! -z "${DOCKER_USERNAME}" ] && [ ! -z "${DOCKER_PASSWORD}" ]; then | ||
echo "Logging in to Docker" | ||
echo "${DOCKER_PASSWORD}" | docker login --username ${DOCKER_USERNAME} --password-stdin | ||
fi | ||
|
||
if [ -z "$CURRENT_DIR" ]; then | ||
CURRENT_DIR=$(echo $PWD) | ||
fi | ||
|
||
echo "CURRENT_DIR=$CURRENT_DIR" | ||
|
||
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o ${CURRENT_DIR}/docker-compose --insecure | ||
sudo chmod +x ${CURRENT_DIR}/docker-compose | ||
|
||
sudo REGISTRY=$LOCAL_REGISTRY ./docker-compose -f "${CURRENT_DIR}/docker-compose.yml" build | ||
|
||
if [ "${INSTALL_MICROK8S}" = "true" ]; then | ||
install_microk8s | ||
install_kubectl | ||
fi | ||
|
||
local_docker_push | ||
terraform_apply | ||
run_tests | ||
terraform_destroy | ||
docker_push |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
DOMAIN=$1 | ||
IS_LOCALHOST=$2 | ||
ERROR_COUNT=0 | ||
|
||
# check the basic health check on its own | ||
if [ "$IS_LOCALHOST" = "true" ]; then | ||
curl_response=$(curl -Is -H "Host: health-check.${DOMAIN}" https://localhost --insecure -f) | ||
else | ||
curl_response=$(curl -Is -H "Host: health-check.${DOMAIN}" https://health-check.${DOMAIN} --insecure -f) | ||
fi | ||
|
||
if [ -z "$curl_response" ]; then | ||
echo "health-check service is unhealthy" | ||
ERROR_COUNT=$((ERROR_COUNT + 1)) | ||
fi | ||
|
||
# TODO: Add video when it works - "video" | ||
declare -a services=("workflow" "scheduler" "notification" "in-mail" "auth" "audit") | ||
|
||
for service in "${services[@]}"; do | ||
if [ "$IS_LOCALHOST" = "true" ]; then | ||
curl_response=$(curl -Is -H "Host: ${service}.${DOMAIN}" https://localhost/openapi.json --insecure -f) | ||
else | ||
curl_response=$(curl -Is -H "Host: ${service}.${DOMAIN}" https://${service}.${DOMAIN}/openapi.json --insecure -f) | ||
fi | ||
|
||
if [ -z "$curl_response" ]; then | ||
echo "${service} service is unhealthy" | ||
ERROR_COUNT=$((ERROR_COUNT + 1)) | ||
fi | ||
done | ||
|
||
if (($ERROR_COUNT > 0)); then | ||
echo "${ERROR_COUNT} services are unhealthy" | ||
exit 1 | ||
else | ||
echo "All services are healthy" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
latest:^0.14 | ||
latest:^1.0.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
// TODO: make variables | ||
provider "kubectl" { | ||
load_config_file = true | ||
config_context = "sourceloop-sandbox" | ||
config_context_cluster = "microk8s-cluster" | ||
config_path = "~/.kube/config" | ||
} | ||
|
||
// TODO: make variables | ||
provider "kubernetes" { | ||
config_context = "sourceloop-sandbox" | ||
config_context_cluster = "microk8s-cluster" | ||
config_path = "~/.kube/config" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
terraform { | ||
required_version = ">= 0.14" | ||
required_version = ">= 1.0.3" | ||
|
||
|
||
required_providers { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters