Last active
May 5, 2022 16:03
-
-
Save r4rohan/1d0f62610fd9b2ce5281dc302d4a1590 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
- docker:18.09.9-dind | |
cache: | |
paths: | |
- .m2/repository | |
before_script: | |
- source ci/script.sh | |
variables: | |
VARIABLES_FILE: ./variables.txt | |
DOCKER_API_VERSION: "1.39" | |
DOCKER_HOST: tcp://localhost:2375 | |
stages: | |
- build | |
- deploy_dev | |
- deploy_stg | |
- deploy_prod | |
maven-build: | |
image: maven:3.6-jdk-8 | |
stage: build | |
script: | |
- mvn verify -DskipTests | |
variables: | |
MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository" | |
artifacts: | |
paths: | |
- target/hello-world.jar | |
expire_in: 1 week | |
dev-deployment: | |
stage: deploy_dev | |
image: google/cloud-sdk | |
only: | |
refs: | |
- branches | |
except: | |
refs: | |
- master | |
- stg | |
script: | |
- deploy_vm dev | |
staging-deployment: | |
stage: deploy_stg | |
image: google/cloud-sdk | |
only: | |
refs: | |
- master | |
- stg | |
script: | |
- deploy_vm stg | |
when: manual | |
production-deployment: | |
stage: deploy_prod | |
image: google/cloud-sdk | |
only: | |
refs: | |
- master | |
- stg | |
script: | |
- deploy_vm prod | |
when: manual |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
export CI_BUILD_SHA="x${CI_BUILD_REF:0:8}" | |
deploy_vm() { | |
if [ $1 == 'dev' ] | |
then | |
echo 'DEV DEPLOYMENT' | |
echo $DEV_GCP_TOKEN > /tmp/key.json | |
gcloud auth activate-service-account --key-file /tmp/key.json | |
gcloud beta compute ssh --tunnel-through-iap --zone "us-central1-a" "spring-boot-vm" --project "cloudorbit-dev" --command="sudo systemctl stop hello-world" | |
sleep 5 | |
gcloud compute scp target/hello-world.jar spring-boot-vm:/hello-world --zone=us-central1-a --project "cloudorbit-dev" --tunnel-through-iap | |
gcloud beta compute ssh --tunnel-through-iap --zone "us-central1-a" "spring-boot-vm" --project "cloudorbit-dev" --command="sudo systemctl start hello-world" | |
elif [ $1 == 'stg' ] | |
then | |
echo 'STAGE DEPLOYMENT' | |
echo $STG_GCP_TOKEN > /tmp/key.json | |
gcloud auth activate-service-account --key-file /tmp/key.json | |
gcloud beta compute ssh --tunnel-through-iap --zone "us-central1-a" "spring-boot-vm" --project "cloudorbit-stg" --command="sudo systemctl stop hello-world" | |
sleep 5 | |
gcloud compute scp target/hello-world.jar spring-boot-vm:/hello-world --zone=us-central1-a --project "cloudorbit-stg" --tunnel-through-iap | |
gcloud beta compute ssh --tunnel-through-iap --zone "us-central1-a" "spring-boot-vm" --project "cloudorbit-stg" --command="sudo systemctl start hello-world" | |
elif [ $1 == 'prod' ] | |
then | |
echo 'PROD DEPLOYMENT' | |
echo $PROD_GCP_TOKEN > /tmp/key.json | |
gcloud auth activate-service-account --key-file /tmp/key.json | |
gcloud beta compute ssh --tunnel-through-iap --zone "us-central1-a" "spring-boot-vm" --project "cloudorbit-prod" --command="sudo systemctl stop hello-world" | |
sleep 5 | |
gcloud compute scp target/hello-world.jar spring-boot-vm:/hello-world --zone=us-central1-a --project "cloudorbit-prod" --tunnel-through-iap | |
gcloud beta compute ssh --tunnel-through-iap --zone "us-central1-a" "spring-boot-vm" --project "cloudorbit-prod" --command="sudo systemctl start hello-world" | |
else | |
echo 'Unknown environment "$1".' | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment