2019-01-16 19:22:44 +01:00
variables :
GIT_SUBMODULE_STRATEGY : none
CI_DISPOSABLE_ENVIRONMENT : "true"
2019-11-11 14:13:52 +01:00
DOCKER_DRIVER : overlay2
DOCKER_HOST : tcp://localhost:2375
DOCKER_TLS_CERTDIR : ""
2021-07-15 20:36:14 +02:00
API_IMAGE : us.gcr.io/satellite-api/satellite-api
SSE_IMAGE : us.gcr.io/satellite-api/satellite-api-sse
2019-11-11 14:13:52 +01:00
2021-03-29 17:34:55 +02:00
image : blockstream/gcloud-docker:v0.14.5
2019-01-16 19:22:44 +01:00
stages :
2021-07-20 17:05:29 +02:00
- test
2019-01-16 19:22:44 +01:00
- build
- plan
- deploy
before_script :
- TMPF=$(mktemp) || exit 1
2019-02-13 23:36:26 +01:00
- echo $GCLOUD_KEY > $TMPF
2019-01-16 19:22:44 +01:00
- export GOOGLE_APPLICATION_CREDENTIALS=$TMPF
- gcloud auth activate-service-account --key-file=$TMPF
2021-07-16 15:49:29 +02:00
- gcloud auth configure-docker
2019-01-16 19:22:44 +01:00
- gcloud auth list
- gcloud --version
2021-07-15 20:36:14 +02:00
# Run the unit tests
unit_tests :
2021-07-20 17:05:29 +02:00
stage : test
image : python:3.9
2020-03-10 15:29:55 +01:00
tags :
2021-07-20 17:05:29 +02:00
- k8s
2021-07-16 17:59:40 +02:00
except :
- cleanup_staging@satellite/ionosphere
- /^staging_.*/
- /^prod_.*/
- /^misc_.*/
2019-05-20 19:11:45 +02:00
before_script :
2021-07-20 17:05:29 +02:00
- pip install flake8 yapf pytest pytest-cov
- pip install -r server/requirements.txt
- pip install -r server/test_requirements.txt
2019-05-20 19:11:45 +02:00
script :
2021-07-20 17:05:29 +02:00
- flake8 .
- yapf --diff --recursive --verbose server/
- cd server/ && python -m pytest --cov=.
2019-05-20 19:11:45 +02:00
2021-07-15 20:36:14 +02:00
# Test the Satellite API docker image build
docker_build :
stage : build
tags :
- k8s-docker
services :
- docker:19-dind
only :
- branches@satellite/ionosphere
2021-07-16 17:59:40 +02:00
except :
- cleanup_staging@satellite/ionosphere
- /^staging_.*/
- /^prod_.*/
- /^misc_.*/
2021-07-15 20:36:14 +02:00
parallel :
matrix :
- IMAGE : $API_IMAGE
DIR : server
- IMAGE : $SSE_IMAGE
DIR : sse
script :
- cd $DIR
- docker pull $IMAGE:$CI_COMMIT_REF_SLUG || docker pull $IMAGE:latest || true
- >
docker build
-f Dockerfile
--network=host
--cache-from $IMAGE:$CI_COMMIT_REF_SLUG
--cache-from $IMAGE:latest
--build-arg BUILDKIT_INLINE_CACHE=1
.
# Build and push the Satellite API docker image
docker_push :
2019-01-16 19:22:44 +01:00
stage : build
2019-11-11 14:13:52 +01:00
tags :
2020-12-07 18:46:08 +01:00
- k8s-docker
2021-07-16 16:27:45 +02:00
when : manual
2020-12-07 18:46:08 +01:00
services :
- docker:19-dind
2019-01-16 19:22:44 +01:00
only :
2021-07-16 16:27:45 +02:00
- branches@satellite/ionosphere
2021-07-15 20:36:14 +02:00
parallel :
matrix :
- IMAGE : $API_IMAGE
DIR : server
- IMAGE : $SSE_IMAGE
DIR : sse
2019-01-16 19:22:44 +01:00
script :
2021-07-15 20:36:14 +02:00
- cd $DIR
- docker pull $IMAGE:$CI_COMMIT_REF_SLUG || docker pull $IMAGE:latest || true
- >
docker build
-f Dockerfile
--network=host
--cache-from $IMAGE:$CI_COMMIT_REF_SLUG
--cache-from $IMAGE:latest
--build-arg BUILDKIT_INLINE_CACHE=1
-t $IMAGE:$CI_COMMIT_SHA
-t $IMAGE:$CI_COMMIT_REF_SLUG
-t $IMAGE:latest
.
- docker push $IMAGE:$CI_COMMIT_SHA
- docker push $IMAGE:$CI_COMMIT_REF_SLUG
- if [ $CI_COMMIT_BRANCH == "master" ]; then docker push $IMAGE:latest; fi
2019-01-16 19:22:44 +01:00
2019-02-20 19:57:02 +01:00
# Any newly-pushed, WIP branch will be ran through plan (keep in mind docker images are using the latest tag, which may be an older one since the current commit may not match an available image)
2019-01-18 23:57:15 +01:00
plan_satapi :
2019-01-16 19:22:44 +01:00
stage : plan
2020-03-10 15:29:55 +01:00
tags :
- k8s
2019-01-16 19:22:44 +01:00
only :
- branches@satellite/ionosphere
except :
- cleanup_staging@satellite/ionosphere
2019-01-29 21:17:51 +01:00
- /^staging_.*/
- /^prod_.*/
2019-01-18 23:57:15 +01:00
- /^misc_.*/
2019-01-16 19:22:44 +01:00
script :
- (cd terraform
&& terraform init -input=false
&& terraform workspace select staging
2020-09-26 00:12:36 +02:00
&& terraform init -input=false
2019-01-16 19:22:44 +01:00
&& terraform plan
2021-07-15 20:36:14 +02:00
-var "ionosphere_docker=$API_IMAGE:$CI_COMMIT_SHA"
-var "ionosphere_sse_docker=$SSE_IMAGE:$CI_COMMIT_SHA"
2019-01-16 19:22:44 +01:00
-var "region=$REGION"
-var "zone=$ZONE"
-var "instance_type=$INSTANCE_TYPE"
-var "host=$HOST_STAGING"
-var "timeout=$TIMEOUT"
-var "prom_service_acct=$PROM_SA"
-var "opsgenie_key=$OPSGENIE_KEY"
2019-06-13 18:01:23 +02:00
-var "public_bucket_url=$PUBLIC_BUCKET_URL"
2019-09-06 20:43:25 +02:00
-var "private_bucket=$PRIVATE_BUCKET"
2019-06-13 18:01:23 +02:00
-var "letsencrypt_email=$LE_EMAIL"
2019-08-07 01:47:59 +02:00
-var "charge_token=$CHARGE_TOKEN"
2019-09-05 04:18:20 +02:00
-var "rpcpass=$RPCPASS"
2019-08-07 01:47:59 +02:00
-var "k8s_autossh_lb=$GKE_LB"
2021-01-26 18:05:45 +01:00
-var "station1=$STATION_1"
-var "station2=$STATION_2"
2019-01-16 19:22:44 +01:00
-input=false)
2019-11-11 14:13:52 +01:00
2019-03-07 21:29:43 +01:00
# This plan gets triggered only for miscellaneous branches/tags (i.e. tor, prometheus, etc), so make sure the branch/tag name starts with misc_
2019-01-18 23:57:15 +01:00
plan_misc :
stage : plan
2020-03-10 15:29:55 +01:00
tags :
- k8s
2021-07-20 14:55:50 +02:00
only :
2019-01-19 00:15:42 +01:00
- /^misc_v.*/
2019-01-18 23:57:15 +01:00
script :
- (echo -n "$V3_PK" > terraform/modules/tor/v3.pk)
- (echo -n "$V3_PUBK" > terraform/modules/tor/v3.pubk)
- (cd terraform
&& terraform init -input=false
&& terraform workspace select misc
2020-09-26 00:12:36 +02:00
&& terraform init -input=false
2019-01-18 23:57:15 +01:00
&& terraform plan
-var "region=$REGION"
-var "zone=$ZONE"
2019-02-27 01:44:51 +01:00
-var "instance_type=$INSTANCE_TYPE"
2019-01-18 23:57:15 +01:00
-var "onion_host=$ONION_HOST"
2019-02-27 01:44:51 +01:00
-var "prom_allowed_source_ip=$PROMETHEUS_ALLOWED_SOURCE_IP"
2019-02-26 23:03:37 +01:00
-var "prom_service_acct=$PROM_SA"
2019-02-27 21:47:01 +01:00
-var "opsgenie_key=$OPSGENIE_KEY"
2019-02-26 23:03:37 +01:00
-var "satellite_lb=$SATELLITE_LB"
-var "satellite_api_lb=$SATELLITE_API_LB"
-var "satellite_api_lb_staging=$SATELLITE_API_LB_STAGING"
2021-02-23 16:33:03 +01:00
-var "blocksat_monitoring=$BLOCKSAT_MONITORING_LB"
2019-01-18 23:57:15 +01:00
-input=false)
2019-03-07 21:29:43 +01:00
# This deploys only tags/branches starting with misc_v.* (i.e. tor, prometheus, etc)
deploy_misc :
stage : deploy
2021-07-20 14:55:50 +02:00
when : manual
2020-03-10 15:29:55 +01:00
tags :
- k8s
2019-03-07 21:29:43 +01:00
only :
- /^misc_v.*/
script :
- (echo -n "$V3_PK" > terraform/modules/tor/v3.pk)
- (echo -n "$V3_PUBK" > terraform/modules/tor/v3.pubk)
- (cd terraform
&& terraform init -input=false
&& terraform workspace select misc
2020-09-26 00:12:36 +02:00
&& terraform init -input=false
2019-03-07 21:29:43 +01:00
&& terraform apply
-var "region=$REGION"
-var "zone=$ZONE"
-var "instance_type=$INSTANCE_TYPE"
-var "onion_host=$ONION_HOST"
-var "prom_allowed_source_ip=$PROMETHEUS_ALLOWED_SOURCE_IP"
-var "prom_service_acct=$PROM_SA"
-var "opsgenie_key=$OPSGENIE_KEY"
-var "satellite_lb=$SATELLITE_LB"
-var "satellite_api_lb=$SATELLITE_API_LB"
-var "satellite_api_lb_staging=$SATELLITE_API_LB_STAGING"
2021-02-23 16:33:03 +01:00
-var "blocksat_monitoring=$BLOCKSAT_MONITORING_LB"
2019-06-13 18:01:23 +02:00
-input=false -auto-approve)
2019-03-07 21:29:43 +01:00
2019-09-05 02:29:16 +02:00
# Tag with staging_v.* to plan mainnet + LB to staging (e.g. staging_v0.1.1)
plan_staging :
stage : plan
2020-03-10 15:29:55 +01:00
tags :
- k8s
2019-09-05 02:29:16 +02:00
only :
- /^staging_v.*/
script :
- (cd terraform
&& terraform init -input=false
&& terraform workspace select staging
2020-09-26 00:12:36 +02:00
&& terraform init -input=false
2019-09-05 02:29:16 +02:00
&& terraform plan
2021-07-15 20:36:14 +02:00
-var "ionosphere_docker=$API_IMAGE:$CI_COMMIT_SHA"
-var "ionosphere_sse_docker=$SSE_IMAGE:$CI_COMMIT_SHA"
2019-09-05 02:29:16 +02:00
-var "region=$REGION"
-var "zone=$ZONE"
-var "instance_type=$INSTANCE_TYPE"
-var "host=$HOST_STAGING"
-var "timeout=$TIMEOUT"
-var "prom_service_acct=$PROM_SA"
-var "opsgenie_key=$OPSGENIE_KEY"
-var "public_bucket_url=$PUBLIC_BUCKET_URL"
2019-09-06 20:43:25 +02:00
-var "private_bucket=$PRIVATE_BUCKET"
2019-09-05 02:29:16 +02:00
-var "letsencrypt_email=$LE_EMAIL"
-var "charge_token=$CHARGE_TOKEN"
-var "rpcpass=$RPCPASS"
-var "k8s_autossh_lb=$GKE_LB"
2021-01-26 18:05:45 +01:00
-var "station1=$STATION_1"
-var "station2=$STATION_2"
2019-09-05 02:29:16 +02:00
-input=false)
# Tag with staging_v.* to deploy mainnet + LB to staging (e.g. staging_v0.1.1)
2019-01-16 19:22:44 +01:00
deploy_staging :
stage : deploy
2019-09-05 02:29:16 +02:00
when : manual
2020-03-10 15:29:55 +01:00
tags :
- k8s
2019-01-16 19:22:44 +01:00
only :
2019-01-29 21:17:51 +01:00
- /^staging_v.*/
2019-01-16 19:22:44 +01:00
script :
- (cd terraform
&& terraform init -input=false
&& terraform workspace select staging
2020-09-26 00:12:36 +02:00
&& terraform init -input=false
2019-01-16 19:22:44 +01:00
&& terraform apply
2021-07-15 20:36:14 +02:00
-var "ionosphere_docker=$API_IMAGE:$CI_COMMIT_SHA"
-var "ionosphere_sse_docker=$SSE_IMAGE:$CI_COMMIT_SHA"
2019-01-16 19:22:44 +01:00
-var "region=$REGION"
-var "zone=$ZONE"
-var "instance_type=$INSTANCE_TYPE"
-var "host=$HOST_STAGING"
-var "timeout=$TIMEOUT"
-var "prom_service_acct=$PROM_SA"
-var "opsgenie_key=$OPSGENIE_KEY"
2019-06-13 18:01:23 +02:00
-var "public_bucket_url=$PUBLIC_BUCKET_URL"
2019-09-06 20:43:25 +02:00
-var "private_bucket=$PRIVATE_BUCKET"
2019-06-13 18:01:23 +02:00
-var "letsencrypt_email=$LE_EMAIL"
2019-08-07 01:47:59 +02:00
-var "charge_token=$CHARGE_TOKEN"
-var "rpcpass=$RPCPASS"
-var "k8s_autossh_lb=$GKE_LB"
2021-01-26 18:05:45 +01:00
-var "station1=$STATION_1"
-var "station2=$STATION_2"
2019-01-16 19:22:44 +01:00
-input=false -auto-approve)
2019-09-05 02:29:16 +02:00
# Tag with prod_v.* to plan mainnet + LB to production (e.g. prod_v0.1.1)
plan_production :
stage : plan
2020-03-10 15:29:55 +01:00
tags :
- k8s
2019-09-05 02:29:16 +02:00
only :
- /^prod_v.*/
script :
- (cd terraform
&& terraform init -input=false
&& terraform workspace select prod
2020-09-26 00:12:36 +02:00
&& terraform init -input=false
2019-09-05 02:29:16 +02:00
&& terraform plan
2021-07-15 20:36:14 +02:00
-var "ionosphere_docker=$API_IMAGE:$CI_COMMIT_SHA"
-var "ionosphere_sse_docker=$SSE_IMAGE:$CI_COMMIT_SHA"
2019-09-05 02:29:16 +02:00
-var "region=$REGION"
-var "zone=$ZONE"
-var "instance_type=$INSTANCE_TYPE"
-var "host=$HOST"
-var "timeout=$TIMEOUT"
-var "prom_service_acct=$PROM_SA"
-var "opsgenie_key=$OPSGENIE_KEY"
-var "public_bucket_url=$PUBLIC_BUCKET_URL"
2019-09-06 20:43:25 +02:00
-var "private_bucket=$PRIVATE_BUCKET"
2019-09-05 02:29:16 +02:00
-var "letsencrypt_email=$LE_EMAIL"
-var "charge_token=$CHARGE_TOKEN"
-var "rpcpass=$RPCPASS"
-var "k8s_autossh_lb=$GKE_LB"
2021-01-26 18:05:45 +01:00
-var "station1=$STATION_1"
-var "station2=$STATION_2"
2019-09-05 02:29:16 +02:00
-input=false)
# Tag with prod_v.* to deploy mainnet + LB to production (e.g. prod_v0.1.1)
2019-01-16 19:22:44 +01:00
deploy_production :
stage : deploy
2019-09-05 02:29:16 +02:00
when : manual
2020-03-10 15:29:55 +01:00
tags :
- k8s
2019-01-16 19:22:44 +01:00
only :
2019-01-29 21:17:51 +01:00
- /^prod_v.*/
2019-01-16 19:22:44 +01:00
script :
- (cd terraform
&& terraform init -input=false
&& terraform workspace select prod
2020-09-26 00:12:36 +02:00
&& terraform init -input=false
2019-01-16 19:22:44 +01:00
&& terraform apply
2021-07-15 20:36:14 +02:00
-var "ionosphere_docker=$API_IMAGE:$CI_COMMIT_SHA"
-var "ionosphere_sse_docker=$SSE_IMAGE:$CI_COMMIT_SHA"
2019-01-16 19:22:44 +01:00
-var "region=$REGION"
-var "zone=$ZONE"
-var "instance_type=$INSTANCE_TYPE"
-var "host=$HOST"
-var "timeout=$TIMEOUT"
-var "prom_service_acct=$PROM_SA"
-var "opsgenie_key=$OPSGENIE_KEY"
2019-06-13 18:01:23 +02:00
-var "public_bucket_url=$PUBLIC_BUCKET_URL"
2019-09-06 20:43:25 +02:00
-var "private_bucket=$PRIVATE_BUCKET"
2019-06-13 18:01:23 +02:00
-var "letsencrypt_email=$LE_EMAIL"
2019-08-07 01:47:59 +02:00
-var "charge_token=$CHARGE_TOKEN"
-var "rpcpass=$RPCPASS"
-var "k8s_autossh_lb=$GKE_LB"
2021-01-26 18:05:45 +01:00
-var "station1=$STATION_1"
-var "station2=$STATION_2"
2019-01-16 19:22:44 +01:00
-input=false -auto-approve)
2019-09-07 00:33:25 +02:00
# Tag with testnet_prod_v.* to plan testnet to production (e.g. testnet_prod_v0.1.1)
2019-09-05 02:29:16 +02:00
plan_production_testnet :
stage : plan
2020-03-10 15:29:55 +01:00
tags :
- k8s
2019-09-05 02:29:16 +02:00
only :
- /^testnet_prod_v.*/
script :
- (cd terraform
&& terraform init -input=false
&& terraform workspace select testnet-prod
2020-09-26 00:12:36 +02:00
&& terraform init -input=false
2019-09-05 02:29:16 +02:00
&& terraform plan
2021-07-15 20:36:14 +02:00
-var "ionosphere_docker=$API_IMAGE:$CI_COMMIT_SHA"
-var "ionosphere_sse_docker=$SSE_IMAGE:$CI_COMMIT_SHA"
2019-09-05 02:29:16 +02:00
-var "region=$REGION"
-var "zone=$ZONE"
-var "instance_type=$INSTANCE_TYPE"
-var "timeout=$TIMEOUT"
-var "prom_service_acct=$PROM_SA"
-var "opsgenie_key=$OPSGENIE_KEY"
-var "public_bucket_url=$PUBLIC_BUCKET_URL"
2019-09-06 20:43:25 +02:00
-var "private_bucket=$PRIVATE_BUCKET"
2019-09-05 02:29:16 +02:00
-var "letsencrypt_email=$LE_EMAIL"
-var "charge_token=$CHARGE_TOKEN"
2019-09-05 04:18:20 +02:00
-var "rpcpass=$RPCPASS_TESTNET"
2019-09-05 02:29:16 +02:00
-var "k8s_autossh_lb=$GKE_LB"
-input=false)
# Tag with testnet_prod_v.* to deploy testnet to production (e.g. testnet_prod_v0.1.1)
2019-03-07 21:29:43 +01:00
deploy_production_testnet :
stage : deploy
2019-09-05 02:29:16 +02:00
when : manual
2020-03-10 15:29:55 +01:00
tags :
- k8s
2019-03-07 21:29:43 +01:00
only :
- /^testnet_prod_v.*/
script :
- (cd terraform
&& terraform init -input=false
&& terraform workspace select testnet-prod
2020-09-26 00:12:36 +02:00
&& terraform init -input=false
2019-03-07 21:29:43 +01:00
&& terraform apply
2021-07-15 20:36:14 +02:00
-var "ionosphere_docker=$API_IMAGE:$CI_COMMIT_SHA"
-var "ionosphere_sse_docker=$SSE_IMAGE:$CI_COMMIT_SHA"
2019-03-07 21:29:43 +01:00
-var "region=$REGION"
-var "zone=$ZONE"
-var "instance_type=$INSTANCE_TYPE"
-var "timeout=$TIMEOUT"
-var "prom_service_acct=$PROM_SA"
-var "opsgenie_key=$OPSGENIE_KEY"
2019-06-13 18:01:23 +02:00
-var "public_bucket_url=$PUBLIC_BUCKET_URL"
2019-09-06 20:43:25 +02:00
-var "private_bucket=$PRIVATE_BUCKET"
2019-06-13 18:01:23 +02:00
-var "letsencrypt_email=$LE_EMAIL"
2019-08-07 01:47:59 +02:00
-var "charge_token=$CHARGE_TOKEN"
-var "rpcpass=$RPCPASS_TESTNET"
-var "k8s_autossh_lb=$GKE_LB"
2019-01-18 23:57:15 +01:00
-input=false -auto-approve)
2019-01-29 21:17:51 +01:00
# Pushing to this branch destroys the staging infrastructure
2019-01-16 19:22:44 +01:00
cleanup_staging :
stage : deploy
2020-03-10 15:29:55 +01:00
tags :
- k8s
2019-01-16 19:22:44 +01:00
only :
- cleanup_staging@satellite/ionosphere
script :
- (cd terraform && terraform init -input=false &&
terraform workspace select staging &&
terraform destroy
-target module.blc.google_compute_instance_group_manager.blc
2019-06-13 18:01:23 +02:00
-target module.lb.google_compute_region_instance_group_manager.satapi-lb
2019-01-16 19:22:44 +01:00
-auto-approve)
2019-03-07 21:29:43 +01:00
- (cd terraform && terraform init -input=false &&
terraform workspace select testnet-staging &&
terraform destroy
-target module.blc.google_compute_instance_group_manager.blc
-auto-approve)