diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..802d2d4 --- /dev/null +++ b/.github/workflows/release.yaml @@ -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 diff --git a/.gitignore b/.gitignore index 1a05076..54e50f6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ /manifests/*.json.clean /manifests/tests/*.json /manifests/tests/*.json.clean +/manifests/ova/* +/manifests/ovf/** /export/** /packer* /govc* diff --git a/Makefile b/Makefile index c29cad0..e26c451 100644 --- a/Makefile +++ b/Makefile @@ -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 $@ $