-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpipeline.yml
65 lines (61 loc) · 3.43 KB
/
pipeline.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
resources:
- name: capi-workspace
type: git
source:
branch: new-workstations
uri: https://github.com/cloudfoundry/capi-workspace
- name: capi-env-pool
type: git
source:
branch: main
uri: [email protected]:pivotal-cf/capi-env-pool.git
private_key: ((pcf_bosh_lite_pool_deploy_key))
jobs:
- name: create-latest-workstation
plan:
- get: capi-workspace
- get: capi-env-pool
- task: create-workstation-image
config:
platform: linux
image_resource:
type: registry-image
source:
repository: google/cloud-sdk
params:
GCP_SERVICE_ACCOUNT_KEY: ((arya_gcp_json_key))
inputs:
- name: capi-workspace
- name: capi-env-pool
run:
path: bash
args:
- -c
- |
set -e
gcloud auth activate-service-account --key-file=<(echo $GCP_SERVICE_ACCOUNT_KEY)
echo "Creating Latest VM"
gcloud compute instances create capi-ws-vm-latest --zone "us-central1-a" --project "cf-capi-arya" --boot-disk-size=50GB --boot-disk-type=pd-balanced --machine-type=e2-standard-8 --tags=workstations --image-family=ubuntu-2204-lts --image-project=ubuntu-os-cloud
echo "wait 30 for instance to be up"
sleep 30
echo "copy capi-workspace over"
gcloud compute ssh --zone "us-central1-a" "pivotal@capi-ws-vm-latest" --project "cf-capi-arya" -q --command 'mkdir -p ~/workspace'
gcloud compute scp --recurse capi-workspace/ --zone "us-central1-a" "pivotal@capi-ws-vm-latest:~/workspace" --project "cf-capi-arya" -q
gcloud compute scp --recurse capi-env-pool/ --zone "us-central1-a" "pivotal@capi-ws-vm-latest:~/workspace" --project "cf-capi-arya" -q
echo "run set-up-new-machine.sh on workstation"
gcloud compute ssh --zone "us-central1-a" "pivotal@capi-ws-vm-latest" --project "cf-capi-arya" -q --command '~/workspace/capi-workspace/set-up-new-machine.sh' --ssh-flag="-A"
# if we don't wait, the last written file in the set up new machine script won't be written correctly when we make the machine image
sleep 30
gcloud compute machine-images describe capi-ws-image-latest --project "cf-capi-arya"
testVal=$?
if [[ $testVal -eq 0 ]]; then
echo "Delete old capi-ws-image-latest"
gcloud compute machine-images delete capi-ws-image-latest --project "cf-capi-arya" -q
fi
echo "Create source image from vm - 'capi-ws-image-latest' "
gcloud compute machine-images create capi-ws-image-latest --project "cf-capi-arya" --source-instance "capi-ws-vm-latest" --source-instance-zone "us-central1-a"
echo "Let's delete the source vm instance - use base image to create a workstation"
gcloud compute instances delete capi-ws-vm-latest --zone "us-central1-a" --project "cf-capi-arya" -q
echo "you should probably check to see if this worked now, it probably did!"
echo "try creating your own workstation vm from this image with: gcloud compute instances create capi-ws-yourname --zone 'us-central1-a' --source-machine-image 'capi-ws-image-latest'"
echo "connect with, gcloud compute ssh --zone 'us-central1-a' 'pivotal@capi-ws-yourname' --project 'cf-capi-arya' --ssh-flag='-A'"