From 421aa0d1d055d50bbd11c32ff8818c9f01a6b33c Mon Sep 17 00:00:00 2001 From: Alberto Rios Date: Wed, 15 May 2019 11:54:14 +0200 Subject: [PATCH] Removing ATs environment from CircleCI --- ci/Dockerfile | 24 - ci/README.md | 38 -- .../bosh-lite-disk.yml | 3 - .../bosh-lite-vm-type-small.yml | 5 - .../cloud-config/bosh-lite.yml | 72 --- .../create-director-override.sh | 61 -- .../create-jumpbox-override.sh | 38 -- .../delete-director-override.sh | 21 - .../delete-jumpbox-override.sh | 12 - .../disable-resurrector.yml | 4 - .../external-ip-gcp.yml | 17 - ci/appbroker-bbl-plan-patch/ip-forwarding.yml | 4 - .../jumpbox-vm-type-small.yml | 8 - .../terraform/bbl-template.tf.tmpl | 190 ------- .../terraform/bosh-lite_override.tf.tmpl | 57 -- ci/config.yml | 160 ++---- ci/scripts/manage-bosh-bbl-environment.sh | 521 ------------------ ci/scripts/run-local-ci-job.sh | 1 - ci/scripts/update-route53.sh | 48 -- .../wait-for-bosh-locks-to-be-released.sh | 33 -- ci/scripts/wait-for-other-builds-to-finish.sh | 40 -- 21 files changed, 32 insertions(+), 1325 deletions(-) delete mode 100644 ci/Dockerfile delete mode 100644 ci/appbroker-bbl-plan-patch/bosh-lite-disk.yml delete mode 100644 ci/appbroker-bbl-plan-patch/bosh-lite-vm-type-small.yml delete mode 100644 ci/appbroker-bbl-plan-patch/cloud-config/bosh-lite.yml delete mode 100755 ci/appbroker-bbl-plan-patch/create-director-override.sh delete mode 100755 ci/appbroker-bbl-plan-patch/create-jumpbox-override.sh delete mode 100755 ci/appbroker-bbl-plan-patch/delete-director-override.sh delete mode 100755 ci/appbroker-bbl-plan-patch/delete-jumpbox-override.sh delete mode 100644 ci/appbroker-bbl-plan-patch/disable-resurrector.yml delete mode 100644 ci/appbroker-bbl-plan-patch/external-ip-gcp.yml delete mode 100644 ci/appbroker-bbl-plan-patch/ip-forwarding.yml delete mode 100644 ci/appbroker-bbl-plan-patch/jumpbox-vm-type-small.yml delete mode 100755 ci/appbroker-bbl-plan-patch/terraform/bbl-template.tf.tmpl delete mode 100644 ci/appbroker-bbl-plan-patch/terraform/bosh-lite_override.tf.tmpl delete mode 100755 ci/scripts/manage-bosh-bbl-environment.sh delete mode 100755 ci/scripts/update-route53.sh delete mode 100755 ci/scripts/wait-for-bosh-locks-to-be-released.sh delete mode 100755 ci/scripts/wait-for-other-builds-to-finish.sh diff --git a/ci/Dockerfile b/ci/Dockerfile deleted file mode 100644 index 13aa777..0000000 --- a/ci/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -FROM circleci/openjdk:8-jdk - -RUN BOSH_URL="https://s3.amazonaws.com/bosh-cli-artifacts/bosh-cli-5.0.1-linux-amd64"&& \ - sudo curl --silent --show-error --location --fail --retry 3 --output /usr/bin/bosh $BOSH_URL && \ - sudo chmod +x /usr/bin/bosh && \ - bosh -v - -RUN BBL_URL="https://github.com/cloudfoundry/bosh-bootloader/releases/download/v6.8.4/bbl-v6.8.4_linux_x86-64" && \ - sudo curl --silent --show-error --location --fail --retry 3 --output /usr/bin/bbl $BBL_URL && \ - sudo chmod +x /usr/bin/bbl && \ - bbl -v - -RUN sudo apt-get -qqy install python3 \ - lsb-release \ - apt-transport-https - -RUN export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)" && \ - echo "deb https://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | sudo tee /etc/apt/sources.list.d/google-cloud-sdk.list && \ - sudo curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - && \ - sudo apt-get update && \ - sudo apt-get install -y google-cloud-sdk && \ - gcloud config set core/disable_usage_reporting true && \ - gcloud config set component_manager/disable_update_check true && \ - gcloud --version \ No newline at end of file diff --git a/ci/README.md b/ci/README.md index 4acc911..74d1a69 100644 --- a/ci/README.md +++ b/ci/README.md @@ -1,30 +1,5 @@ #App Broker CI Pipeline -### Managing BOSH Lite on GCP - -Currently CircleCI is used to run the acceptance tests. The system under test is a BOSH Lite, provisioned using [BOSH Bootloader](https://github.com/cloudfoundry/bosh-bootloader) - -The BOSH Lite director can be targeted using following steps; - -* Install bosh-cli and bbl - ``` - $ brew tap cloudfoundry/tap - $ brew install bosh-cli - $ brew install bbl - ``` -* Setup BBL environment variables - ``` - source ci/.envrc - "Check variables ACTIVE_BBL_ENV_LOCAL ACTIVE_BBL_ENV_CIRCLECI to see the current environment aliases" - ./scripts/manage-bosh-bbl-environment.sh generate-bbl-state-directory -b [Env alias eg. plymouth] - cd bosh-env-[env-alias]/bbl-state - bbl print-env > bbl-env.sh && source bbl-env.sh - bosh deployments - ``` - -### Set the active environment to be used by CI -./scripts/manage-bosh-bbl-environment.sh set-active-environment -b [bbl-env-alias] -t [local/circleci] - ### Running CI pipeline locally CircleCI allows pipelines to be run locally, this is very useful development purposes @@ -35,16 +10,3 @@ CircleCI allows pipelines to be run locally, this is very useful development pur ``` * Run script to execute pipeline `ci/scripts/run-local-ci-job.sh` - -### Credentials -CircleCI uses environment variables to store credentials (these are stored inside -a Vault instance within the CircleCI server). Environment variables need to -be uploaded to circle so they can be used by the build. - - -### Building / Repaving a BOSH Lite environment - -* Decide a new name for the environment. Currently the naming convention is towns and villages in Devon (see https://www.devonguide.com/gazetteer.htm) so for example `ENV_NAME=appbroker-exeter` -* Create a working directory *outside of version control* to create the environments -* ./ci/scripts/manage-bosh-bbl-environment.sh create-new-environment -b plymouth -i [internal IP cidr eg 10.0.3.0/24] -e -* Test the new CF install `cf api $ENV_NAME.cf-app.com --skip-ssl-validation` \ No newline at end of file diff --git a/ci/appbroker-bbl-plan-patch/bosh-lite-disk.yml b/ci/appbroker-bbl-plan-patch/bosh-lite-disk.yml deleted file mode 100644 index 34c04fd..0000000 --- a/ci/appbroker-bbl-plan-patch/bosh-lite-disk.yml +++ /dev/null @@ -1,3 +0,0 @@ -- type: replace - path: /disk_pools/name=disks/disk_size? - value: 131_072 diff --git a/ci/appbroker-bbl-plan-patch/bosh-lite-vm-type-small.yml b/ci/appbroker-bbl-plan-patch/bosh-lite-vm-type-small.yml deleted file mode 100644 index ed26ce1..0000000 --- a/ci/appbroker-bbl-plan-patch/bosh-lite-vm-type-small.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -# Configure sizes for bosh-lite on gcp -- type: replace - path: /resource_pools/name=vms/cloud_properties/machine_type - value: n1-standard-4 \ No newline at end of file diff --git a/ci/appbroker-bbl-plan-patch/cloud-config/bosh-lite.yml b/ci/appbroker-bbl-plan-patch/cloud-config/bosh-lite.yml deleted file mode 100644 index ec4dc83..0000000 --- a/ci/appbroker-bbl-plan-patch/cloud-config/bosh-lite.yml +++ /dev/null @@ -1,72 +0,0 @@ ---- -- type: replace - path: /azs - value: - - name: z1 - - name: z2 - - name: z3 -- type: replace - path: /compilation - value: - az: z1 - network: default - reuse_compilation_vms: true - vm_type: minimal - workers: 6 -- type: replace - path: /disk_types - value: - - disk_size: 1024 - name: 1GB - - disk_size: 5120 - name: 5GB - - disk_size: 10240 - name: 10GB - - disk_size: 100240 - name: 100GB -- type: replace - path: /networks - value: - - name: default - subnets: - - azs: [z1, z2, z3] - cloud_properties: - name: random - gateway: 10.244.0.1 - range: 10.244.0.0/20 - reserved: - - 10.244.0.1 - static: - - 10.244.0.2 - 10.244.0.127 - - 10.244.1.0 - 10.244.1.127 - - 10.244.2.0 - 10.244.2.127 - - 10.244.3.0 - 10.244.3.127 -- type: replace - path: /vm_extensions - value: - - name: 5GB_ephemeral_disk - - name: 10GB_ephemeral_disk - - name: 50GB_ephemeral_disk - - name: 100GB_ephemeral_disk - - name: 500GB_ephemeral_disk - - name: 1TB_ephemeral_disk - - name: ssh-proxy-and-router-lb - cloud_properties: - ports: - - host: 80 - - host: 443 - - host: 2222 - - name: cf-tcp-router-network-properties - cloud_properties: - ports: - - host: 1024-1123 - - name: credhub-lb - cloud_properties: - ports: - - host: 8845 -- type: replace - path: /vm_types - value: - - name: minimal - - name: small - - name: small-highmem diff --git a/ci/appbroker-bbl-plan-patch/create-director-override.sh b/ci/appbroker-bbl-plan-patch/create-director-override.sh deleted file mode 100755 index 38bd774..0000000 --- a/ci/appbroker-bbl-plan-patch/create-director-override.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash -declare -a bosh_create_env_command=() -bosh_create_env_command+=( - bosh - create-env - ${BBL_STATE_DIR}/bosh-deployment/bosh.yml - --state - ${BBL_STATE_DIR}/vars/bosh-state.json - --vars-store - ${BBL_STATE_DIR}/vars/director-vars-store.yml - --vars-file - ${BBL_STATE_DIR}/vars/director-vars-file.yml - --var-file - gcp_credentials_json="${BBL_GCP_SERVICE_ACCOUNT_KEY_PATH}" - -v - project_id="${BBL_GCP_PROJECT_ID}" - -v - zone="${BBL_GCP_ZONE}" - -o - ${BBL_STATE_DIR}/bosh-deployment/gcp/cpi.yml - -o - ${BBL_STATE_DIR}/bosh-deployment/jumpbox-user.yml - -o - ${BBL_STATE_DIR}/bosh-deployment/uaa.yml - -o - ${BBL_STATE_DIR}/bosh-deployment/credhub.yml - -o - ${BBL_STATE_DIR}/bosh-deployment/bosh-lite.yml - -o - ${BBL_STATE_DIR}/bosh-deployment/bosh-lite-runc.yml - -o - ${BBL_STATE_DIR}/bosh-deployment/gcp/bosh-lite-vm-type.yml - -o - ${BBL_STATE_DIR}/external-ip-gcp.yml - -o - ${BBL_STATE_DIR}/ip-forwarding.yml - -o - ${BBL_STATE_DIR}/bosh-lite-vm-type-small.yml - -o - ${BBL_STATE_DIR}/disable-resurrector.yml - -o - ${BBL_STATE_DIR}/bosh-lite-disk.yml -) - -if [[ ! -z "${INTERNAL_CIDR:-}" && ! -z "${DIRECTOR_INTERNAL_IP:-}" ]]; then -bosh_create_env_command+=( - -v - internal_cidr="${INTERNAL_CIDR}" - -v - internal_ip="${DIRECTOR_INTERNAL_IP}" - -v - internal_gateway="${INTERNAL_GATEWAY}" -) -fi -if [[ ! -z "${RECREATE_DIRECTOR:-}" ]]; then -bosh_create_env_command+=( - --recreate -) -fi -echo "Creating director with command: "${bosh_create_env_command[@]}"" -"${bosh_create_env_command[@]}" \ No newline at end of file diff --git a/ci/appbroker-bbl-plan-patch/create-jumpbox-override.sh b/ci/appbroker-bbl-plan-patch/create-jumpbox-override.sh deleted file mode 100755 index 8077ece..0000000 --- a/ci/appbroker-bbl-plan-patch/create-jumpbox-override.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash -declare -a bosh_create_env_command=() -bosh_create_env_command+=( - bosh - create-env - ${BBL_STATE_DIR}/jumpbox-deployment/jumpbox.yml - --state - ${BBL_STATE_DIR}/vars/jumpbox-state.json - --vars-store - ${BBL_STATE_DIR}/vars/jumpbox-vars-store.yml - --vars-file - ${BBL_STATE_DIR}/vars/jumpbox-vars-file.yml - --var-file - gcp_credentials_json="${BBL_GCP_SERVICE_ACCOUNT_KEY_PATH}" - -v - project_id="${BBL_GCP_PROJECT_ID}" - -v - zone="${BBL_GCP_ZONE}" - -o - ${BBL_STATE_DIR}/jumpbox-deployment/gcp/cpi.yml - -o - ${BBL_STATE_DIR}/jumpbox-vm-type-small.yml - -o - ${BBL_STATE_DIR}/ip-forwarding.yml -) - -if [[ ! -z "${INTERNAL_CIDR:-}" && ! -z "${JUMPBOX_INTERNAL_IP:-}" ]]; then -bosh_create_env_command+=( - -v - internal_cidr="${INTERNAL_CIDR}" - -v - internal_ip="${JUMPBOX_INTERNAL_IP}" - -v - internal_gateway="${INTERNAL_GATEWAY}" -) -fi -echo "Creating jumpbox with command: "${bosh_create_env_command[@]}"" -"${bosh_create_env_command[@]}" diff --git a/ci/appbroker-bbl-plan-patch/delete-director-override.sh b/ci/appbroker-bbl-plan-patch/delete-director-override.sh deleted file mode 100755 index 555e33d..0000000 --- a/ci/appbroker-bbl-plan-patch/delete-director-override.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -bosh delete-env \ - ${BBL_STATE_DIR}/bosh-deployment/bosh.yml \ - --state ${BBL_STATE_DIR}/vars/bosh-state.json \ - --vars-store ${BBL_STATE_DIR}/vars/director-vars-store.yml \ - --vars-file ${BBL_STATE_DIR}/vars/director-vars-file.yml \ - --var-file gcp_credentials_json="${BBL_GCP_SERVICE_ACCOUNT_KEY_PATH}" \ - -v project_id="${BBL_GCP_PROJECT_ID}" \ - -v zone="${BBL_GCP_ZONE}" \ - -o ${BBL_STATE_DIR}/bosh-deployment/gcp/cpi.yml \ - -o ${BBL_STATE_DIR}/bosh-deployment/jumpbox-user.yml \ - -o ${BBL_STATE_DIR}/bosh-deployment/uaa.yml \ - -o ${BBL_STATE_DIR}/bosh-deployment/credhub.yml \ - -o ${BBL_STATE_DIR}/bosh-deployment/bosh-lite.yml \ - -o ${BBL_STATE_DIR}/bosh-deployment/bosh-lite-runc.yml \ - -o ${BBL_STATE_DIR}/bosh-deployment/gcp/bosh-lite-vm-type.yml \ - -o ${BBL_STATE_DIR}/external-ip-gcp.yml \ - -o ${BBL_STATE_DIR}/ip-forwarding.yml \ - -o ${BBL_STATE_DIR}/bosh-lite-vm-type-small.yml \ - -o ${BBL_STATE_DIR}/disable-resurrector.yml \ - -o ${BBL_STATE_DIR}/bosh-lite-disk.yml \ No newline at end of file diff --git a/ci/appbroker-bbl-plan-patch/delete-jumpbox-override.sh b/ci/appbroker-bbl-plan-patch/delete-jumpbox-override.sh deleted file mode 100755 index 2090272..0000000 --- a/ci/appbroker-bbl-plan-patch/delete-jumpbox-override.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -bosh delete-env \ - ${BBL_STATE_DIR}/jumpbox-deployment/jumpbox.yml \ - --state ${BBL_STATE_DIR}/vars/jumpbox-state.json \ - --vars-store ${BBL_STATE_DIR}/vars/jumpbox-vars-store.yml \ - --vars-file ${BBL_STATE_DIR}/vars/jumpbox-vars-file.yml \ - --var-file gcp_credentials_json="${BBL_GCP_SERVICE_ACCOUNT_KEY_PATH}" \ - -v project_id="${BBL_GCP_PROJECT_ID}" \ - -v zone="${BBL_GCP_ZONE}" \ - -o ${BBL_STATE_DIR}/jumpbox-deployment/gcp/cpi.yml \ - -o ${BBL_STATE_DIR}/jumpbox-vm-type-small.yml \ - -o ${BBL_STATE_DIR}/ip-forwarding.yml diff --git a/ci/appbroker-bbl-plan-patch/disable-resurrector.yml b/ci/appbroker-bbl-plan-patch/disable-resurrector.yml deleted file mode 100644 index dcfd2a4..0000000 --- a/ci/appbroker-bbl-plan-patch/disable-resurrector.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -- type: replace - path: /resource_pools/name=vms/cloud_properties/ip_forwarding? - value: true diff --git a/ci/appbroker-bbl-plan-patch/external-ip-gcp.yml b/ci/appbroker-bbl-plan-patch/external-ip-gcp.yml deleted file mode 100644 index dd4b3fa..0000000 --- a/ci/appbroker-bbl-plan-patch/external-ip-gcp.yml +++ /dev/null @@ -1,17 +0,0 @@ -# Adapted from bosh-deployment/external-ip-not-recommended.yml - -- type: replace - path: /networks/- - value: - name: foo - type: vip - -- type: replace - path: /instance_groups/name=bosh/networks/0/default? - value: [dns, gateway] - -- type: replace - path: /instance_groups/name=bosh/networks/- - value: - name: foo - static_ips: [((external_ip))] diff --git a/ci/appbroker-bbl-plan-patch/ip-forwarding.yml b/ci/appbroker-bbl-plan-patch/ip-forwarding.yml deleted file mode 100644 index dcfd2a4..0000000 --- a/ci/appbroker-bbl-plan-patch/ip-forwarding.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -- type: replace - path: /resource_pools/name=vms/cloud_properties/ip_forwarding? - value: true diff --git a/ci/appbroker-bbl-plan-patch/jumpbox-vm-type-small.yml b/ci/appbroker-bbl-plan-patch/jumpbox-vm-type-small.yml deleted file mode 100644 index 82b56ed..0000000 --- a/ci/appbroker-bbl-plan-patch/jumpbox-vm-type-small.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- type: replace - path: /resource_pools/name=vms/cloud_properties? - value: - zone: ((zone)) - machine_type: g1-small - root_disk_size_gb: 20 - root_disk_type: pd-standard \ No newline at end of file diff --git a/ci/appbroker-bbl-plan-patch/terraform/bbl-template.tf.tmpl b/ci/appbroker-bbl-plan-patch/terraform/bbl-template.tf.tmpl deleted file mode 100755 index a2f30d6..0000000 --- a/ci/appbroker-bbl-plan-patch/terraform/bbl-template.tf.tmpl +++ /dev/null @@ -1,190 +0,0 @@ -variable "project_id" { - type = "string" -} - -variable "region" { - type = "string" -} - -variable "zone" { - type = "string" -} - -variable "env_id" { - type = "string" -} - -variable "credentials" { - type = "string" -} - -provider "google" { - credentials = "${file("${var.credentials}")}" - project = "${var.project_id}" - region = "${var.region}" -} - -variable "subnet_cidr" { - type = "string" - default = "<%= internalCidr %>" -} - -resource "google_compute_network" "bbl-network" { - name = "${var.env_id}-network" - auto_create_subnetworks = false -} - -resource "google_compute_subnetwork" "bbl-subnet" { - name = "${var.env_id}-subnet" - ip_cidr_range = "${var.subnet_cidr}" - network = "${google_compute_network.bbl-network.self_link}" -} - -resource "google_compute_firewall" "external" { - name = "${var.env_id}-external" - network = "${google_compute_network.bbl-network.name}" - - source_ranges = ["0.0.0.0/0"] - - allow { - ports = ["22", "6868", "25555"] - protocol = "tcp" - } - - target_tags = ["${var.env_id}-bosh-open"] -} - -resource "google_compute_firewall" "bosh-open" { - name = "${var.env_id}-bosh-open" - network = "${google_compute_network.bbl-network.name}" - - source_tags = ["${var.env_id}-bosh-open"] - - allow { - ports = ["22", "6868", "8443", "8844", "25555"] - protocol = "tcp" - } - - target_tags = ["${var.env_id}-bosh-director"] -} - -resource "google_compute_firewall" "bosh-director" { - name = "${var.env_id}-bosh-director" - network = "${google_compute_network.bbl-network.name}" - - source_tags = ["${var.env_id}-bosh-director"] - - allow { - protocol = "tcp" - } - - target_tags = ["${var.env_id}-internal"] -} - -resource "google_compute_firewall" "internal-to-director" { - name = "${var.env_id}-internal-to-director" - network = "${google_compute_network.bbl-network.name}" - - source_tags = ["${var.env_id}-internal"] - - allow { - ports = ["4222", "25250", "25777"] - protocol = "tcp" - } - - target_tags = ["${var.env_id}-bosh-director"] -} - -resource "google_compute_firewall" "jumpbox-to-all" { - name = "${var.env_id}-jumpbox-to-all" - network = "${google_compute_network.bbl-network.name}" - - source_tags = ["${var.env_id}-jumpbox"] - - allow { - ports = ["22", "3389"] - protocol = "tcp" - } - - target_tags = ["${var.env_id}-internal", "${var.env_id}-bosh-director"] -} - -resource "google_compute_firewall" "internal" { - name = "${var.env_id}-internal" - network = "${google_compute_network.bbl-network.name}" - - source_tags = ["${var.env_id}-internal"] - - allow { - protocol = "icmp" - } - - allow { - protocol = "tcp" - } - - allow { - protocol = "udp" - } - - target_tags = ["${var.env_id}-internal"] -} - -output "network" { - value = "${google_compute_network.bbl-network.name}" -} - -output "subnetwork" { - value = "${google_compute_subnetwork.bbl-subnet.name}" -} - -output "internal_cidr" { - value = "${var.subnet_cidr}" -} - -output "internal_gw" { - value = "${google_compute_subnetwork.bbl-subnet.gateway_address}" -} - -output "director_name" { - value = "bosh-${var.env_id}" -} - -output "jumpbox__internal_ip" { - value = "${cidrhost(var.subnet_cidr, 5)}" -} - -output "director__internal_ip" { - value = "${cidrhost(var.subnet_cidr, 6)}" -} - -output "jumpbox__tags" { - value = [ - "${google_compute_firewall.bosh-open.name}", - "${var.env_id}-jumpbox", - ] -} - -output "director__tags" { - value = ["${google_compute_firewall.bosh-director.name}"] -} - -output "internal_tag_name" { - value = "${google_compute_firewall.internal.name}" -} - -resource "google_compute_address" "jumpbox-ip" { - name = "${var.env_id}-jumpbox-ip" -} - -output "jumpbox_url" { - value = "${google_compute_address.jumpbox-ip.address}:22" -} - -output "external_ip" { - value = "${google_compute_address.jumpbox-ip.address}" -} - -output "director_address" { - value = "https://${google_compute_address.jumpbox-ip.address}:25555" -} diff --git a/ci/appbroker-bbl-plan-patch/terraform/bosh-lite_override.tf.tmpl b/ci/appbroker-bbl-plan-patch/terraform/bosh-lite_override.tf.tmpl deleted file mode 100644 index 3c1695d..0000000 --- a/ci/appbroker-bbl-plan-patch/terraform/bosh-lite_override.tf.tmpl +++ /dev/null @@ -1,57 +0,0 @@ -locals { - short_env_id = "${substr(var.env_id, 0, min(20, length(var.env_id)))}" -} - -resource "google_compute_firewall" "bosh-director-lite" { - name = "${local.short_env_id}-bosh-director-lite" - network = "${google_compute_network.bbl-network.name}" - - source_ranges = ["0.0.0.0/0"] - - allow { - ports = ["80", "443", "2222"] - protocol = "tcp" - } - - target_tags = ["${local.short_env_id}-bosh-director"] -} - -resource "google_compute_address" "bosh-director-ip" { - name = "${var.env_id}-bosh-director-ip" -} - -resource "google_compute_route" "bosh-lite-vms" { - name = "${var.env_id}-bosh-lite-vms" - dest_range = "10.244.0.0/16" - network = "${google_compute_network.bbl-network.name}" - next_hop_ip = "<%= directorIp %>" - priority = 1 - - depends_on = ["google_compute_subnetwork.bbl-subnet"] -} - -resource "google_compute_firewall" "bosh-director-lite-tcp-routing" { - name = "${local.short_env_id}-bosh-director-lite-tcp-routing" - network = "${google_compute_network.bbl-network.name}" - - source_ranges = ["0.0.0.0/0"] - - allow { - ports = ["1024-1123"] - protocol = "tcp" - } - - target_tags = ["${local.short_env_id}-bosh-director"] -} - -output "director__external_ip" { - value = "${google_compute_address.bosh-director-ip.address}" -} - -output "external_ip" { - value = "${google_compute_address.jumpbox-ip.address}" -} - -output "jumpbox__external_ip" { - value = "${google_compute_address.jumpbox-ip.address}" -} diff --git a/ci/config.yml b/ci/config.yml index 2a379b1..a466202 100644 --- a/ci/config.yml +++ b/ci/config.yml @@ -6,7 +6,7 @@ version: 2 jobs: build: docker: - - image: springcloudservices/spring-cloud-app-broker-ci:v1 + - image: circleci/openjdk:8-jdk working_directory: ~/repo @@ -16,145 +16,49 @@ jobs: TERM: dumb steps: - - checkout + - checkout - - restore_cache: - key: sc-app-broker-{{ .Branch }} + - restore_cache: + key: sc-app-broker-{{ .Branch }} - - run: - name: "Download dependencies" - command: ./gradlew assemble + - run: + name: "Download dependencies" + command: ./gradlew assemble - - save_cache: - paths: - - ~/.gradle - key: sc-app-broker-{{ .Branch }} + - save_cache: + paths: + - ~/.gradle + key: sc-app-broker-{{ .Branch }} - - run: - name: "Disable Gradle daemon" - command: touch ~/.gradle/gradle.properties && echo "org.gradle.daemon=false" >> ~/.gradle/gradle.properties + - run: + name: "Disable Gradle daemon" + command: touch ~/.gradle/gradle.properties && echo "org.gradle.daemon=false" >> ~/.gradle/gradle.properties - - run: - name: "Run unit tests" - command: ./gradlew clean check codeCoverageReport --stacktrace + - run: + name: "Run unit tests" + command: ./gradlew clean check codeCoverageReport --stacktrace - - run: - name: "Aggregate test results" - when: always - command: | - mkdir -p ~/junit/ - find . -type f -regex ".*/build/test-results/.*" -exec cp {} ~/junit/ \; + - run: + name: "Aggregate test results" + when: always + command: | + mkdir -p ~/junit/ + find . -type f -regex ".*/build/test-results/.*" -exec cp {} ~/junit/ \; - - run: - name: "Upload tests coverage" - command: bash <(curl -s https://codecov.io/bash) + - run: + name: "Upload tests coverage" + command: bash <(curl -s https://codecov.io/bash) - - store_artifacts: - path: ~/junit/ - destination: artifacts + - store_artifacts: + path: ~/junit/ + destination: artifacts - - store_test_results: - path: ~/junit/ - destination: testartifacts + - store_test_results: + path: ~/junit/ + destination: testartifacts - - run: - name: "Queue until all other builds finished" - command: | - cd ~/repo/ci/scripts - ./wait-for-other-builds-to-finish.sh 60 - - - run: - name: "Populate Secrets from Environment" - command: | - cd ~/repo/ci/ - if [[ ${CIRCLE_BUILD_NUM} = "" ]]; then - echo "populating from .envrc" - [[ -f ".envrc-localci" ]] || (printf "Ensure .envrc is present in ci directory before running script"; exit 1) - cat .envrc-localci >> $BASH_ENV - source .envrc-localci - ./scripts/manage-bosh-bbl-environment.sh generate-bbl-state-directory -b "${ACTIVE_BBL_ENV_LOCAL}" - bbl -s "bosh-env-${ACTIVE_BBL_ENV_LOCAL}/bbl-state" print-env >> $BASH_ENV - else - echo "populating from bbl env" - ./scripts/manage-bosh-bbl-environment.sh generate-bbl-state-directory -b "${ACTIVE_BBL_ENV_CIRCLE}" - bbl -s "bosh-env-${ACTIVE_BBL_ENV_CIRCLE}/bbl-state" print-env >> $BASH_ENV - fi - - - run: - name: "Start BOSH Lite" - command: | - cd ~/repo/ci - ./scripts/wait-for-bosh-locks-to-be-released.sh 30 - bosh -n -d cf start - - - run: - name: "Run acceptance tests" - command: | - ./gradlew -b spring-cloud-app-broker-integration-tests/build.gradle assemble - ./gradlew clean assemble check -PacceptanceTests --stacktrace --continue -b spring-cloud-app-broker-acceptance-tests/build.gradle - - - run: - name: "BOSH Cleanup" - command: bosh -n clean-up --all - - - store_test_results: - path: ~/repo/spring-cloud-app-broker-acceptance-tests/build/test-results - destination: acceptancetestartifacts - - bosh_redeploy: - docker: - - image: springcloudservices/spring-cloud-app-broker-ci:v1 - - working_directory: ~/repo - - environment: - JAVA_TOOL_OPTIONS: "-Xms512m -Xmx2048m" - GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx512m -Xmx2048m" -Dorg.gradle.daemon=false' - TERM: dumb - - steps: - - checkout - - - restore_cache: - key: sc-app-broker-{{ .Branch }} - - - run: - name: "Populate Secrets from Environment" - command: | - cd ~/repo/ci/ - if [[ ${CIRCLE_BUILD_NUM} = "" ]]; then - echo "populating from .envrc" - [[ -f ".envrc-localci" ]] || (printf "Ensure .envrc is present in ci directory before running script"; exit 1) - cat .envrc-localci >> $BASH_ENV - source .envrc-localci - ./scripts/manage-bosh-bbl-environment.sh generate-bbl-state-directory -b "${ACTIVE_BBL_ENV_LOCAL}" - bbl -s "bosh-env-${ACTIVE_BBL_ENV_LOCAL}/bbl-state" print-env >> $BASH_ENV - else - echo "populating from bbl env" - ./scripts/manage-bosh-bbl-environment.sh generate-bbl-state-directory -b "${ACTIVE_BBL_ENV_CIRCLE}" - bbl -s "bosh-env-${ACTIVE_BBL_ENV_CIRCLE}/bbl-state" print-env >> $BASH_ENV - fi - - - run: - name: "Redeploy and cleanup cf" - command: | - cd ~/repo/ci - scripts/manage-bosh-bbl-environment.sh recreate-environment -b plymouth - bosh disks --orphaned | grep disk- | awk '{print $1}' | xargs -L1 bosh delete-disk -n - workflows: version: 2 commit: jobs: - build - nightly: - triggers: - - schedule: - cron: "0 7 * * 0" - filters: - branches: - only: - - master - jobs: - - bosh_redeploy - diff --git a/ci/scripts/manage-bosh-bbl-environment.sh b/ci/scripts/manage-bosh-bbl-environment.sh deleted file mode 100755 index 5a97e9c..0000000 --- a/ci/scripts/manage-bosh-bbl-environment.sh +++ /dev/null @@ -1,521 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -readonly SCRIPT_DIR=$(readlink -m $(dirname $0)) -readonly CI_DIR=$(dirname "${SCRIPT_DIR}") -readonly BBL_VERSION=v6.9.16 -readonly BOSH_VERSION=5.2.2 -readonly CREDHUB_VERSION=2.0.0 -readonly BBL_GCP_SERVICE_ACCOUNT_KEY="${CI_DIR}/gcp-key.json" -readonly CIRCLE_API_BASE=https://circleci.com/api/v1.1/project/github/spring-cloud-incubator/spring-cloud-app-broker - -validate(){ - local -r internal_cidr="${1}" - source_environment_variables - [[ $(type bbl) ]] || (echo "bbl tool not installed" >&2 ; bbl_usage ; exit 2) - [[ $(type gcloud) ]] || (echo "gcloud tool not installed" >&2 ; gcloud_usage ; exit 2) - [[ $(type bosh) ]] || (echo "bosh cli not installed" >&2 ; bosh_usage ; exit 2) - [[ $(type credhub) ]] || (echo "credhub cli not installed" >&2 ; credhub_usage ; exit 2) - [[ $(type aws) ]] || (echo "aws-cli tool not installed, Install using \"brew install aws-cli\"" >&2 ; exit 2) - - has_ip_cidr_already_been_used "${internal_cidr}" - is_ip_cidr_valid "${internal_cidr}" -} - -bbl_usage() { - cat <<- EOF -Install bbl command line tool : - "curl -o /usr/local/bin/bbl https://github.com/cloudfoundry/bosh-bootloader/releases/download/${BBL_VERSION}/bbl-${BBL_VERSION}_osx && \ - chmod +x /usr/local/bin/bbl" -EOF -} - -bosh_usage() { - cat <<- EOF -Install bosh command line tool: - "curl -o /usr/local/bin/bosh https://github.com/cloudfoundry/bosh-cli/releases/download/${BOSH_VERSION}/bosh-cli-${BOSH_VERSION}-darwin-amd64 && \ - chmod +x /usr/local/bin/bosh" -EOF -} - -gcloud_usage() { - cat <<- EOF -Install Google Cloud SDK, see https://cloud.google.com/sdk/docs/quickstart-macos -EOF -} - -credhub_usage() { - cat <<-EOF -Install Credhub CLI: - "curl https://github.com/cloudfoundry-incubator/credhub-cli/releases/download/${CREDHUB_VERSION}/credhub-darwin-${CREDHUB_VERSION}.tgz - EOF -} - -usage() { - cat <<- EOF -Usage: ./manage-bosh-bbl-env.sh - - create-new-environment -e -l -b "env-suffix" -i "internal cidr" - "Creates a new bosh lite environment in GCP using BBL. Optionally upload state and variable data to Circleci and Lastpass" - -e Flag to upload environment variables to CircleCI - -i CIDR range for internal network of Jumpbox and BOSH director (must not have already been used in GCP project) eg 10.0.1.0/24 - -b Alias for new BBL environment that will be used for creating dns entry. Convention is an English town name, see https://en.wikipedia.org/wiki/List_of_towns_in_England - - generate-bbl-state-directory -b "env-suffix" - "Generates a new BBL state directory based on an existing environment, using state and vars files that are base64 encoded in environment variables" - -b Existing BBL environment that state directory will be generated for - - set-active-environment - "Select which bosh lite environment will be used for cirleci or local ci testing" - -t Target to set active, must equal "circleci" or "local" - -b BBL environment alias to set as target - - delete-environment - "Deletes a bosh lite environment and removes any variables" - -b BBL environment alias to remove -EOF -} - -has_ip_cidr_already_been_used(){ - local -r internal_cidr="${1}" - echo "${GCP_KEY_BASE64}" | base64 -d > "${CI_DIR}/gcp-key.json" - gcloud auth activate-service-account --key-file="${BBL_GCP_SERVICE_ACCOUNT_KEY}" - gcloud config set project "${BBL_GCP_PROJECT_ID}" - gcloud compute networks subnets list --filter="name :(appbroker*)" --format=json \ - | jq -e --arg IP_CIDR "${internal_cidr}" '. | map(.ipCidrRange) | index($IP_CIDR) | not' -} - -is_ip_cidr_valid(){ - local -r internal_cidr="${1}" - python3 -c "import ipaddress, sys; ipaddress.ip_network(sys.argv[1])" "${internal_cidr}" -} - -calculate_jumpbox_ip(){ - local -r internal_cidr="${1}" - python3 -c "import ipaddress, sys; n = ipaddress.ip_network(sys.argv[1]); print(n[5])" "${internal_cidr}" -} - -calculate_director_ip(){ - local -r internal_cidr="${1}" - python3 -c "import ipaddress, sys; n = ipaddress.ip_network(sys.argv[1]); print(n[6])" "${internal_cidr}" -} - -calculate_gateway_ip(){ - local -r internal_cidr="${1}" - python3 -c "import ipaddress, sys; n = ipaddress.ip_network(sys.argv[1]); print(n[1])" "${internal_cidr}" -} - -source_environment_variables(){ - [[ ! -f "${CI_DIR}/.envrc" ]] && printf "Ensure .envrc is present in directory ${CI_DIR} before running script" && exit 1 - source "${CI_DIR}/.envrc" -} - -create_bbl_state_dir() { - local -r bbl_env_suffix="${1}" - mkdir -p $(get_bbl_state_dir "${bbl_env_suffix}") -} - -create_new_bbl_plan() { - local -r bbl_env_suffix="${1}" - local -r bbl_state_dir=$(get_bbl_state_dir "${bbl_env_suffix}") - local -r bbl_env_name="${bbl_env_suffix}" - - bbl plan --name "${bbl_env_suffix}" -s "${bbl_state_dir}" --gcp-service-account-key="${CI_DIR}/gcp-key.json" -} - -copy_plan_patch_files() { - local -r bbl_env_suffix="${1}" - cp -r "${CI_DIR}/appbroker-bbl-plan-patch/." $(get_bbl_state_dir "${bbl_env_suffix}") -} - -interpolate_terraform_template_file() { - local -r internal_cidr="${1}" bbl_env_suffix="${2}" - sed -e "s|<%= directorIp %>|$(calculate_director_ip ${internal_cidr})|;" "$(get_bbl_state_dir "${bbl_env_suffix}")/terraform/bosh-lite_override.tf.tmpl" > "$(get_bbl_state_dir "${bbl_env_suffix}")/terraform/bosh-lite_override.tf" - sed -e "s|<%= internalCidr %>|${internal_cidr}|;" "$(get_bbl_state_dir "${bbl_env_suffix}")/terraform/bbl-template.tf.tmpl" > "$(get_bbl_state_dir "${bbl_env_suffix}")/terraform/bbl-template.tf" -} - -create_director_and_jumpbox(){ - local -r internal_cidr="${1}" bbl_env_suffix="${2}" - DIRECTOR_INTERNAL_IP=$(calculate_director_ip "${internal_cidr}") \ - JUMPBOX_INTERNAL_IP=$(calculate_jumpbox_ip "${internal_cidr}") \ - INTERNAL_GATEWAY=$(calculate_gateway_ip "${internal_cidr}") \ - INTERNAL_CIDR="${internal_cidr}" \ - bbl up -s $(get_bbl_state_dir "${bbl_env_suffix}") --gcp-service-account-key="${CI_DIR}/gcp-key.json" -} - -recreate_director_and_jumpbox(){ - local -r internal_cidr="${1}" bbl_env_suffix="${2}" - DIRECTOR_INTERNAL_IP=$(calculate_director_ip "${internal_cidr}") \ - JUMPBOX_INTERNAL_IP=$(calculate_jumpbox_ip "${internal_cidr}") \ - INTERNAL_GATEWAY=$(calculate_gateway_ip "${internal_cidr}") \ - INTERNAL_CIDR="${internal_cidr}" \ - RECREATE_DIRECTOR=true \ - bbl up -s $(get_bbl_state_dir "${bbl_env_suffix}") --gcp-service-account-key="${CI_DIR}/gcp-key.json" -} - -source_bbl_environment() { - local -r bbl_env_suffix="${1}" - bbl print-env -s $(get_bbl_state_dir "${bbl_env_suffix}") --gcp-service-account-key="${CI_DIR}/gcp-key.json"> bbl-env.sh && source bbl-env.sh && rm bbl-env.sh -} - -clone_cf_deployment(){ - local -r bbl_env_suffix="${1}" - git clone git@github.com:cloudfoundry/cf-deployment.git "$(get_bbl_state_dir "${bbl_env_suffix}")/cf-deployment" || true -} - -deploy_cf(){ - local -r bbl_env_suffix="${1}" - local -r bbl_state_dir=$(get_bbl_state_dir "${bbl_env_suffix}") - bosh -n update-runtime-config "${bbl_state_dir}/bosh-deployment/runtime-configs/dns.yml" --name dns - local -r stemcell_version=$(bosh interpolate "${bbl_state_dir}/cf-deployment/cf-deployment.yml" --path /stemcells/alias=default/version) - bosh -n upload-stemcell https://bosh.io/d/stemcells/bosh-warden-boshlite-ubuntu-xenial-go_agent?v=${stemcell_version} - bosh -n -d cf deploy "${bbl_state_dir}/cf-deployment/cf-deployment.yml" -o "${bbl_state_dir}/cf-deployment/operations/bosh-lite.yml" \ - -o "${bbl_state_dir}/cf-deployment/operations/use-compiled-releases.yml" -o "${bbl_state_dir}/cf-deployment/operations/experimental/add-deployment-updater.yml" \ - -v system_domain="$(get_bbl_env_name ${bbl_env_suffix}).cf-app.com" -} - -update_dns(){ - local -r bbl_env_suffix="${1}" - local -r director_external_ip=$(awk '/external_ip:/ {print $2}' < "$(get_bbl_state_dir "${bbl_env_suffix}")/vars/director-vars-file.yml") - "${SCRIPT_DIR}/update-route53.sh" $(get_bbl_env_name "${bbl_env_suffix}") "${director_external_ip}" -} - -base64_encode_bbl_state(){ - - local -r bbl_env_suffix="${1}" internal_cidr="${2}" upload_env_vars_to_circle="${3}" - local -r bbl_env_suffix_upper="${bbl_env_suffix^^}" - local -r bbl_state_dir=$(get_bbl_state_dir "${bbl_env_suffix}") - - declare -Ar bbl_state_file_paths=( - ["BBL_${bbl_env_suffix_upper}_BBL_STATE_JSON"]="${bbl_state_dir}/bbl-state.json" - ["BBL_${bbl_env_suffix_upper}_BBL_TFVARS"]="${bbl_state_dir}/vars/bbl.tfvars" - ["BBL_${bbl_env_suffix_upper}_BOSH_STATE_JSON"]="${bbl_state_dir}/vars/bosh-state.json" - ["BBL_${bbl_env_suffix_upper}_CLOUD_CONFIG_VARS_YML"]="${bbl_state_dir}/vars/cloud-config-vars.yml" - ["BBL_${bbl_env_suffix_upper}_DIRECTOR_VARS_FILE_YML"]="${bbl_state_dir}/vars/director-vars-file.yml" - ["BBL_${bbl_env_suffix_upper}_DIRECTOR_VARS_STORE_YML"]="${bbl_state_dir}/vars/director-vars-store.yml" - ["BBL_${bbl_env_suffix_upper}_JUMPBOX_STATE_JSON"]="${bbl_state_dir}/vars/jumpbox-state.json" - ["BBL_${bbl_env_suffix_upper}_JUMPBOX_VARS_FILE_YML"]="${bbl_state_dir}/vars/jumpbox-vars-file.yml" - ["BBL_${bbl_env_suffix_upper}_JUMPBOX_VARS_STORE_YML"]="${bbl_state_dir}/vars/jumpbox-vars-store.yml" - ["BBL_${bbl_env_suffix_upper}_TERRAFORM_TFSTATE"]="${bbl_state_dir}/vars/terraform.tfstate" - ) - [[ -f "${CI_DIR}/.envrc-localci" ]] || (printf "Ensure .envrc-localci is present in directory ${CI_DIR} before running script"; exit 1) - update_internal_network_environment_variable "${bbl_env_suffix}" "${upload_env_vars_to_circle}" "${internal_cidr}" - - for var_name in "${!bbl_state_file_paths[@]}"; do - local base64_file_contents=$(base64 -w0 "${bbl_state_file_paths[${var_name}]}") - if [[ ! -z "${base64_file_contents}" ]]; then - #Delete previous variable in .envrc file then replace with new value - sed -i -e "/${var_name}=/d" "${CI_DIR}/.envrc-localci" - - #Create a .envrc also in the bbl-state directory so the environment can be easily targeted manually - #.envrc-localci is used by the local circleci runner - printf "${var_name}=\"${base64_file_contents}\"\n" >> "${CI_DIR}/.envrc-localci" - if [ "${upload_env_vars_to_circle}" = true ]; then - upload_environment_variables_to_circleci "${var_name}" "${base64_file_contents}" - fi - else - echo "${var_name} was empty, unable to decode variables" - exit 1 - fi - done - lastpass_upload_instructions -} - -base64_decode_bbl_state(){ - local -r bbl_env_suffix="${1}" - local -r bbl_env_suffix_upper="${bbl_env_suffix^^}" - local -r bbl_state_dir=$(get_bbl_state_dir "${bbl_env_suffix}") - declare -Ar bbl_state_file_paths=( - ["BBL_${bbl_env_suffix_upper}_BBL_STATE_JSON"]="${bbl_state_dir}/bbl-state.json" - ["BBL_${bbl_env_suffix_upper}_BBL_TFVARS"]="${bbl_state_dir}/vars/bbl.tfvars" - ["BBL_${bbl_env_suffix_upper}_BOSH_STATE_JSON"]="${bbl_state_dir}/vars/bosh-state.json" - ["BBL_${bbl_env_suffix_upper}_CLOUD_CONFIG_VARS_YML"]="${bbl_state_dir}/vars/cloud-config-vars.yml" - ["BBL_${bbl_env_suffix_upper}_DIRECTOR_VARS_FILE_YML"]="${bbl_state_dir}/vars/director-vars-file.yml" - ["BBL_${bbl_env_suffix_upper}_DIRECTOR_VARS_STORE_YML"]="${bbl_state_dir}/vars/director-vars-store.yml" - ["BBL_${bbl_env_suffix_upper}_JUMPBOX_STATE_JSON"]="${bbl_state_dir}/vars/jumpbox-state.json" - ["BBL_${bbl_env_suffix_upper}_JUMPBOX_VARS_FILE_YML"]="${bbl_state_dir}/vars/jumpbox-vars-file.yml" - ["BBL_${bbl_env_suffix_upper}_JUMPBOX_VARS_STORE_YML"]="${bbl_state_dir}/vars/jumpbox-vars-store.yml" - ["BBL_${bbl_env_suffix_upper}_TERRAFORM_TFSTATE"]="${bbl_state_dir}/vars/terraform.tfstate" - ) - mkdir -p "${bbl_state_dir}/vars/" - for var_name in "${!bbl_state_file_paths[@]}"; do - local decoded_file_contents=$(eval echo "\$${var_name}" | base64 -d) - if [[ ! -z "${decoded_file_contents}" ]]; then - echo "${decoded_file_contents}" > "${bbl_state_file_paths[${var_name}]}" - else - echo "${var_name} was empty, unable to decode variables" - exit 1 - fi - done -} - -lastpass_upload_instructions(){ - cp "${CI_DIR}/.envrc-localci" "${CI_DIR}/envrc-local.txt" - echo "LastPass cli can only upload attachments via the GUI\n" - echo "Go to LastPass GUI and edit note: \"Shared-Spring Cloud Services /App Broker *LOCAL CI* .envrc-local file\"" - echo "Delete the previous attachment \"envrc-local.txt\"" - echo "then upload the modified env file ${CI_DIR}/envrc-local.txt as an attachment to the LastPass note" -} - -upload_environment_variables_to_circleci(){ - local envvar_name="${1}" - local envvar_value="${2}" - - curl -XPOST "${CIRCLE_API_BASE}/envvar?circle-token=${CIRCLECI_API_KEY}" \ - -H "Content-Type: application/json" -d '{"name": "'"${envvar_name}"'", "value": "'"${envvar_value}"'"}' -} - -update_internal_network_environment_variable(){ - local -r bbl_env_suffix="${1}" upload_env_vars_to_circle="${2}" internal_cidr="${3}" - local -r bbl_env_suffix_upper="${bbl_env_suffix^^}" - local -r bbl_state_dir=$(get_bbl_state_dir "${bbl_env_suffix}") - local -r internal_network_var_name="BBL_${bbl_env_suffix^^}_INTERNAL_NETWORK_CIDR" - - sed -i -e "/${internal_network_var_name}=/d" "${CI_DIR}/.envrc-localci" - printf "${internal_network_var_name}=${internal_cidr}\n" >> "${CI_DIR}/.envrc-localci" - if [ "${upload_env_vars_to_circle}" = true ]; then - upload_environment_variables_to_circleci "${internal_network_var_name}" "${internal_cidr}" - fi -} - -update_variables_to_target_active_environment(){ - local -r bbl_env_suffix="${1}" ci_target="${2}" - local -r bbl_state_dir=$(get_bbl_state_dir "${bbl_env_suffix}") - local -r api_host_var_name="SPRING_CLOUD_APPBROKER_ACCEPTANCETEST_CLOUDFOUNDRY_API_HOST" - local -r cf_password_var_name="SPRING_CLOUD_APPBROKER_ACCEPTANCETEST_CLOUDFOUNDRY_PASSWORD" - local -r envrc_file="${CI_DIR}/.envrc-localci" - - source_bbl_environment "${bbl_env_suffix}" - local -r bbl_env_id=$(bbl -s "${bbl_state_dir}" env-id) - local -r cf_password=$(credhub get -n "/bosh-${bbl_env_id}/cf/cf_admin_password" -j | jq -r '.value') - local -r api_host="api.appbroker-${bbl_env_suffix}.cf-app.com" - if [[ -z "${cf_password}" ]]; then - echo "Error: unable to find cf password" - exit 1 - fi - if [[ "$ci_target" != "local" && "$ci_target" != "circleci" ]]; then - printf "-t option must equal local or circleci" 1>&2 - exit 1 - fi - if [ "$ci_target" = "circleci" ]; then - upload_environment_variables_to_circleci "${cf_password_var_name}" "${cf_password}" - upload_environment_variables_to_circleci "${api_host_var_name}" "${api_host}" - upload_environment_variables_to_circleci "ACTIVE_BBL_ENV_CIRCLE" "${bbl_env_suffix}" - sed -i -e "/export ACTIVE_BBL_ENV_CIRCLE=/d" "${envrc_file}" - printf "export ACTIVE_BBL_ENV_CIRCLE=${bbl_env_suffix}\\n" >> "${envrc_file}" - - fi - if [ "$ci_target" = "local" ]; then - sed -i -e "/export ACTIVE_BBL_ENV_LOCAL=/d" "${envrc_file}" - printf "export ACTIVE_BBL_ENV_LOCAL=${bbl_env_suffix}\\n" >> "${envrc_file}" - fi - - #Remove existing values from .envrc - sed -i -e "/export ${api_host_var_name}=/d" "${envrc_file}" - sed -i -e "/export ${cf_password_var_name}=/d" "${envrc_file}" - - printf "export ${api_host_var_name}=${api_host}\\n" >> "${envrc_file}" - printf "export ${cf_password_var_name}=${cf_password}\\n" >> "${envrc_file}" - lastpass_upload_instructions -} - -recreate_environment(){ - local -r bbl_env_suffix="${1}" - local -r bbl_state_dir=$(get_bbl_state_dir "${bbl_env_suffix}") - local -r bbl_suffix_upper=${bbl_env_suffix^^} - local -r internal_network_var_name="BBL_${bbl_suffix_upper}_INTERNAL_NETWORK_CIDR" - local -r internal_cidr=$(eval echo "\$${internal_network_var_name}") - source_bbl_environment "${bbl_env_suffix}" - clone_cf_deployment "${bbl_env_suffix}" - - bosh -n update-runtime-config "${bbl_state_dir}/bosh-deployment/runtime-configs/dns.yml" --name dns - local -r stemcell_version=$(bosh interpolate "${bbl_state_dir}/cf-deployment/cf-deployment.yml" --path /stemcells/alias=default/version) - bosh -n upload-stemcell https://bosh.io/d/stemcells/bosh-warden-boshlite-ubuntu-xenial-go_agent?v=${stemcell_version} - local -r cf_password=$(credhub get -n "/bosh-${bbl_env_suffix}/cf/cf_admin_password" -j | jq -r '.value') - bosh -n -d cf delete-deployment - bosh -n -d cf deploy "${bbl_state_dir}/cf-deployment/cf-deployment.yml" -o "${bbl_state_dir}/cf-deployment/operations/bosh-lite.yml" \ - -o "${bbl_state_dir}/cf-deployment/operations/use-compiled-releases.yml" -v system_domain="$(get_bbl_env_name ${bbl_env_suffix}).cf-app.com" -v cf_admin_password="${cf_password}" -} - -get_bbl_state_dir(){ - local -r bbl_env_suffix="${1}" - echo "${CI_DIR}/bosh-env-${bbl_env_suffix}/bbl-state" -} - -get_bbl_env_name(){ - local -r bbl_env_suffix="${1}" - echo "appbroker-${bbl_env_suffix}" -} - -generate_bbl_state_dir_for_environment(){ - local -r bbl_env_suffix="${1}" - local -r bbl_suffix_upper=${bbl_env_suffix^^} - local -r bbl_state_dir=$(get_bbl_state_dir "${bbl_env_suffix}") - - if [[ -z "${CIRCLE_BUILD_NUM:-}" ]] ; then - source_environment_variables - [[ -f "${CI_DIR}/.envrc-localci" ]] || (printf "Ensure .envrc is present in directory ${CI_DIR} before running script"; exit 1) - source "${CI_DIR}/.envrc-localci" - fi - local -r internal_network_var_name="BBL_${bbl_suffix_upper}_INTERNAL_NETWORK_CIDR" - local -r internal_cidr=$(eval echo "\$${internal_network_var_name}") - create_bbl_state_dir "${bbl_env_suffix}" - #Just for creating files required by bbl, ignore any failures - bbl plan --name "${bbl_env_suffix}" -s "${bbl_state_dir}" --gcp-service-account-key="${CI_DIR}/gcp-key.json" || true - copy_plan_patch_files "${bbl_env_suffix}" - interpolate_terraform_template_file "${internal_cidr}" "${bbl_env_suffix}" - base64_decode_bbl_state "${bbl_env_suffix}" - echo "Finished creating generating BBL state directory for $(get_bbl_env_name ${bbl_env_suffix})" -} - -create_new_bbl_bosh_environment(){ - local -r bbl_env_suffix="${1}" internal_network_cidr="${2}" upload_env_vars_to_circleci="${3}" - validate "${internal_network_cidr}" - create_bbl_state_dir "${bbl_env_suffix}" - create_new_bbl_plan "${bbl_env_suffix}" - copy_plan_patch_files "${bbl_env_suffix}" - interpolate_terraform_template_file "${internal_network_cidr}" "${bbl_env_suffix}" - create_director_and_jumpbox "${internal_network_cidr}" "${bbl_env_suffix}" - source_bbl_environment "${bbl_env_suffix}" - clone_cf_deployment "${bbl_env_suffix}" - deploy_cf "${bbl_env_suffix}" - update_dns "${bbl_env_suffix}" - base64_encode_bbl_state "${bbl_env_suffix}" "${internal_network_cidr}" "${upload_env_vars_to_circleci}" - echo "Finished creating cloud foundry environment, you can now target CF using 'cf api api.$(get_bbl_env_name ${bbl_env_suffix}).cf-app.com --skip-ssl-validation'" -} - -process_command(){ - local -r arg="${1}" - local OPTIND - local upload_env_vars_to_circleci=false - local upload_env_vars_to_lastpass=false - local internal_network_cidr - local bbl_env_suffix - local ci_target - - case "${arg}" in - create-new-environment) - shift - while getopts ":ei:b:" FOUND "${@}"; - do - case ${FOUND} in - e) upload_env_vars_to_circleci=true - ;; - i) internal_network_cidr="${OPTARG}" - ;; - b) bbl_env_suffix="${OPTARG}" - ;; - \:) printf "argument missing from -%s option\n" $OPTARG - usage - exit 2 - ;; - \?) printf "unknown option: -%s\n" $OPTARG - usage - exit 2 - ;; - esac >&2 - done - shift $(($OPTIND - 1)) - : ${bbl_env_suffix:?"Required Env Variable not found!"} - : ${internal_network_cidr:?"Required Env Variable not found!"} - create_new_bbl_bosh_environment "${bbl_env_suffix}" "${internal_network_cidr}" "${upload_env_vars_to_circleci}" - ;; - - generate-bbl-state-directory) - shift - while getopts ":b:" FOUND "${@}"; - do - case ${FOUND} in - b) bbl_env_suffix="${OPTARG}" - ;; - \:) printf "argument missing from -%s option\n" $OPTARG - usage - exit 2 - ;; - \?) printf "unknown option: -%s\n" $OPTARG - usage - exit 2 - ;; - esac >&2 - done - shift $(($OPTIND - 1)) - : ${bbl_env_suffix:?"Required Env Variable not found!"} - generate_bbl_state_dir_for_environment "${bbl_env_suffix}" - ;; - - set-active-environment) - shift - while getopts ":b:t:" FOUND "${@}"; - do - case ${FOUND} in - b) bbl_env_suffix="${OPTARG}" - ;; - t) ci_target="${OPTARG}" - ;; - \:) printf "argument missing from -%s option\n" $OPTARG - usage - exit 2 - ;; - \?) printf "unknown option: -%s\n" $OPTARG - usage - exit 2 - ;; - esac >&2 - done - generate_bbl_state_dir_for_environment "${bbl_env_suffix}" - update_variables_to_target_active_environment "${bbl_env_suffix}" "${ci_target}" - ;; - - recreate-environment) - shift - while getopts ":b:" FOUND "${@}"; - do - case ${FOUND} in - b) bbl_env_suffix="${OPTARG}" - ;; - \:) printf "argument missing from -%s option\n" $OPTARG - usage - exit 2 - ;; - \?) printf "unknown option: -%s\n" $OPTARG - usage - exit 2 - ;; - esac >&2 - done - generate_bbl_state_dir_for_environment "${bbl_env_suffix}" - recreate_environment "${bbl_env_suffix}" - ;; - - redeploy-cf) - shift - while getopts ":b:" FOUND "${@}"; - do - case ${FOUND} in - b) bbl_env_suffix="${OPTARG}" - ;; - \:) printf "argument missing from -%s option\n" $OPTARG - usage - exit 2 - ;; - \?) printf "unknown option: -%s\n" $OPTARG - usage - exit 2 - ;; - esac >&2 - done - generate_bbl_state_dir_for_environment "${bbl_env_suffix}" - source_bbl_environment "${bbl_env_suffix}" - deploy_cf "${bbl_env_suffix}" - ;; - - delete-environment) - printf "Command not yet implemented" - ;; - *) - printf "${arg}: Unknown command" - ;; - esac -} - -[[ $# -lt 1 ]] && printf "Not enough arguments\n\n" && usage && exit 1 -process_command "${@}" diff --git a/ci/scripts/run-local-ci-job.sh b/ci/scripts/run-local-ci-job.sh index c906e5b..59c81c4 100755 --- a/ci/scripts/run-local-ci-job.sh +++ b/ci/scripts/run-local-ci-job.sh @@ -7,7 +7,6 @@ readonly PROJECT_ROOT=$(dirname "${CI_DIR}") validate(){ [[ $(type circleci) ]] || (echo "circleci tool not installed" >&2 ; circle_usage ; exit 2) - [[ -f "${CI_DIR}/.envrc" ]] || (printf "Download .envrc from LastPass using \"lpass show --notes 7083089362665788436\" in directory ${CI_DIR} before running script"; exit 1) } circle_usage() { diff --git a/ci/scripts/update-route53.sh b/ci/scripts/update-route53.sh deleted file mode 100755 index 147a8dd..0000000 --- a/ci/scripts/update-route53.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bash -# After creating a new environment with BBL you need to create / update the DNS zone in route53 -set -euo pipefail - -readonly PROG_DIR=$(readlink -m $(dirname $0)) -readonly CI_DIR=$(dirname "${PROG_DIR}") -[[ -z "${1:-}" ]] && printf "Must provide BBL environment id (use bbl env-id to retrieve)\n" && exit 1 -[[ -z "${2:-}" ]] && printf "Must provide external IP of Director VM (found in file bbl-state/vars/director-vars-file.yml)\n" && exit 1 - -validate(){ - [[ $(type aws) ]] || (echo "aws-cli tool not installed" >&2 ; aws_usage ; exit 2) - [[ -f "${CI_DIR}/.envrc" ]] || (printf "Download .envrc in directory ${CI_DIR} before running script"; exit 1) - -} - -aws_usage() { - cat <<- EOF -Install aws-cli tool using "brew install aws-cli" -EOF -} - -update_dns() { - local bbl_env_id="${1}" director_external_ip="${2}" - source "${CI_DIR}/.envrc" - [[ -z "${DNS_ZONE_ID:-}" ]] && printf "DNS_ZONE_ID must be set" && exit 1 - - aws route53 change-resource-record-sets --hosted-zone-id /hostedzone/"${DNS_ZONE_ID}" --change-batch='{ - "Comment": "", - "Changes": [ - { - "Action": "UPSERT", - "ResourceRecordSet": { - "Name": "*.'"${bbl_env_id}"'.cf-app.com", - "Type": "A", - "TTL": 0, - "ResourceRecords": [ - { - "Value": "'"${director_external_ip}"'" - } - ] - } - } - ] - }' - -} -validate -update_dns "${1}" "${2}" diff --git a/ci/scripts/wait-for-bosh-locks-to-be-released.sh b/ci/scripts/wait-for-bosh-locks-to-be-released.sh deleted file mode 100755 index 5ac8f4d..0000000 --- a/ci/scripts/wait-for-bosh-locks-to-be-released.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash -# The BOSH director might be in use by someone else. Check `bosh locks` command before running ATs -set -euo pipefail - -[[ -z "${1:-}" ]] && printf "Must provide Max Queue Time in *minutes* as script argument\n" && exit 1 - -readonly MAX_TIME=${1} - -wait_for_bosh_locks_to_be_released(){ - local max_time_seconds=$((MAX_TIME * 60)) - - until [[ $(bosh locks --json | jq '.Tables[].Rows | length') -eq 0 ]]; do - - sleep 10 - printf "." - if [[ "${SECONDS}" -gt "${max_time_seconds}" ]]; then - # After cancelling the build, wait some time to ensure the job has been cancelled otherwise - # the script will exit and the job will be incorrectly marked success or failed - printf "Max time exceeded waiting for bosh locks to be released, cancelling build\n" - cancel_current_build - sleep 20 - exit 1 - fi - done - printf "No BOSH locks found, continuing build\n" -} - -cancel_current_build() { - curl -s -X POST \ - "https://circleci.com/api/v1.1/project/github/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/${CIRCLE_BUILD_NUM}/cancel?circle-token=${CIRCLECI_API_KEY}" > /dev/null -} - -wait_for_bosh_locks_to_be_released \ No newline at end of file diff --git a/ci/scripts/wait-for-other-builds-to-finish.sh b/ci/scripts/wait-for-other-builds-to-finish.sh deleted file mode 100755 index 7dbe890..0000000 --- a/ci/scripts/wait-for-other-builds-to-finish.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -[[ -z "${1:-}" ]] && printf "Must provide Max Queue Time in *minutes* as script argument\n" && exit 1 -[[ -z "${CIRCLE_BUILD_NUM:-}" ]] && printf "skipping, not running on remote circleci environment\n" && exit 0 -: ${CIRCLECI_API_KEY:?"Required Env Variable not found!"} -: ${CIRCLE_PROJECT_USERNAME:?"Required Env Variable not found!"} -: ${CIRCLE_PROJECT_REPONAME:?"Required Env Variable not found!"} -: ${CIRCLE_REPOSITORY_URL:?"Required Env Variable not found!"} - -readonly MAX_TIME=${1} - -wait_for_previous_builds_to_complete(){ - local max_time_seconds=$((MAX_TIME * 60)) - - until [[ $(curl -s "https://circleci.com/api/v1.1/project/github/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}?circle-token=${CIRCLECI_API_KEY}&filter=running" \ - | jq 'min_by(.build_num) | .build_num') \ - -eq ${CIRCLE_BUILD_NUM} ]]; do - - sleep 10 - printf "." - if [[ "${SECONDS}" -gt "${max_time_seconds}" ]]; then - # After cancelling the build, wait some time to ensure the job has been cancelled otherwise - # the script will exit and the job will be incorrectly marked success or failed - printf "Max time exceeded waiting to reach front of queue, cancelling build\n" - cancel_current_build - sleep 20 - exit 1 - fi - done - printf "Build is front of queue\n" - -} - -cancel_current_build() { - curl -s -X POST \ - "https://circleci.com/api/v1.1/project/github/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/${CIRCLE_BUILD_NUM}/cancel?circle-token=${CIRCLECI_API_KEY}" > /dev/null -} - -wait_for_previous_builds_to_complete \ No newline at end of file