-
Notifications
You must be signed in to change notification settings - Fork 70
/
ci_build.sh
executable file
·113 lines (96 loc) · 4.15 KB
/
ci_build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/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 ${LOCAL_REGISTRY}/search-ms-example
docker push ${LOCAL_REGISTRY}/chat-notification-pubnub-example
docker push ${LOCAL_REGISTRY}/feature-toggle-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 tag ${LOCAL_REGISTRY}/search-ms-example ${DOCKER_USERNAME}/search-ms-example
docker tag ${LOCAL_REGISTRY}/chat-notification-pubnub-example ${DOCKER_USERNAME}/chat-notification-pubnub-example
docker tag ${LOCAL_REGISTRY}/feature-toggle-example ${DOCKER_USERNAME}/feature-toggle-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
docker push ${DOCKER_USERNAME}/search-ms-example
docker push ${DOCKER_USERNAME}/chat-notification-pubnub-example
docker push ${DOCKER_USERNAME}/feature-toggle-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