From 17c7b2bd6d7940460fc77f20dd7c59baff4ad75b Mon Sep 17 00:00:00 2001 From: Suzuki Takeo Date: Sun, 1 Sep 2019 06:31:32 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E3=83=AA=E3=82=BD=E3=83=BC=E3=82=B9?= =?UTF-8?q?=E3=82=92destroy=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .circleci/config.yml | 87 +------------------- infrastructure/staging/gcp/terraform/main.tf | 55 +------------ 2 files changed, 4 insertions(+), 138 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5d16f4c..16e1d40 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -53,98 +53,17 @@ jobs: command: terraform apply -auto-approve -var-file=../gcloud-env working_directory: ~/project/infrastructure/staging/gcp/terraform - push: - docker: - - image: circleci/openjdk:8-jdk - environment: - SBT_VERSION: 1.2.8 - JVM_OPTS: -Xmx3200m - TERM: dumb - steps: - - checkout - - setup_remote_docker - - run: - name: Create gcp credential - command: | - echo $GCLOUD_SERVICE_KEY | base64 -d > ${HOME}/account.json - - run: - name: Login docker - command: | - cat ${HOME}/account.json | docker login -u _json_key --password-stdin https://gcr.io - - run: - name: Docker build and push - command: | - . ~/project/infrastructure/staging/gcp/gcloud-env - export DOCKER_TAG=`echo "${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}:latest" | tr '[:upper:]' '[:lower:]'` - export IMAGE_NAME=gcr.io/${GOOGLE_PROJECT_ID}/${DOCKER_TAG} - sbt docker:publishLocal - docker tag ${DOCKER_TAG} ${IMAGE_NAME} - docker push ${IMAGE_NAME} - cd tools/mysql - docker build . -t gcr.io/${GOOGLE_PROJECT_ID}/mysql:latest - docker push gcr.io/${GOOGLE_PROJECT_ID}/mysql:latest - - deploy: - docker: - - image: google/cloud-sdk - steps: - - checkout - - setup_remote_docker - - run: - name: Install helm - command: | - curl https://storage.googleapis.com/kubernetes-helm/helm-v2.12.3-linux-amd64.tar.gz | tar zx linux-amd64/helm - mv linux-amd64/helm /usr/local/bin/helm; rm -rf linux-amd64 - - run: - name: Deploy to GKE - command: | - . ~/project/infrastructure/staging/gcp/gcloud-env - - export DOCKER_TAG=`echo "${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}:latest" | tr '[:upper:]' '[:lower:]'` - export IMAGE_NAME=gcr.io/${GOOGLE_PROJECT_ID}/${DOCKER_TAG} - - export DB_IMAGE=gcr.io/${GOOGLE_PROJECT_ID}/mysql - export DB_TAG=latest - - echo $GCLOUD_SERVICE_KEY | base64 -d > ${HOME}/account.json - gcloud auth activate-service-account --key-file ${HOME}/account.json - gcloud --quiet config set project $GOOGLE_PROJECT_ID - gcloud --quiet config set compute/region $GOOGLE_COMPUTE_REGION - gcloud --quiet config set compute/zone $GOOGLE_COMPUTE_ZONE - gcloud --quiet container clusters get-credentials $GOOGLE_CLUSTER_NAME - - cd ~/project/infrastructure/staging/gcp/k8s - sh ./setup-k8s.sh - workflows: version: 2 build-n-deploy: jobs: - build: filters: - tags: - only: /.*/ + branches: + only: feature/destroy-gcp-source - staging: requires: - build filters: branches: - ignore: /.*/ - tags: - only: /^v.*/ - - push: - requires: - - staging - filters: - branches: - ignore: /.*/ - tags: - only: /^v.*/ - - deploy: - requires: - - push - filters: - branches: - ignore: /.*/ - tags: - only: /^v.*/ + only: feature/destroy-gcp-source diff --git a/infrastructure/staging/gcp/terraform/main.tf b/infrastructure/staging/gcp/terraform/main.tf index b61143c..130e706 100644 --- a/infrastructure/staging/gcp/terraform/main.tf +++ b/infrastructure/staging/gcp/terraform/main.tf @@ -7,57 +7,4 @@ provider "google" { credentials = "${file("./account.json")}" region = "${var.GOOGLE_COMPUTE_REGION}" project = "${var.GOOGLE_PROJECT_ID}" -} - -// Network -resource "google_compute_network" "default" { - name = "${var.GOOGLE_PROJECT_ID}" - auto_create_subnetworks = false -} - -// Subnetwork -resource "google_compute_subnetwork" "default" { - name = "${var.GOOGLE_PROJECT_ID}" - ip_cidr_range = "192.168.10.0/24" - network = "${google_compute_network.default.self_link}" - region = "${var.GOOGLE_COMPUTE_REGION}" - private_ip_google_access = true -} - -// Cluster -resource "google_container_cluster" "default" { - name = "${var.GOOGLE_CLUSTER_NAME}" - zone = "${var.GOOGLE_COMPUTE_ZONE}" - initial_node_count = 20 - network = "${google_compute_subnetwork.default.name}" - subnetwork = "${google_compute_subnetwork.default.name}" - - enable_legacy_abac = true - - master_auth { - username = "" - password = "" - } - - provisioner "local-exec" { - when = "destroy" - command = "sleep 90" - } - - node_config { - oauth_scopes = [ - "https://www.googleapis.com/auth/compute", - "https://www.googleapis.com/auth/devstorage.read_only", - "https://www.googleapis.com/auth/logging.write", - "https://www.googleapis.com/auth/monitoring", - ] - preemptible = true - machine_type = "n1-standard-2" - } -} - -// Static IP -//terraform import -var-file=../gcloud-env google_compute_global_address.ip_address ${GOOGLE_PROJECT_ID}/${GOOGLE_PROJECT_ID}-static-ip -//resource "google_compute_global_address" "ip_address" { -// name = "${var.GOOGLE_PROJECT_ID}-static-ip" -//} \ No newline at end of file +} \ No newline at end of file From 0ef089935a55525648e1e5db0329ffa7b4200f33 Mon Sep 17 00:00:00 2001 From: Suzuki Takeo Date: Sun, 1 Sep 2019 07:22:06 +0900 Subject: [PATCH 2/3] =?UTF-8?q?destroy=E5=87=A6=E7=90=86=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .circleci/config.yml | 4 +- infrastructure/staging/gcp/terraform/main.tf | 55 +++++++++++++++++++- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 16e1d40..871637e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -46,11 +46,11 @@ jobs: working_directory: ~/project/infrastructure/staging/gcp/terraform - run: name: plan terraform - command: terraform plan -var-file=../gcloud-env + command: terraform plan -destroy -var-file=../gcloud-env working_directory: ~/project/infrastructure/staging/gcp/terraform - run: name: apply terraform - command: terraform apply -auto-approve -var-file=../gcloud-env + command: terraform destroy -auto-approve -var-file=../gcloud-env working_directory: ~/project/infrastructure/staging/gcp/terraform workflows: diff --git a/infrastructure/staging/gcp/terraform/main.tf b/infrastructure/staging/gcp/terraform/main.tf index 130e706..b61143c 100644 --- a/infrastructure/staging/gcp/terraform/main.tf +++ b/infrastructure/staging/gcp/terraform/main.tf @@ -7,4 +7,57 @@ provider "google" { credentials = "${file("./account.json")}" region = "${var.GOOGLE_COMPUTE_REGION}" project = "${var.GOOGLE_PROJECT_ID}" -} \ No newline at end of file +} + +// Network +resource "google_compute_network" "default" { + name = "${var.GOOGLE_PROJECT_ID}" + auto_create_subnetworks = false +} + +// Subnetwork +resource "google_compute_subnetwork" "default" { + name = "${var.GOOGLE_PROJECT_ID}" + ip_cidr_range = "192.168.10.0/24" + network = "${google_compute_network.default.self_link}" + region = "${var.GOOGLE_COMPUTE_REGION}" + private_ip_google_access = true +} + +// Cluster +resource "google_container_cluster" "default" { + name = "${var.GOOGLE_CLUSTER_NAME}" + zone = "${var.GOOGLE_COMPUTE_ZONE}" + initial_node_count = 20 + network = "${google_compute_subnetwork.default.name}" + subnetwork = "${google_compute_subnetwork.default.name}" + + enable_legacy_abac = true + + master_auth { + username = "" + password = "" + } + + provisioner "local-exec" { + when = "destroy" + command = "sleep 90" + } + + node_config { + oauth_scopes = [ + "https://www.googleapis.com/auth/compute", + "https://www.googleapis.com/auth/devstorage.read_only", + "https://www.googleapis.com/auth/logging.write", + "https://www.googleapis.com/auth/monitoring", + ] + preemptible = true + machine_type = "n1-standard-2" + } +} + +// Static IP +//terraform import -var-file=../gcloud-env google_compute_global_address.ip_address ${GOOGLE_PROJECT_ID}/${GOOGLE_PROJECT_ID}-static-ip +//resource "google_compute_global_address" "ip_address" { +// name = "${var.GOOGLE_PROJECT_ID}-static-ip" +//} \ No newline at end of file From deb0f79c36634a4068ae1b436a01f985d72be021 Mon Sep 17 00:00:00 2001 From: Suzuki Takeo Date: Thu, 5 Sep 2019 07:56:07 +0900 Subject: [PATCH 3/3] destroy gatling-runner-cluster --- .../staging/gcp/terraform/import.sh | 1 + infrastructure/staging/gcp/terraform/main.tf | 42 ++++++++++++++++--- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/infrastructure/staging/gcp/terraform/import.sh b/infrastructure/staging/gcp/terraform/import.sh index 7824a49..f11e399 100644 --- a/infrastructure/staging/gcp/terraform/import.sh +++ b/infrastructure/staging/gcp/terraform/import.sh @@ -4,4 +4,5 @@ terraform init terraform import -var-file=../gcloud-env google_compute_network.default ${GOOGLE_PROJECT_ID} terraform import -var-file=../gcloud-env google_compute_subnetwork.default ${GOOGLE_PROJECT_ID} terraform import -var-file=../gcloud-env google_container_cluster.default ${GOOGLE_PROJECT_ID}/${GOOGLE_COMPUTE_ZONE}/${GOOGLE_CLUSTER_NAME} +terraform import -var-file=../gcloud-env google_container_cluster.loadtest-server ${GOOGLE_PROJECT_ID}/${GOOGLE_COMPUTE_ZONE}/gatling-runner-cluster true \ No newline at end of file diff --git a/infrastructure/staging/gcp/terraform/main.tf b/infrastructure/staging/gcp/terraform/main.tf index b61143c..919e73c 100644 --- a/infrastructure/staging/gcp/terraform/main.tf +++ b/infrastructure/staging/gcp/terraform/main.tf @@ -28,7 +28,7 @@ resource "google_compute_subnetwork" "default" { resource "google_container_cluster" "default" { name = "${var.GOOGLE_CLUSTER_NAME}" zone = "${var.GOOGLE_COMPUTE_ZONE}" - initial_node_count = 20 + initial_node_count = 21 network = "${google_compute_subnetwork.default.name}" subnetwork = "${google_compute_subnetwork.default.name}" @@ -53,11 +53,41 @@ resource "google_container_cluster" "default" { ] preemptible = true machine_type = "n1-standard-2" + disk_size_gb = 10 + disk_type = "pd-ssd" } } -// Static IP -//terraform import -var-file=../gcloud-env google_compute_global_address.ip_address ${GOOGLE_PROJECT_ID}/${GOOGLE_PROJECT_ID}-static-ip -//resource "google_compute_global_address" "ip_address" { -// name = "${var.GOOGLE_PROJECT_ID}-static-ip" -//} \ No newline at end of file +// Gatling Cluster +resource "google_container_cluster" "loadtest-server" { + name = "gatling-runner-cluster" + zone = "${var.GOOGLE_COMPUTE_ZONE}" + initial_node_count = 1 + network = "${google_compute_subnetwork.default.name}" + subnetwork = "${google_compute_subnetwork.default.name}" + + enable_legacy_abac = true + + master_auth { + username = "" + password = "" + } + + provisioner "local-exec" { + when = "destroy" + command = "sleep 90" + } + + node_config { + oauth_scopes = [ + "https://www.googleapis.com/auth/compute", + "https://www.googleapis.com/auth/devstorage.read_only", + "https://www.googleapis.com/auth/logging.write", + "https://www.googleapis.com/auth/monitoring", + ] + preemptible = true + machine_type = "n1-standard-2" + disk_size_gb = 10 + disk_type = "pd-ssd" + } +}