|
| 1 | +name: Nightly fat image build |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + schedule: |
| 5 | + - cron: '0 0 * * *' # Run at midnight |
| 6 | + |
| 7 | +jobs: |
| 8 | + openstack: |
| 9 | + name: openstack-imagebuild |
| 10 | + concurrency: |
| 11 | + group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os_version }}-${{ matrix.build }} # to branch/PR + OS + build |
| 12 | + cancel-in-progress: true |
| 13 | + runs-on: ubuntu-22.04 |
| 14 | + strategy: |
| 15 | + fail-fast: false # allow other matrix jobs to continue even if one fails |
| 16 | + matrix: # build RL8+OFED, RL9+OFED base images |
| 17 | + os_version: |
| 18 | + - RL8 |
| 19 | + - RL9 |
| 20 | + build: |
| 21 | + - openstack.openhpc-latest |
| 22 | + env: |
| 23 | + ANSIBLE_FORCE_COLOR: True |
| 24 | + OS_CLOUD: openstack |
| 25 | + CI_CLOUD: ${{ vars.CI_CLOUD }} |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v2 |
| 28 | + |
| 29 | + - name: Setup ssh |
| 30 | + run: | |
| 31 | + set -x |
| 32 | + mkdir ~/.ssh |
| 33 | + echo "${{ secrets[format('{0}_SSH_KEY', vars.CI_CLOUD)] }}" > ~/.ssh/id_rsa |
| 34 | + chmod 0600 ~/.ssh/id_rsa |
| 35 | + shell: bash |
| 36 | + |
| 37 | + - name: Add bastion's ssh key to known_hosts |
| 38 | + run: cat environments/.stackhpc/bastion_fingerprints >> ~/.ssh/known_hosts |
| 39 | + shell: bash |
| 40 | + |
| 41 | + - name: Install ansible etc |
| 42 | + run: dev/setup-env.sh |
| 43 | + |
| 44 | + - name: Write clouds.yaml |
| 45 | + run: | |
| 46 | + mkdir -p ~/.config/openstack/ |
| 47 | + echo "${{ secrets[format('{0}_CLOUDS_YAML', vars.CI_CLOUD)] }}" > ~/.config/openstack/clouds.yaml |
| 48 | + shell: bash |
| 49 | + |
| 50 | + - name: Setup environment |
| 51 | + run: | |
| 52 | + . venv/bin/activate |
| 53 | + . environments/.stackhpc/activate |
| 54 | +
|
| 55 | + - name: Build fat image with packer |
| 56 | + id: packer_build |
| 57 | + run: | |
| 58 | + set -x |
| 59 | + . venv/bin/activate |
| 60 | + . environments/.stackhpc/activate |
| 61 | + cd packer/ |
| 62 | + packer init . |
| 63 | +
|
| 64 | + PACKER_LOG=1 packer build \ |
| 65 | + -on-error=${{ vars.PACKER_ON_ERROR }} \ |
| 66 | + -only=${{ matrix.build }} \ |
| 67 | + -var-file=$PKR_VAR_environment_root/${{ vars.CI_CLOUD }}.pkrvars.hcl \ |
| 68 | + openstack.pkr.hcl |
| 69 | + env: |
| 70 | + PKR_VAR_os_version: ${{ matrix.os_version }} |
| 71 | + |
| 72 | + - name: Get created image names from manifest |
| 73 | + id: manifest |
| 74 | + run: | |
| 75 | + . venv/bin/activate |
| 76 | + IMAGE_ID=$(jq --raw-output '.builds[-1].artifact_id' packer/packer-manifest.json) |
| 77 | + while ! openstack image show -f value -c name $IMAGE_ID; do |
| 78 | + sleep 5 |
| 79 | + done |
| 80 | + IMAGE_NAME=$(openstack image show -f value -c name $IMAGE_ID) |
| 81 | + echo "image-name=${IMAGE_NAME}" >> "$GITHUB_OUTPUT" |
| 82 | + echo "image-id=$IMAGE_ID" >> "$GITHUB_OUTPUT" |
| 83 | +
|
| 84 | + - name: Download image |
| 85 | + run: | |
| 86 | + . venv/bin/activate |
| 87 | + sudo mkdir /mnt/images |
| 88 | + sudo chmod 777 /mnt/images |
| 89 | + openstack image save --file /mnt/images/${{ steps.manifest.outputs.image-name }}.qcow2 ${{ steps.manifest.outputs.image-name }} |
| 90 | +
|
| 91 | + - name: Set up QEMU |
| 92 | + uses: docker/setup-qemu-action@v3 |
| 93 | + |
| 94 | + - name: install libguestfs |
| 95 | + run: | |
| 96 | + sudo apt -y update |
| 97 | + sudo apt -y install libguestfs-tools |
| 98 | +
|
| 99 | + - name: mkdir for mount |
| 100 | + run: sudo mkdir -p './${{ steps.manifest.outputs.image-name }}' |
| 101 | + |
| 102 | + - name: mount qcow2 file |
| 103 | + run: sudo guestmount -a /mnt/images/${{ steps.manifest.outputs.image-name }}.qcow2 -i --ro -o allow_other './${{ steps.manifest.outputs.image-name }}' |
| 104 | + |
| 105 | + - name: Run Trivy vulnerability scanner |
| 106 | + uses: aquasecurity/[email protected] |
| 107 | + with: |
| 108 | + scan-type: fs |
| 109 | + scan-ref: "${{ steps.manifest.outputs.image-name }}" |
| 110 | + scanners: "vuln" |
| 111 | + format: sarif |
| 112 | + output: "${{ steps.manifest.outputs.image-name }}.sarif" |
| 113 | + # turn off secret scanning to speed things up |
| 114 | + |
| 115 | + - name: Upload Trivy scan results to GitHub Security tab |
| 116 | + uses: github/codeql-action/upload-sarif@v3 |
| 117 | + with: |
| 118 | + sarif_file: "${{ steps.manifest.outputs.image-name }}.sarif" |
| 119 | + category: "${{ matrix.os_version }}-${{ matrix.build }}" |
| 120 | + |
| 121 | + - name: Fail if scan has CRITICAL vulnerabilities |
| 122 | + uses: aquasecurity/[email protected] |
| 123 | + with: |
| 124 | + scan-type: fs |
| 125 | + scan-ref: "${{ steps.manifest.outputs.image-name }}" |
| 126 | + scanners: "vuln" |
| 127 | + format: table |
| 128 | + exit-code: '1' |
| 129 | + severity: 'CRITICAL' |
| 130 | + ignore-unfixed: true |
0 commit comments