Build NS8 disk images #1638
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build NS8 disk images | |
on: | |
workflow_run: | |
workflows: [core] | |
types: | |
- completed | |
workflow_dispatch: | |
jobs: | |
core-version: | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
runs-on: ubuntu-latest | |
outputs: | |
is_stable: ${{ steps.check.outputs.is_stable }} | |
steps: | |
- id: python-dep | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.9 | |
- id: check | |
run: | | |
pip install semver | |
check_core_version=$(cat <<EOF | |
import semver, sys | |
try: | |
print("false") if semver.VersionInfo.parse("${{ github.event.workflow_run.head_branch }}").prerelease else print ("true") | |
except ValueError: print("false") | |
EOF | |
) | |
echo is_stable=$(python3 -c "$check_core_version") >> $GITHUB_OUTPUT | |
build-images-qemu: | |
runs-on: [self-hosted] | |
permissions: | |
contents: write | |
strategy: | |
fail-fast: false | |
matrix: | |
source: | |
- qemu.rl | |
needs: | |
- core-version | |
if: needs.core-version.outputs.is_stable == 'true' | |
steps: | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
- name: Setup s3cmd | |
run: | | |
pip install s3cmd | |
s3cmd --version | |
- name: Setup `packer` | |
uses: hashicorp/setup-packer@main | |
- uses: actions/checkout@v4 | |
with: | |
repository: NethServer/ns8-images | |
- name: Run `packer init` | |
id: init | |
run: packer init . | |
- name: Run `packer build` | |
id: validate | |
run: packer build --only=${{ matrix.source }} . | |
- id: qcow2 | |
run: | | |
IMAGE_PATH=$(cat packer-manifest.json | jq -r .builds[0].files[0].name) | |
echo "path=${IMAGE_PATH}" >> "$GITHUB_OUTPUT" | |
- id: vmdk | |
name: Convert to VMDK | |
run: | | |
VMDK_PATH=$(echo ${{ steps.qcow2.outputs.path }} | sed -e 's/\.qcow2$/\.vmdk/') | |
qemu-img convert -f qcow2 -O vmdk ${{ steps.qcow2.outputs.path }} $VMDK_PATH | |
echo "path=${VMDK_PATH}" >> "$GITHUB_OUTPUT" | |
- id: checksum | |
name: Create checksum | |
run: | | |
cd $(dirname ${{ steps.qcow2.outputs.path }}) | |
sha256sum $(basename ${{ steps.qcow2.outputs.path }}) > ../CHECKSUM | |
sha256sum $(basename ${{ steps.vmdk.outputs.path }}) >> ../CHECKSUM | |
- name: Upload images | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.DO_SPACE_ACCESS_KEY }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.DO_SPACE_SECRET_KEY }} | |
run: > | |
s3cmd put | |
--host=ams3.digitaloceanspaces.com | |
--host-bucket=ns8.ams3.digitaloceanspaces.com | |
--verbose | |
--progress | |
--acl-public | |
--guess-mime-type | |
${{ steps.qcow2.outputs.path }} | |
${{ steps.vmdk.outputs.path }} | |
CHECKSUM | |
s3://ns8/ns8-images/ |