blockstream-satellite-api/.gitlab-ci.yml

392 lines
14 KiB
YAML
Raw Normal View History

2019-01-16 19:22:44 +01:00
variables:
GIT_SUBMODULE_STRATEGY: none
CI_DISPOSABLE_ENVIRONMENT: "true"
2019-09-06 20:22:15 +02:00
image: blockstream/gcloud-docker@sha256:832d8a67d102fe4651ba96e51fe3a82287d0b3d1bf7eb5b5337286aa5b70b527
2019-01-16 19:22:44 +01:00
stages:
- build
- plan
- deploy
before_script:
- TMPF=$(mktemp) || exit 1
- 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
- gcloud auth list
- gcloud --version
2019-05-20 19:11:45 +02:00
# Run tests
test_build:
stage: build
2019-09-05 02:42:16 +02:00
image: blockstream/satapi-builder@sha256:a768bbd26e1b52dd681e122d35226943c043e9a35efeba45cea41a07d64357c4
2019-05-20 19:11:45 +02:00
only:
- branches@satellite/ionosphere
except:
- master@satellite/ionosphere
- cleanup_staging@satellite/ionosphere
2019-05-20 19:11:45 +02:00
before_script:
- export CHARGE_ROOT=$CHARGE_ROOT_CI
- export REDIS_URI=$REDIS_URI_CI
script:
- bundle exec rake db:create && bundle exec rake db:schema:load && bundle exec rake db:migrate
2019-05-21 13:40:08 +02:00
- bundle exec ruby tests/tests.rb || { echo -e "Tests failed..\n Sleeping for an hour to debug."; sleep 3600; exit 1; }
2019-05-20 19:11:45 +02:00
- echo "Tests passed!"
# Run tests and build docker images
2019-01-16 19:22:44 +01:00
build:
stage: build
2019-09-05 02:42:16 +02:00
image: blockstream/satapi-builder@sha256:a768bbd26e1b52dd681e122d35226943c043e9a35efeba45cea41a07d64357c4
2019-01-16 19:22:44 +01:00
only:
- master@satellite/ionosphere
before_script:
- export CHARGE_ROOT=$CHARGE_ROOT_CI
2019-02-28 02:27:27 +01:00
- export REDIS_URI=$REDIS_URI_CI
2019-01-16 19:22:44 +01:00
script:
2019-02-28 02:27:27 +01:00
- bundle exec rake db:create && bundle exec rake db:schema:load && bundle exec rake db:migrate
2019-02-28 21:17:59 +01:00
- bundle exec ruby tests/tests.rb || { echo "Tests failed.."; exit 1; }
2019-01-29 20:28:40 +01:00
- echo $DOCKERHUB_PW | docker login -u $DOCKERHUB_USER --password-stdin
- docker pull blockstream/satellite-api:latest
- docker pull blockstream/satellite-api-sse:latest
- docker build --cache-from blockstream/satellite-api:latest -f Dockerfile -t blockstream/satellite-api:latest -t blockstream/satellite-api:$CI_COMMIT_SHA .
- docker push blockstream/satellite-api:latest
- docker push blockstream/satellite-api:$CI_COMMIT_SHA
- echo "Building Satellite API SSE image"
- docker build --cache-from blockstream/satellite-api-sse:latest -f Dockerfile.sse -t blockstream/satellite-api-sse:latest -t blockstream/satellite-api-sse:$CI_COMMIT_SHA sse/
- docker push blockstream/satellite-api-sse:latest
- docker push blockstream/satellite-api-sse:$CI_COMMIT_SHA
2019-01-16 19:22:44 +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
only:
- branches@satellite/ionosphere
except:
- cleanup_staging@satellite/ionosphere
- /^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
&& terraform plan
-var "ionosphere_docker=blockstream/satellite-api:latest"
-var "ionosphere_sse_docker=blockstream/satellite-api-sse:latest"
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"
-var "private_bucket=$PRIVATE_BUCKET"
2019-06-13 18:01:23 +02:00
-var "letsencrypt_email=$LE_EMAIL"
2019-07-30 01:40:27 +02:00
-var "pguser=$PGUSER"
-var "pgpass=$PGPASS"
-var "charge_token=$CHARGE_TOKEN"
2019-09-05 04:18:20 +02:00
-var "rpcpass=$RPCPASS"
-var "k8s_autossh_lb=$GKE_LB"
2019-01-16 19:22:44 +01:00
-input=false)
2019-05-31 16:23:30 +02: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
only:
- /^misc_.*/
2019-01-19 00:15:42 +01:00
except:
- /^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
&& terraform plan
-var "region=$REGION"
-var "zone=$ZONE"
-var "instance_type=$INSTANCE_TYPE"
2019-01-18 23:57:15 +01:00
-var "onion_host=$ONION_HOST"
-var "prom_allowed_source_ip=$PROMETHEUS_ALLOWED_SOURCE_IP"
2019-02-26 23:03:37 +01:00
-var "prom_service_acct=$PROM_SA"
-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"
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
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
&& 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"
2019-06-13 18:01:23 +02:00
-input=false -auto-approve)
2019-03-07 21:29:43 +01:00
# Tag with staging_v.* to plan mainnet + LB to staging (e.g. staging_v0.1.1)
plan_staging:
stage: plan
only:
- /^staging_v.*/
script:
- (cd terraform
&& terraform init -input=false
&& terraform workspace select staging
&& terraform plan
-var "ionosphere_docker=blockstream/satellite-api:$CI_COMMIT_SHA"
-var "ionosphere_sse_docker=blockstream/satellite-api-sse:$CI_COMMIT_SHA"
-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"
-var "private_bucket=$PRIVATE_BUCKET"
-var "letsencrypt_email=$LE_EMAIL"
-var "pguser=$PGUSER"
-var "pgpass=$PGPASS"
-var "charge_token=$CHARGE_TOKEN"
-var "rpcpass=$RPCPASS"
-var "k8s_autossh_lb=$GKE_LB"
-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
when: manual
2019-01-16 19:22:44 +01:00
only:
- /^staging_v.*/
2019-01-16 19:22:44 +01:00
script:
- (cd terraform
&& terraform init -input=false
&& terraform workspace select staging
&& terraform apply
-var "ionosphere_docker=blockstream/satellite-api:$CI_COMMIT_SHA"
-var "ionosphere_sse_docker=blockstream/satellite-api-sse:$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"
-var "private_bucket=$PRIVATE_BUCKET"
2019-06-13 18:01:23 +02:00
-var "letsencrypt_email=$LE_EMAIL"
2019-07-30 01:40:27 +02:00
-var "pguser=$PGUSER"
-var "pgpass=$PGPASS"
-var "charge_token=$CHARGE_TOKEN"
-var "rpcpass=$RPCPASS"
-var "k8s_autossh_lb=$GKE_LB"
2019-01-16 19:22:44 +01:00
-input=false -auto-approve)
# Tag with prod_v.* to plan mainnet + LB to production (e.g. prod_v0.1.1)
plan_production:
stage: plan
only:
- /^prod_v.*/
script:
- (cd terraform
&& terraform init -input=false
&& terraform workspace select prod
&& terraform plan
-var "ionosphere_docker=blockstream/satellite-api:$CI_COMMIT_SHA"
-var "ionosphere_sse_docker=blockstream/satellite-api-sse:$CI_COMMIT_SHA"
-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"
-var "private_bucket=$PRIVATE_BUCKET"
-var "letsencrypt_email=$LE_EMAIL"
-var "pguser=$PGUSER"
-var "pgpass=$PGPASS"
-var "charge_token=$CHARGE_TOKEN"
-var "rpcpass=$RPCPASS"
-var "k8s_autossh_lb=$GKE_LB"
-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
when: manual
2019-01-16 19:22:44 +01:00
only:
- /^prod_v.*/
2019-01-16 19:22:44 +01:00
script:
- (cd terraform
&& terraform init -input=false
&& terraform workspace select prod
&& terraform apply
-var "ionosphere_docker=blockstream/satellite-api:$CI_COMMIT_SHA"
-var "ionosphere_sse_docker=blockstream/satellite-api-sse:$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"
-var "private_bucket=$PRIVATE_BUCKET"
2019-06-13 18:01:23 +02:00
-var "letsencrypt_email=$LE_EMAIL"
2019-07-30 01:40:27 +02:00
-var "pguser=$PGUSER"
-var "pgpass=$PGPASS"
-var "charge_token=$CHARGE_TOKEN"
-var "rpcpass=$RPCPASS"
-var "k8s_autossh_lb=$GKE_LB"
2019-01-16 19:22:44 +01:00
-input=false -auto-approve)
# Tag with testnet_staging_v.* to plan testnet staging (e.g. testnet_staging_v0.1.1)
plan_staging_testnet:
stage: plan
only:
- /^testnet_staging_v.*/
script:
- (cd terraform
&& terraform init -input=false
&& terraform workspace select testnet-staging
&& terraform plan
-var "ionosphere_docker=blockstream/satellite-api:$CI_COMMIT_SHA"
-var "ionosphere_sse_docker=blockstream/satellite-api-sse:$CI_COMMIT_SHA"
-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"
-var "private_bucket=$PRIVATE_BUCKET"
-var "letsencrypt_email=$LE_EMAIL"
-var "pguser=$PGUSER"
-var "pgpass=$PGPASS"
-var "charge_token=$CHARGE_TOKEN"
-var "rpcpass=$RPCPASS_TESTNET"
-var "k8s_autossh_lb=$GKE_LB"
-input=false)
# Tag with testnet_staging_v.* to deploy testnet staging (e.g. testnet_staging_v0.1.1)
2019-03-07 21:29:43 +01:00
deploy_staging_testnet:
2019-01-18 23:57:15 +01:00
stage: deploy
when: manual
2019-01-18 23:57:15 +01:00
only:
2019-03-07 21:29:43 +01:00
- /^testnet_staging_v.*/
2019-01-18 23:57:15 +01:00
script:
- (cd terraform
2019-03-07 21:29:43 +01:00
&& terraform init -input=false
&& terraform workspace select testnet-staging
&& terraform apply
-var "ionosphere_docker=blockstream/satellite-api:$CI_COMMIT_SHA"
-var "ionosphere_sse_docker=blockstream/satellite-api-sse:$CI_COMMIT_SHA"
-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"
-var "private_bucket=$PRIVATE_BUCKET"
2019-06-13 18:01:23 +02:00
-var "letsencrypt_email=$LE_EMAIL"
2019-07-30 01:40:27 +02:00
-var "pguser=$PGUSER"
-var "pgpass=$PGPASS"
-var "charge_token=$CHARGE_TOKEN"
-var "rpcpass=$RPCPASS_TESTNET"
-var "k8s_autossh_lb=$GKE_LB"
2019-03-07 21:29:43 +01:00
-input=false -auto-approve)
# Tag with testnet_prod_v.* to plan testnet to production (e.g. testnet_prod_v0.1.1)
plan_production_testnet:
stage: plan
only:
- /^testnet_prod_v.*/
script:
- (cd terraform
&& terraform init -input=false
&& terraform workspace select testnet-prod
&& terraform plan
-var "ionosphere_docker=blockstream/satellite-api:$CI_COMMIT_SHA"
-var "ionosphere_sse_docker=blockstream/satellite-api-sse:$CI_COMMIT_SHA"
-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"
-var "private_bucket=$PRIVATE_BUCKET"
-var "letsencrypt_email=$LE_EMAIL"
-var "pguser=$PGUSER"
-var "pgpass=$PGPASS"
-var "charge_token=$CHARGE_TOKEN"
2019-09-05 04:18:20 +02:00
-var "rpcpass=$RPCPASS_TESTNET"
-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
when: manual
2019-03-07 21:29:43 +01:00
only:
- /^testnet_prod_v.*/
script:
- (cd terraform
&& terraform init -input=false
&& terraform workspace select testnet-prod
&& terraform apply
-var "ionosphere_docker=blockstream/satellite-api:$CI_COMMIT_SHA"
-var "ionosphere_sse_docker=blockstream/satellite-api-sse:$CI_COMMIT_SHA"
-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"
-var "private_bucket=$PRIVATE_BUCKET"
2019-06-13 18:01:23 +02:00
-var "letsencrypt_email=$LE_EMAIL"
2019-07-30 01:40:27 +02:00
-var "pguser=$PGUSER"
-var "pgpass=$PGPASS"
-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)
# Pushing to this branch destroys the staging infrastructure
2019-01-16 19:22:44 +01:00
cleanup_staging:
stage: deploy
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)