Skip to content

Commit

Permalink
build: update gcp image upload playbook to support fedora 39
Browse files Browse the repository at this point in the history
  • Loading branch information
henrywang committed Aug 12, 2023
1 parent b331fb3 commit 4614877
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 28 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci-demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
- name: Show all environment variables
run: printenv

# runner-beaker-arm:
# runs-on: [kite, aarch64, beaker, fedora-37]
# steps:
# - name: Show all environment variables
# run: printenv
runner-beaker-arm:
runs-on: [kite, aarch64, beaker, fedora-37]
steps:
- name: Show all environment variables
run: printenv
32 changes: 32 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---

yaml-files:
- '*.yaml'
- '*.yml'
- '.yamllint'

rules:
braces: enable
brackets: enable
colons: enable
commas: enable
comments:
level: warning
comments-indentation:
level: warning
document-end: disable
document-start:
level: warning
empty-lines: enable
empty-values: disable
hyphens: enable
indentation: enable
key-duplicates: enable
key-ordering: disable
line-length: disable
new-line-at-end-of-file: enable
new-lines: enable
octal-values: disable
quoted-strings: disable
trailing-spaces: enable
truthy: disable
2 changes: 1 addition & 1 deletion tools/deploy_container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
groups: guest
runner_name: "{{ instance_name }}"

- name: set private key permisson to 600
- name: set private key permission to 600
file:
path: key/ostree_key
mode: "0600"
Expand Down
9 changes: 9 additions & 0 deletions tools/startup-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ source /etc/os-release
if [[ "$ID" == "fedora" ]]; then
growpart /dev/sda 5
btrfs filesystem resize 1:+70G /
dnf install -y python3 python3-dnf
fi

# Enable CRB repo or powertools repo on Centos Stream 9 or 8
if [[ "${ID}-${VERSION_ID}" == "centos-9" ]]; then
dnf config-manager --set-enabled crb
fi
if [[ "${ID}-${VERSION_ID}" == "centos-8" ]]; then
dnf config-manager --set-enabled powertools
fi
50 changes: 28 additions & 22 deletions tools/upload_gcp_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,22 @@
gather_facts: no
become: no
vars:
ci_env: "prod"
gcp_storage_bucket_name: "{{ lookup('env', 'GCP_STORAGE_BUCKET_NAME') }}"
gcp_service_account_file: "{{ lookup('env', 'GCP_SERVICE_ACCOUNT_FILE') }}"
gcp_service_account_name: "{{ lookup('env', 'GCP_SERVICE_ACCOUNT_NAME') }}"
gcp_project: "{{ lookup('env', 'GCP_PROJECT') }}"
os: "fedora-rawhide"
image_url:
fedora-rawhide: https://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/Cloud/x86_64/images
fedora-39: https://dl.fedoraproject.org/pub/fedora/linux/development/39/Cloud/x86_64/images
fedora-38: https://dl.fedoraproject.org/pub/fedora/linux/releases/38/Cloud/x86_64/images
fedora-37: https://dl.fedoraproject.org/pub/fedora/linux/releases/37/Cloud/x86_64/images
# image name must be a match of regex '[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?|[1-9][0-9]{0,19}'
gcp_image_name:
fedora-rawhide:
prod: "kite-image-fedora-rawhide"
stage: "kite-image-stage-fedora-rawhide"
fedora-38:
prod: "kite-image-fedora-38"
stage: "kite-image-stage-fedora-38"
fedora-37:
prod: "kite-image-fedora-37"
stage: "kite-image-stage-fedora-37"
fedora-rawhide: "kite-image-fedora-rawhide"
fedora-39: "kite-image-fedora-39"
fedora-38: "kite-image-fedora-38"
fedora-37: "kite-image-fedora-37"

tasks:
- name: get latest Fedora rawhide images
Expand All @@ -37,6 +32,17 @@
- os == "fedora-rawhide"
- result_file.changed

- name: get latest Fedora 39 images
shell: curl -s {{ image_url[os] }}/ | grep -ioE '>Fedora-Cloud-Base-GCP-39-.*.x86_64.tar.gz<' | tr -d '><'
register: result_file
when: os == "fedora-39"

- set_fact:
image_file_name: "{{ result_file.stdout }}"
when:
- os == "fedora-39"
- result_file.changed

- name: get latest Fedora 38 images
shell: curl -s {{ image_url[os] }}/ | grep -ioE '>Fedora-Cloud-Base-GCP-38-.*.x86_64.tar.gz<' | tr -d '><'
register: result_file
Expand Down Expand Up @@ -70,7 +76,7 @@
- name: create a bucket
google.cloud.gcp_storage_bucket:
name: "{{ gcp_storage_bucket_name }}"
project: virt-qe
project: "{{ gcp_project }}"
auth_kind: serviceaccount
service_account_file: "{{ gcp_service_account_file }}"
state: present
Expand All @@ -86,15 +92,15 @@
command: /usr/bin/gsutil -h Content-MD5:{{ md5_checksum }} cp /tmp/{{ image_file_name }} gs://{{ gcp_storage_bucket_name }}

