diff --git a/.circleci/config.yml b/.circleci/config.yml index 5d16f4c..871637e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -46,105 +46,24 @@ 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 - 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/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" + } +}