-
Notifications
You must be signed in to change notification settings - Fork 0
/
debian-bookworm-gitlab-ci.yml
63 lines (61 loc) · 4.16 KB
/
debian-bookworm-gitlab-ci.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
stages:
- setup
- transfer
create_vm:
image:
name: gcr.io/google.com/cloudsdktool/cloud-sdk:latest
entrypoint: [""]
stage: setup
allow_failure: false
variables:
SETUP_COMMAND: 'git clone ${CI_REPOSITORY_URL} && /bin/bash +x /root/${CI_PROJECT_NAME}/setup.sh'
CLEANUP_COMMAND: 'rm /root/${CI_PROJECT_NAME}/setup.sh && rm /root/${CI_PROJECT_NAME}/.gitlab-ci.yml && rm /root/${CI_PROJECT_NAME}/.gitignore && rm /root/${CI_PROJECT_NAME}/README.md && rm -rf /root/${CI_PROJECT_NAME}/.git && history -c'
CHALLENGE_CLEAN_DIRECTORY: python3 -c 'import os;import shutil;shutil.rmtree("/root/${CI_PROJECT_NAME}/validators") if os.path.exists("/root/${CI_PROJECT_NAME}/validators") else print("no `validators` directory found")'
CHALLENGE_CLEAN_SOLUTIONS: python3 -c 'import os;os.remove("/root/${CI_PROJECT_NAME}/solution.md") if os.path.isfile("/root/${CI_PROJECT_NAME}/solution.md") else print("no `solution` file found")'
CHALLENGE_CLEAN_RESULTS_JSON: python3 -c 'import os;os.remove("/root/${CI_PROJECT_NAME}/results.json") if os.path.isfile("/root/${CI_PROJECT_NAME}/results.json") else print("no `results.json` file found")'
CHALLENGE_CLEAN_HISTORY: 'history -c'
before_script:
- apt update
- apt install -y wget git
- wget -O chit https://s3.amazonaws.com/theia-config-files/chit && mv chit /usr/bin/ && chmod +x /usr/bin/chit
- wget -O create_image.py https://s3.amazonaws.com/theia-config-files/create_image.py
- /usr/bin/chit configure -e [email protected] -t ${CHIT_TOKEN}
script:
- gcloud auth activate-service-account --key-file $SECONDARY_GOOGLE_CREDS
- gcloud config set project $SECONDARY_GCP_PROJECT_ID
- gcloud beta compute instances delete ${CI_PROJECT_NAME} --zone=${ZONE} || true
- gcloud beta compute instances create ${CI_PROJECT_NAME} --zone=${ZONE} --machine-type=${IMG_CONFIG} --subnet=image-vpc --network-tier=STANDARD --maintenance-policy=MIGRATE --no-service-account --no-scopes --tags=http-server,https-server --image=ase-deb-12-final --image-project=${SECONDARY_GCP_PROJECT_ID} --boot-disk-size=10GB --boot-disk-type=pd-ssd --boot-disk-device-name=${CI_PROJECT_NAME} --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any --metadata cos-update-strategy=update_disabled
- sleep 45
- gcloud compute ssh --zone ${ZONE} ${CI_PROJECT_NAME} -- ${SETUP_COMMAND}
- gcloud compute ssh --zone ${ZONE} ${CI_PROJECT_NAME} -- ${CLEANUP_COMMAND}
- gcloud compute ssh --zone ${ZONE} ${CI_PROJECT_NAME} -- ${CHALLENGE_CLEAN_DIRECTORY}
- gcloud compute ssh --zone ${ZONE} ${CI_PROJECT_NAME} -- ${CHALLENGE_CLEAN_SOLUTIONS}
- gcloud compute ssh --zone ${ZONE} ${CI_PROJECT_NAME} -- ${CHALLENGE_CLEAN_HISTORY}
- gcloud beta compute instances stop ${CI_PROJECT_NAME} --zone=${ZONE}
- gcloud beta compute images delete ${CI_PROJECT_NAME} || true
- gcloud beta compute images create ${CI_PROJECT_NAME} --source-disk=${CI_PROJECT_NAME} --source-disk-zone=${ZONE} --storage-location=us
- gcloud beta compute instances delete ${CI_PROJECT_NAME} --zone=${ZONE}
- echo "done"
- python3 create_image.py --name "${CI_PROJECT_NAME}" --email "${GITLAB_USER_EMAIL}" --url ${CI_PROJECT_URL}
- /usr/bin/chit create image -f ./image.json
artifacts:
paths: [image.json]
expire_in: never
transfer_vm:
image:
name: gcr.io/google.com/cloudsdktool/cloud-sdk:latest
entrypoint: [""]
variables:
SLACK_MESSAGE: '{"text":"${GITLAB_USER_EMAIL} transferred the ${CI_PROJECT_NAME} image to Primary GCP! <$CI_PROJECT_URL|Click here to view the pipeline>!"}'
stage: transfer
allow_failure: false
before_script:
- apt update
- apt install -y curl
script:
- gcloud auth activate-service-account --key-file $SECONDARY_GOOGLE_CREDS
- gcloud config set project $SECONDARY_GCP_PROJECT_ID
- gcloud beta compute --project=$PRIMARY_GCP_PROJECT_ID images delete ${CI_PROJECT_NAME} || true
- gcloud compute --project=$PRIMARY_GCP_PROJECT_ID images create ${CI_PROJECT_NAME} --source-image=${CI_PROJECT_NAME} --source-image-project=$SECONDARY_GCP_PROJECT_ID
- curl -X POST --data-urlencode "payload=$SLACK_MESSAGE" $SLACK_WEBHOOK_URL
when: manual