- name: create image for test
command: /usr/bin/gcloud compute images create {{ gcp_image_name[os][ci_env] }}-tmp --source-uri gs://{{ gcp_storage_bucket_name }}/{{ image_file_name }} --guest-os-features="UEFI_COMPATIBLE,GVNIC,SEV_CAPABLE,VIRTIO_SCSI_MULTIQUEUE" --project={{ gcp_project }} --labels=kite=kite-image-{{ gcp_image_name[os][ci_env] }}
command: /usr/bin/gcloud compute images create {{ gcp_image_name[os] }}-tmp --source-uri gs://{{ gcp_storage_bucket_name }}/{{ image_file_name }} --guest-os-features="UEFI_COMPATIBLE,GVNIC,SEV_CAPABLE,VIRTIO_SCSI_MULTIQUEUE" --project={{ gcp_project }} --labels=kite=kite-image-{{ gcp_image_name[os] }}

# image test
- block:
- set_fact:
test_instance_name: "image-test-{{ gcp_image_name[os][ci_env] }}"
test_instance_name: "image-test-{{ gcp_image_name[os] }}"

- name: create gcp instance
command: /usr/bin/gcloud compute instances create "{{ test_instance_name }}" --zone=us-central1-a --machine-type=n2-standard-4 --boot-disk-auto-delete --boot-disk-size=80GB --boot-disk-type=pd-ssd --metadata-from-file=ssh-keys="{{ playbook_dir }}/key/gcp_key",startup-script="{{ playbook_dir }}/startup-script.sh" --metadata=block-project-ssh-keys=TRUE --provisioning-model=SPOT --image="{{ gcp_image_name[os][ci_env] }}-tmp" --enable-nested-virtualization --service-account="{{ gcp_service_account_name }}" --project="{{ gcp_project }}" --format=json
command: /usr/bin/gcloud compute instances create "{{ test_instance_name }}" --zone=us-central1-a --machine-type=n2-standard-4 --boot-disk-auto-delete --boot-disk-size=80GB --boot-disk-type=pd-ssd --metadata-from-file=ssh-keys="{{ playbook_dir }}/key/gcp_key",startup-script="{{ playbook_dir }}/startup-script.sh" --metadata=block-project-ssh-keys=TRUE --provisioning-model=SPOT --image="{{ gcp_image_name[os] }}-tmp" --enable-nested-virtualization --service-account="{{ gcp_service_account_name }}" --project="{{ gcp_project }}" --format=json
register: result_instance

- set_fact:
Expand Down Expand Up @@ -160,27 +166,27 @@
msg: "upload GCP image fail"

always:
- name: "delete tmp image {{ gcp_image_name[os][ci_env] }}-tmp"
command: /usr/bin/gcloud compute images delete {{ gcp_image_name[os][ci_env] }}-tmp --quiet --project={{ gcp_project }}
- name: "delete tmp image {{ gcp_image_name[os] }}-tmp"
command: /usr/bin/gcloud compute images delete {{ gcp_image_name[os] }}-tmp --quiet --project={{ gcp_project }}

- name: delete test instance
command: /usr/bin/gcloud compute instances delete {{ test_instance_name }} --quiet --zone=us-central1-a --delete-disks=all --project={{ gcp_project }}

- name: old image exists or not
google.cloud.gcp_compute_image_info:
filters:
- name = "{{ gcp_image_name[os][ci_env] }}"
project: virt-qe
- name = "{{ gcp_image_name[os] }}"
project: "{{ gcp_project }}"
auth_kind: serviceaccount
service_account_file: "{{ gcp_service_account_file }}"
register: result_image

- name: "delete old image {{ gcp_image_name[os][ci_env] }}"
command: /usr/bin/gcloud compute images delete {{ gcp_image_name[os][ci_env] }} --project={{ gcp_project }}
- name: "delete old image {{ gcp_image_name[os] }}"
command: /usr/bin/gcloud compute images delete {{ gcp_image_name[os] }} --project={{ gcp_project }}
when: result_image.resources != []

- name: "create new {{ gcp_image_name[os][ci_env] }}"
command: /usr/bin/gcloud compute images create {{ gcp_image_name[os][ci_env] }} --source-uri gs://{{ gcp_storage_bucket_name }}/{{ image_file_name }} --guest-os-features="UEFI_COMPATIBLE,GVNIC,SEV_CAPABLE,VIRTIO_SCSI_MULTIQUEUE" --project={{ gcp_project }} --labels=kite=kite-image-{{ gcp_image_name[os][ci_env] }}
- name: "create new {{ gcp_image_name[os] }}"
command: /usr/bin/gcloud compute images create {{ gcp_image_name[os] }} --source-uri gs://{{ gcp_storage_bucket_name }}/{{ image_file_name }} --guest-os-features="UEFI_COMPATIBLE,GVNIC,SEV_CAPABLE,VIRTIO_SCSI_MULTIQUEUE" --project={{ gcp_project }} --labels=kite=kite-image-{{ gcp_image_name[os] }}

- name: "delete {{ image_file_name }} from bucket {{ gcp_storage_bucket_name }}"
command: /usr/bin/gsutil rm gs://{{ gcp_storage_bucket_name }}/{{ image_file_name }}

0 comments on commit 4614877

Please sign in to comment.