Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add release-pipeline #6

Merged
merged 8 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
---
name: Release

on:
push:
tags:
- 'v*'
jobs:
release:
name: Create D2iQ Templates
runs-on:
- self-hosted
- small
strategy:
fail-fast: false
matrix:
os: ["ubuntu", "rocky", "centos", "rhel", "flatcar"]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.ref }}
- name: Setup requirements
run: |
sudo apt-get update && sudo apt-get -y install xorriso
curl -L -o - "https://github.com/vmware/govmomi/releases/latest/download/govc_$(uname -s)_$(uname -m).tar.gz" | sudo tar -C /usr/local/bin -xvzf - govc
- name: Run release for ${{ matrix.os }}
run: make ${{ matrix.os }}-release
env:
VSPHERE_USERNAME: ${{ secrets.VSPHERE_SRE_USERNAME }}
VSPHERE_PASSWORD: ${{ secrets.VSPHERE_SRE_PASSWORD }}
VSPHERE_SERVER: ${{ secrets.VSPHERE_SERVER }}
GOVC_URL: ${{ secrets.VSPHERE_SRE_USERNAME }}:${{ secrets.VSPHERE_SRE_PASSWORD }}@${{ secrets.VSPHERE_SERVER }}
PKR_VAR_vsphere_cluster: ${{ secrets.VSPHERE_CLUSTER }}
PKR_VAR_vsphere_datacenter: ${{ secrets.VSPHERE_DATACENTER }}
PKR_VAR_vsphere_datastore: ${{ secrets.VSPHERE_DATASTORE }}
PKR_VAR_vsphere_network: ${{ secrets.VSPHERE_NETWORK }}
PKR_VAR_vsphere_resource_pool: ${{ secrets.VSPHERE_RESOURCE_POOL }}
RHN_SUBSCRIPTION_ORG: ${{ secrets.RHN_SUBSCRIPTION_ORG }}
RHN_SUBSCRIPTION_KEY: ${{ secrets.RHN_SUBSCRIPTION_KEY }}
create_release:
name: Create Github release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
export:
name: Generate OVF for Export
needs: [release]
runs-on:
- self-hosted
- small
strategy:
fail-fast: false
matrix:
os: ["ubuntu", "rocky", "centos", "flatcar"]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.ref }}
- name: Setup requirements
run: |
sudo apt-get update && sudo apt-get -y install xorriso
- name: Export ovf for ${{ matrix.os }}
run: make ${{ matrix.os }}-ovf
env:
VSPHERE_USERNAME: ${{ secrets.VSPHERE_SRE_USERNAME }}
VSPHERE_PASSWORD: ${{ secrets.VSPHERE_SRE_PASSWORD }}
VSPHERE_SERVER: ${{ secrets.VSPHERE_SERVER }}
GOVC_URL: ${{ secrets.VSPHERE_SRE_USERNAME }}:${{ secrets.VSPHERE_SRE_PASSWORD }}@${{ secrets.VSPHERE_SERVER }}
PKR_VAR_vsphere_cluster: ${{ secrets.VSPHERE_CLUSTER }}
PKR_VAR_vsphere_datacenter: ${{ secrets.VSPHERE_DATACENTER }}
PKR_VAR_vsphere_datastore: ${{ secrets.VSPHERE_DATASTORE }}
PKR_VAR_vsphere_network: ${{ secrets.VSPHERE_NETWORK }}
PKR_VAR_vsphere_resource_pool: ${{ secrets.VSPHERE_RESOURCE_POOL }}
RHN_SUBSCRIPTION_ORG: ${{ secrets.RHN_SUBSCRIPTION_ORG }}
RHN_SUBSCRIPTION_KEY: ${{ secrets.RHN_SUBSCRIPTION_KEY }}
- name: Export ovf for ${{ matrix.os }}
run: make ${{ matrix.os }}-ovf
- uses: actions/upload-artifact@v3
with:
name: releaseovf
path: |
manifests/ovf/*.ovf.tar.gz
artifactinventory:
name: Create artifact inventory
runs-on: ubuntu-latest
needs: [export]
outputs:
listovf: ${{ steps.list.outputs.listovf }}
steps:
- uses: actions/download-artifact@v3
id: download
with:
name: releaseovf
path: releaseovf/
- name: json from downloaded artifacts
id: list
run: |
DATA=$(ls releaseovf/*.ovf.tar.gz | jq -R -s -c 'split("\n")[:-1]')
echo "listovf=$DATA" >> "$GITHUB_OUTPUT"
releaseassets:
name: Upload release assets
runs-on: ubuntu-latest
needs: [create_release, artifactinventory]
strategy:
fail-fast: false
matrix:
ovf: ${{ fromJSON(needs.artifactinventory.outputs.listovf) }}
steps:
- uses: actions/download-artifact@v3
id: download
with:
name: releaseovf
path: releaseovf/
- name: Upload ovf
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ./releaseovf/${{ matrix.ovf }}
asset_name: ${{ matrix.ovf }}
asset_content_type: application/zip
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/manifests/*.json.clean
/manifests/tests/*.json
/manifests/tests/*.json.clean
/manifests/ova/*
/manifests/ovf/**
/export/**
/packer*
/govc*
Expand Down
31 changes: 26 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,30 @@ manifests/d2iq-base-%$(NAME_POSTFIX).json: packer.initialized vsphere.pkr.hcl $(

.PHONY: manifests/d2iq-base-%$(NAME_POSTFIX).json.clean
manifests/d2iq-base-%$(NAME_POSTFIX).json.clean: manifests/d2iq-base-%$(NAME_POSTFIX).json
bash -x mkinclude/helper_deletetemplate.sh $(shell jq -r '.builds[0].custom_data.template' $<)
bash -x mkinclude/helper_deletetemplate.sh $(shell jq -r '.builds[0].custom_data.template' $<) "" $(shell jq -r '.builds[0].custom_data.resource_pool' $<)
mv $< $@

manifests/tests/d2iq-base-%$(NAME_POSTFIX).json: manifests/d2iq-base-%$(NAME_POSTFIX).json clone-test.pkr.hcl
$(PACKER) build -force -var vsphere_folder=$(VSPHERE_FOLDER) -var vm_name=test-$(shell basename -s .json $<) -var template_manifest=$< -var manifest_output=$@ -on-error="$(PACKER_ON_ERROR)" clone-test.pkr.hcl

manifests/ovf/d2iq-base-%$(NAME_POSTFIX).ovf: manifests/d2iq-base-%$(NAME_POSTFIX).json
bash mkinclude/helper_markasvm.sh $(VSPHERE_FOLDER)/d2iq-base-$* "" $(shell jq -r '.builds[0].custom_data.resource_pool' $<)
$(GOVC) export.ovf -dc=$(shell jq -r '.builds[0].custom_data.datacenter' $<) -vm=$(VSPHERE_FOLDER)/$(shell jq -r '.builds[0].custom_data.template_name' $<) $@
tar -czf $@.tar.gz $@/*

# manifests/ova/d2iq-base-%$(NAME_POSTFIX).ova: manifests/ovf/d2iq-base-%$(NAME_POSTFIX).ovf
# tar -cvf $@ $</d2iq-base-$*$(NAME_POSTFIX)/*.ovf $</d2iq-base-$*$(NAME_POSTFIX)/*.vmdk

.PHONY: manifests/tests/d2iq-base-%$(NAME_POSTFIX).json.clean
manifests/tests/d2iq-base-%$(NAME_POSTFIX).json.clean: manifests/tests/d2iq-base-%$(NAME_POSTFIX).json
govc vm.destroy /$(shell jq -r '.builds[0].custom_data.datacenter' $<)/vm/$(VSPHERE_FOLDER)/test-$(shell basename -s .json $<)
$(GOVC) vm.destroy /$(shell jq -r '.builds[0].custom_data.datacenter' $<)/vm/$(VSPHERE_FOLDER)/test-$(shell basename -s .json $<)
mv $< $@

.PHONY: release/d2iq-base-%$(NAME_POSTFIX)
release/d2iq-base-%$(NAME_POSTFIX): manifests/d2iq-base-%$(NAME_POSTFIX).json
bash mkinclude/helper_deletetemplate.sh $(RELEASE_FOLDER)/d2iq-base-$* || true
govc object.rename /$(shell jq -r '.builds[0].custom_data.datacenter' $<)/vm/$(shell jq -r '.builds[0].custom_data.template_name' $<) d2iq-base-$*
govc object.mv /$(shell jq -r '.builds[0].custom_data.datacenter' $<)/vm/$(VSPHERE_FOLDER)/d2iq-base-$* /$(shell jq -r '.builds[0].custom_data.datacenter' $<)/vm/$(RELEASE_FOLDER)
bash mkinclude/helper_deletetemplate.sh $(RELEASE_FOLDER)/d2iq-base-$* "" $(shell jq -r '.builds[0].custom_data.resource_pool' $<)
$(GOVC) object.rename /$(shell jq -r '.builds[0].custom_data.datacenter' $<)/vm/$(shell jq -r '.builds[0].custom_data.template_name' $<) d2iq-base-$*
$(GOVC) object.mv /$(shell jq -r '.builds[0].custom_data.datacenter' $<)/vm/$(VSPHERE_FOLDER)/d2iq-base-$* /$(shell jq -r '.builds[0].custom_data.datacenter' $<)/vm/$(RELEASE_FOLDER)

ubuntu: manifests/d2iq-base-Ubuntu-20.04$(NAME_POSTFIX).json manifests/d2iq-base-Ubuntu-22.04$(NAME_POSTFIX).json
ubuntu-test-20: manifests/tests/d2iq-base-Ubuntu-20.04$(NAME_POSTFIX).json.clean
Expand All @@ -40,6 +48,10 @@ ubuntu-test: ubuntu-test-20-clean ubuntu-test-22-clean
ubuntu-release-20: ubuntu-test-20 release/d2iq-base-Ubuntu-20.04$(NAME_POSTFIX)
ubuntu-release-22: ubuntu-test-22 release/d2iq-base-Ubuntu-22.04$(NAME_POSTFIX)
ubuntu-release: ubuntu-release-20 ubuntu-release-22
ubuntu-ovf-20: manifests/ovf/d2iq-base-Ubuntu-20.04$(NAME_POSTFIX).ovf
ubuntu-ovf-22: manifests/ovf/d2iq-base-Ubuntu-22.04$(NAME_POSTFIX).ovf
ubuntu-ovf: ubuntu-ovf-20 ubuntu-ovf-22


rocky: manifests/d2iq-base-RockyLinux-8.7$(NAME_POSTFIX).json manifests/d2iq-base-RockyLinux-9.1$(NAME_POSTFIX).json
rocky-test-87: manifests/tests/d2iq-base-RockyLinux-8.7$(NAME_POSTFIX).json.clean
Expand All @@ -50,13 +62,18 @@ rocky-test: rocky-test-87-clean rocky-test-91-clean
rocky-release-87: rocky-test-87 release/d2iq-base-RockyLinux-8.7$(NAME_POSTFIX)
rocky-release-91: rocky-test-91 release/d2iq-base-RockyLinux-9.1$(NAME_POSTFIX)
rocky-release: rocky-release-87 rocky-release-91
rocky-ovf-87: manifests/ovf/d2iq-base-RockyLinux-8.7$(NAME_POSTFIX).ovf
rocky-ovf-91: manifests/ovf/d2iq-base-RockyLinux-9.1$(NAME_POSTFIX).ovf
rocky-ovf: rocky-ovf-87 rocky-ovf-91

centos: manifests/d2iq-base-CentOS-7.9$(NAME_POSTFIX).json
centos-test-79: manifests/tests/d2iq-base-CentOS-7.9$(NAME_POSTFIX).json.clean
centos-test-79-clean: centos-test-79 manifests/d2iq-base-CentOS-7.9$(NAME_POSTFIX).json.clean
centos-test: centos-test-79-clean
centos-release-79: centos-test-79 release/d2iq-base-CentOS-7.9$(NAME_POSTFIX)
centos-release: centos-release-79
centos-ovf-79: manifests/ovf/d2iq-base-CentOS-7.9$(NAME_POSTFIX).ovf
centos-ovf: centos-ovf-79

rhel: manifests/d2iq-base-RHEL-79$(NAME_POSTFIX).json manifests/d2iq-base-RHEL-84$(NAME_POSTFIX).json manifests/d2iq-base-RHEL-86$(NAME_POSTFIX).json
rhel-test-79: manifests/tests/d2iq-base-RHEL-79$(NAME_POSTFIX).json.clean
Expand All @@ -70,6 +87,10 @@ rhel-release-79: rhel-test-79 release/d2iq-base-RHEL-79$(NAME_POSTFIX)
rhel-release-84: rhel-test-84 release/d2iq-base-RHEL-84$(NAME_POSTFIX)
rhel-release-86: rhel-test-86 release/d2iq-base-RHEL-86$(NAME_POSTFIX)
rhel-release: rhel-release-79 rhel-release-84 rhel-release-86
rhel-ovf-79: manifests/ovf/d2iq-base-RHEL-79$(NAME_POSTFIX).ovf
rhel-ovf-84: manifests/ovf/d2iq-base-RHEL-84$(NAME_POSTFIX).ovf
rhel-ovf-86: manifests/ovf/d2iq-base-RHEL-86$(NAME_POSTFIX).ovf
rhel-ovf: rhel-ovf-79 rhel-ovf-84 rhel-ovf-86

flatcar: manifests/d2iq-base-Flatcar-3033.3.16$(NAME_POSTFIX).json
flatcar-test-3033: manifests/tests/d2iq-base-Flatcar-3033.3.16$(NAME_POSTFIX).json
Expand Down
Empty file added manifests/ova/.gitkeep
Empty file.
Empty file added manifests/ovf/.gitkeep
Empty file.
11 changes: 10 additions & 1 deletion mkinclude/helper_deletetemplate.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/bin/bash
DATACENTER=${DATACENTER:-$PKR_VAR_vsphere_datacenter}
CLUSTER=${CLUSTER:-$PKR_VAR_vsphere_cluster}

VM_NAME="${1}"
VM_FOLDER="${2}"
VM_POOL="${3}"


VMBASEPATH="/${DATACENTER}/vm/${VM_FOLDER}"
VMPATH="${VMBASEPATH%%/}/${VM_NAME}"
POOLPATH="/${DATACENTER}/host/${CLUSTER}/Resources/${VM_POOL}"

# FIXME: does not work.
if ! govc vm.info "${VMPATH%%/}"; then
Expand All @@ -20,5 +23,11 @@ if [ "${esxhost}" == "" ]; then
exit 0
fi

govc vm.markasvm -host="$esxhost" -dc="${DATACENTER}" "${VMPATH%%/}"
# if VM_POOL is set inject the pool into the command
if [ "${VM_POOL}" != "" ]; then
ADDOPT="-pool=${POOLPATH}"
fi

# shellcheck disable=SC2086
govc vm.markasvm -host="$esxhost" -dc="${DATACENTER}" $ADDOPT "${VMPATH%%/}"
govc vm.destroy "${VMPATH%%/}"
30 changes: 30 additions & 0 deletions mkinclude/helper_markasvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
DATACENTER=${DATACENTER:-$PKR_VAR_vsphere_datacenter}

VM_NAME="${1}"
VM_FOLDER="${2}"
VM_POOL="${3}"


VMBASEPATH="/${DATACENTER}/vm/${VM_FOLDER}"
VMPATH="${VMBASEPATH%%/}/${VM_NAME}"

# FIXME: does not work.
if ! govc vm.info "${VMPATH%%/}"; then
echo "VM ${VMPATH%%/} not found"
exit 0
fi

esxhost=$(govc vm.info "${VMPATH%%/}" | grep 'Host:' | awk '{print $2}')
if [ "${esxhost}" == "" ]; then
echo "VM ${VMPATH%%/} not found"
exit 0
fi

# if VM_POOL is set inject the pool into the command
if [ "${VM_POOL}" != "" ]; then
ADDOPT="-pool=${VM_POOL}"
fi

# shellcheck disable=SC2086
govc vm.markasvm -host="$esxhost" -dc="${DATACENTER}" $ADDOPT "${VMPATH%%/}"
1 change: 1 addition & 0 deletions vsphere.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ build {
datacenter = var.vsphere_datacenter
distribution = var.distribution
distribution_version = var.distribution_version
resource_pool = var.vsphere_resource_pool
bootconfig_type = var.bootconfig_type
}
}
Expand Down