|
| 1 | + |
| 2 | +name: Build, deploy and promote a new OHPC image |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + promote_community: |
| 7 | + description: 'Set the community property on a successfully tested image' |
| 8 | + required: true |
| 9 | + default: false |
| 10 | + type: boolean |
| 11 | + pull_request: |
| 12 | + push: |
| 13 | + branches: |
| 14 | + - main |
| 15 | + tags: |
| 16 | + - '*' |
| 17 | +jobs: |
| 18 | + build-deploy-promote: |
| 19 | + name: Build, deploy and promote a new OHPC image |
| 20 | + if: github.repository == 'stackhpc/caas-slurm-appliance' |
| 21 | + concurrency: ${{ github.ref }} |
| 22 | + runs-on: ubuntu-20.04 |
| 23 | + env: |
| 24 | + ANSIBLE_FORCE_COLOR: True |
| 25 | + OS_CLOUD: openstack |
| 26 | + OS_CLIENT_CONFIG_FILE: ${{ github.workspace }}/clouds.yaml |
| 27 | + EXTRA_VARS_FILE: .github/extra_vars/arcus.yml |
| 28 | + steps: |
| 29 | + - name: Checkout repository |
| 30 | + uses: actions/checkout@v3 |
| 31 | + with: |
| 32 | + submodules: true |
| 33 | + |
| 34 | + - name: Install ansible etc |
| 35 | + run: dev/setup-env.sh |
| 36 | + |
| 37 | + - name: Write clouds.yaml |
| 38 | + run: | |
| 39 | + echo "${CLOUDS_YAML}" > ${OS_CLIENT_CONFIG_FILE} |
| 40 | + shell: bash |
| 41 | + env: |
| 42 | + CLOUDS_YAML: ${{ secrets.CLOUDS_YAML }} |
| 43 | + |
| 44 | + - name: Build OHPC image |
| 45 | + id: build |
| 46 | + run: | |
| 47 | + source venv/bin/activate |
| 48 | + ansible-playbook \ |
| 49 | + -i image-build/hosts \ |
| 50 | + -e @${EXTRA_VARS_FILE} \ |
| 51 | + -e '{"write_cluster_image_uuid_file": true}' \ |
| 52 | + -e image_build_cluster_id="image-build-${GITHUB_SHA::7}" \ |
| 53 | + image-build.yml |
| 54 | + echo "CLUSTER_IMAGE=$(cat cluster_image_uuid.txt)" >> $GITHUB_OUTPUT |
| 55 | + env: |
| 56 | + PACKER_LOG_PATH: ${{ github.workspace }}/packer-build.log |
| 57 | + |
| 58 | + - name: Remove image build infra |
| 59 | + run: | |
| 60 | + source venv/bin/activate |
| 61 | + ansible-playbook \ |
| 62 | + -i image-build/hosts \ |
| 63 | + -e @${EXTRA_VARS_FILE} \ |
| 64 | + -e cluster_state=absent \ |
| 65 | + -e image_build_cluster_id="image-build-${GITHUB_SHA::7}" \ |
| 66 | + image-build.yml |
| 67 | + if: always() |
| 68 | + |
| 69 | + - name: Deploy a cluster based on the new OPHC image |
| 70 | + id: deploy |
| 71 | + run: | |
| 72 | + source venv/bin/activate |
| 73 | + ansible-playbook \ |
| 74 | + -i image-build/hosts \ |
| 75 | + -e @${EXTRA_VARS_FILE} \ |
| 76 | + -e cluster_image=${{ steps.build.outputs.CLUSTER_IMAGE }} \ |
| 77 | + -e cluster_name="caas-ci-${GITHUB_SHA::7}" \ |
| 78 | + slurm-infra.yml |
| 79 | + env: |
| 80 | + SLURM_INFRA_HIDE_DEBUG_OUTPUT: True |
| 81 | + if: success() |
| 82 | + |
| 83 | + - name: Remove cluster based on the new OHPC image |
| 84 | + run: | |
| 85 | + source venv/bin/activate |
| 86 | + ansible-playbook \ |
| 87 | + -i image-build/hosts \ |
| 88 | + -e @${EXTRA_VARS_FILE} \ |
| 89 | + -e cluster_image=${{ steps.build.outputs.CLUSTER_IMAGE }} \ |
| 90 | + -e cluster_state=absent \ |
| 91 | + -e cluster_name="caas-ci-${GITHUB_SHA::7}" \ |
| 92 | + slurm-infra.yml |
| 93 | + if: | |
| 94 | + ( success() || failure() || cancelled() ) && |
| 95 | + steps.build.outcome == 'success' |
| 96 | +
|
| 97 | + - name: Delete built image after testing |
| 98 | + run: | |
| 99 | + source venv/bin/activate |
| 100 | + ansible-playbook \ |
| 101 | + -i image-build/hosts \ |
| 102 | + -e cluster_image=${{ steps.build.outputs.CLUSTER_IMAGE }} \ |
| 103 | + -e '{"cluster_image_delete": true}' \ |
| 104 | + image-build/image-delete-or-promote.yml |
| 105 | + if: | |
| 106 | + ( success() || failure() || cancelled() ) && |
| 107 | + steps.build.outcome == 'success' && |
| 108 | + github.event_name == 'pull_request' |
| 109 | +
|
| 110 | + - name: Promote built image from Private to Community after testing |
| 111 | + run: | |
| 112 | + source venv/bin/activate |
| 113 | + ansible-playbook \ |
| 114 | + -i image-build/hosts \ |
| 115 | + -e cluster_image=${{ steps.build.outputs.CLUSTER_IMAGE }} \ |
| 116 | + -e '{"cluster_image_promote_community": true}' \ |
| 117 | + image-build/image-delete-or-promote.yml |
| 118 | + if: | |
| 119 | + success() && |
| 120 | + steps.build.outcome == 'success' && |
| 121 | + steps.deploy.outcome == 'success' && |
| 122 | + (( github.event_name == 'workflow_dispatch' && inputs.promote_community == true ) |
| 123 | + || github.event_name == 'push' ) |
| 124 | +
|
| 125 | + - name: Upload packer build log artifact |
| 126 | + uses: actions/upload-artifact@v3 |
| 127 | + with: |
| 128 | + name: packer-build-log |
| 129 | + path: ${{ github.workspace }}/packer-build.log |
| 130 | + if: failure() || success() |
0 commit comments