Skip to content

Commit

Permalink
Merge branch 'topic/okurth/ci-add-gitlab-runner' into 'master'
Browse files Browse the repository at this point in the history
ci: add gitlab-runner example

See merge request core-build/photon-os-installer!102
  • Loading branch information
Oliver Kurth committed Nov 15, 2024
2 parents 476f085 + 6704534 commit 1e1c626
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 6 deletions.
17 changes: 13 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,28 @@ ova-poi-harness:
- NAME:
- minimal
- minimal_lvm
OVA_CONFIG: minimal_ova.yaml
- NAME: gitlab-runner
OVA_CONFIG: gitlab-runner_ova.yaml
- NAME: minimal
OVA_CONFIG: minimal_ova.yaml
PHOTON_RELEASE: "4.0"

script:
- VM_NAME=${VM_NAME_BASE}-${NAME}
- KS_FILE=${NAME}_ks.yaml
- PHOTON_RELEASE="${PHOTON_RELEASE:-5.0}"
- VM_NAME=${VM_NAME_BASE}-${NAME}-${PHOTON_RELEASE}

- docker pull ${POI_REGISTRY}/${POI_IMAGE_NAME}
- docker tag ${POI_REGISTRY}/${POI_IMAGE_NAME} ${POI_IMAGE_NAME}

- cd examples/ova
- docker run --rm --privileged -v/dev:/dev -v$(pwd):/workdir ${POI_IMAGE_NAME} create-image --repo-paths= -c ${KS_FILE} -v 5.0
- docker run --rm -v$(pwd):/workdir -w/workdir ${POI_IMAGE_NAME} create-ova --ovf --mf --vmdk --installer-config ${KS_FILE} --ova-config minimal_ova.yaml
- docker run --rm --privileged -v/dev:/dev -v$(pwd):/workdir ${POI_IMAGE_NAME} create-image --repo-paths= -c ${KS_FILE} -v ${PHOTON_RELEASE}
- docker run --rm -v$(pwd):/workdir -w/workdir ${POI_IMAGE_NAME} create-ova --ovf --mf --vmdk --installer-config ${KS_FILE} --ova-config ${OVA_CONFIG}
# clone the harness code
- git clone --depth=1 https://:${POI_HARNESS_PULL_TOKEN}@${CI_SERVER_HOST}/photon/poi-harness.git
- pytest ./poi-harness/ci/pytest/ -rs --deploy --ovf *.ovf --name ${VM_NAME} --vc_config ${VC_CONFIG_FILE} --ks_config ${KS_FILE} --ova_config minimal_ova.yaml
- (cd poi-harness && echo "poi-harness sha is $(git rev-parse --short HEAD)")
- pytest ./poi-harness/ci/pytest/ -rs --deploy --ovf *.ovf --name ${VM_NAME} --vc_config ${VC_CONFIG_FILE} --ks_config ${KS_FILE} --ova_config ${OVA_CONFIG}
after_script:
# change ownerships for cleanup
- cd examples/ova
Expand Down
86 changes: 86 additions & 0 deletions examples/ova/gitlab-runner_ks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
live: False

password:
crypted: false
text: changeme

disks:
default:
filename: !param rootdisk=root.img
size: 40960

partitions:
- mountpoint: /
size: 0
filesystem: ext4
- mountpoint: /boot
size: 128
filesystem: ext4
- size: 4
filesystem: swap

repos:
photon:
name: "Photon 5.0"
baseurl: !param photon_repo_url=https://packages.vcfd.broadcom.net/artifactory/photonos-rpm-local/$releasever/photon_updates_$releasever_$basearch/
enabled: 1
gpgcheck: 0

packagelist_file: packages_minimal.json

additional_packages:
# install vim because you probably need to edit config files
- vim
- build-essential
- zlib-devel
# to build docker images
- docker-buildx
# gitlab runner needs git
- git
# python3 is optional, but many CI/CD jobs will need it
- python3
- python3-PyYAML
- python3-pytest
- python3-lxml
- python3-xmltodict
# to install gitlab python package
- python3-pip
- jq
- tar
- sshpass

linux_flavor: linux

additional_files:
- sudoers-wheel-nopasswd: /etc/sudoers.d/wheel-nopasswd

postinstall:
# see https://docs.gitlab.com/runner/install/linux-manually.html#using-binary-file
- curl -L --output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64"
- chmod +x /usr/local/bin/gitlab-runner
- useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
- gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner

- pip3 install git+https://github.com/python-gitlab/python-gitlab.git

# some scripts use pytest-3
- ln -fs /usr/bin/pytest3.11 /usr/bin/pytest-3

# enable docker and allow gitlab-runner to use it
- systemctl enable docker
- usermod -aG docker gitlab-runner

# sudo access for gitlab-runner
- usermod -aG wheel gitlab-runner

# allow ssh root login - needed for testing
- sed -i "s/\(^PermitRootLogin\)[ ]*no$/\1 yes/g" /etc/ssh/sshd_config

docker:
images:
- method: pull
name: dockerhub.artifactory.vcfd.broadcom.net/photon:5.0
tags:
- photon:5.0

eject_cdrom: false
46 changes: 46 additions & 0 deletions examples/ova/gitlab-runner_ova.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
system:
name: glrunner
type: vmx-14 vmx-20 vmx-21
os_vmw: vmwarePhoton64Guest
firmware: efi
secure_boot: false

networks:
vm_network:
name: "VM Network"
description: "The VM Network network"

hardware:
cpus:
type: cpus
number: 4
memory:
type: memory
size: 8192
sata1:
type: sata_controller
scsi1:
type: scsi_controller
rootdisk:
type: hard_disk
parent: scsi1
raw_image: !param rootdisk=root.img
usb1:
type: usb_controller
ethernet1:
type: ethernet
subtype: VmxNet3
network: vm_network
videocard1:
type: video_card
vmci1:
type: vmci

product:
product: Photon OS Gitlab Runner
vendor: VMware Inc.

annotation:
text: >
Provides a simple gitlab runner based on Photon.
2 changes: 1 addition & 1 deletion examples/ova/minimal_ks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ partitions:

repos:
photon:
name: "Photon 5.0"
name: "Photon"
baseurl: !param photon_repo_url=https://packages.vmware.com/photon/$releasever/photon_updates_$releasever_$basearch
enabled: 1
gpgcheck: 0
Expand Down
2 changes: 1 addition & 1 deletion examples/ova/minimal_lvm_ks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ partitions:

repos:
photon:
name: "Photon 5.0"
name: "Photon"
baseurl: !param photon_repo_url=https://packages.vmware.com/photon/$releasever/photon_updates_$releasever_$basearch
enabled: 1
gpgcheck: 0
Expand Down
1 change: 1 addition & 0 deletions examples/ova/sudoers-wheel-nopasswd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
%wheel ALL=(ALL:ALL) NOPASSWD: ALL

0 comments on commit 1e1c626

Please sign in to comment.