Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.

Commit 00eccea

Browse files
authored
Build qemu images using GH Actions (#195)
1 parent df47d1b commit 00eccea

File tree

1 file changed

+5
-83
lines changed

1 file changed

+5
-83
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,13 @@ env:
1313
VAGRANT_CLOUD_TOKEN: ${{ secrets.VAGRANT_CLOUD_TOKEN }}
1414
# Needed for Packer when calling ansible (https://github.com/ansible/ansible/issues/32499)
1515
OBJC_DISABLE_INITIALIZE_FORK_SAFETY: YES
16+
ACCELERATOR: hvf
1617

1718
jobs:
18-
19-
##############
20-
# libvirt
21-
##############
22-
23-
build-libvirt:
19+
build-boxes:
2420
name: "*"
25-
runs-on: [self-hosted, linux, x64]
21+
runs-on: macos-latest
2622
strategy:
27-
max-parallel: 1
2823
fail-fast: false
2924
matrix:
3025
stage:
@@ -39,77 +34,6 @@ jobs:
3934
- windows-server-2012_r2-standard-x64-eval-libvirt
4035
- windows-server-2016-standard-x64-eval-libvirt
4136
- windows-server-2019-standard-x64-eval-libvirt
42-
43-
steps:
44-
- name: Skip image build if it already exists in Vagrant Cloud
45-
run: |
46-
BUILD="${{ matrix.stage }}"
47-
PACKER_VAGRANT_PROVIDER="${BUILD##*-}"
48-
NAME="${BUILD%-*}"
49-
50-
# Check if the boxes (virtualbox/libvirt) with the same git hash already exists
51-
CURRENT_VERSION_DESCRIPTION_MARKDOWN="$(curl -L --silent "https://app.vagrantup.com/api/v1/box/${VAGRANT_CLOUD_USER}/${NAME}" | jq '.current_version.version as $current_version | .versions[] | select (.version == $current_version) .description_markdown')"
52-
if [[ "${CURRENT_VERSION_DESCRIPTION_MARKDOWN}" =~ ${GITHUB_SHA} ]]; then
53-
echo "*** Git hash \"${GITHUB_SHA}\" found in current markdown description: https://app.vagrantup.com/${VAGRANT_CLOUD_USER}/boxes/${NAME}/"
54-
# Skip build if the box already exists
55-
CURRENT_VERSION_PROVIDER_URL="$(curl -L --silent "https://app.vagrantup.com/api/v1/box/${VAGRANT_CLOUD_USER}/${NAME}" | jq -r ".current_version.version as \$current_version | .versions[] | select (.version == \$current_version) .providers[] | select (.name == \"${PACKER_VAGRANT_PROVIDER}\") .download_url")"
56-
if [ -n "${CURRENT_VERSION_PROVIDER_URL}" ]; then
57-
echo "*** Found already build image \"${BUILD}\" with hash \"${GITHUB_SHA}\": ${CURRENT_VERSION_PROVIDER_URL}"
58-
echo "*** This build will be skipped..."
59-
echo "::set-env name=skip::true"
60-
else
61-
# Set BOX_VERSION variable from existing provider (if exists) or from "date"
62-
BOX_VERSION="$(curl -L --silent "https://app.vagrantup.com/api/v1/box/${VAGRANT_CLOUD_USER}/${NAME}" | jq -r ".current_version.version")"
63-
echo "*** Using previously defined box version \"${BOX_VERSION}\", because there is already builded box with git hash \"${GITHUB_SHA}\""
64-
fi
65-
else
66-
BOX_VERSION="$(date +%Y%m%d).01"
67-
echo "*** Using new box version based on current date: ${BOX_VERSION}"
68-
fi
69-
echo "::set-env name=BOX_VERSION::${BOX_VERSION}"
70-
71-
- uses: actions/checkout@v2
72-
if: env.skip != 'true'
73-
with:
74-
submodules: true
75-
76-
- name: Build image - ${{ matrix.stage }}
77-
if: env.skip != 'true'
78-
run: |
79-
test -d "${PACKER_CACHE_DIR}" || mkdir -v "${PACKER_CACHE_DIR}"
80-
ln -sv "${PACKER_CACHE_DIR}" packer_cache
81-
./build.sh "${{ matrix.stage }}"
82-
83-
- name: Check the created box image - ${{ matrix.stage }}
84-
if: env.skip != 'true'
85-
run: |
86-
./vagrant_init_destroy_boxes.sh "${PACKER_IMAGES_OUTPUT_DIR}/${{ matrix.stage }}.box"
87-
88-
- name: Upload box to Vagrant Cloud - ${{ matrix.stage }}
89-
env:
90-
BOX_VERSION: ${{ env.BOX_VERSION }}
91-
if: env.skip != 'true' && ( github.event_name == 'schedule' || ( github.event_name == 'repository_dispatch' && github.event.action == 'build_release_upload' ) )
92-
run: |
93-
./upload_box_to_vagrantcloud.sh "${VAGRANT_CLOUD_USER}@${PACKER_IMAGES_OUTPUT_DIR}/${{ matrix.stage }}.box"
94-
95-
- name: Build log cleanup - ${{ matrix.stage }}
96-
if: env.skip != 'true' && ( github.event_name == 'schedule' || ( github.event_name == 'repository_dispatch' && github.event.action == 'build_release_upload' ) )
97-
run: |
98-
rm -v "${LOGDIR}/${{ matrix.stage }}-packer.log"
99-
rm -v "${LOGDIR}/${{ matrix.stage }}-init.log"
100-
rm -v "${PACKER_IMAGES_OUTPUT_DIR}/${{ matrix.stage }}.box"
101-
102-
##############
103-
# VirtualBox
104-
##############
105-
106-
build-virtualbox:
107-
name: "*"
108-
runs-on: macos-latest
109-
strategy:
110-
fail-fast: false
111-
matrix:
112-
stage:
11337
- my_ubuntu-20.04-server-amd64-virtualbox
11438
- my_windows-10-enterprise-x64-eval-virtualbox
11539
- ubuntu-16.04-server-amd64-virtualbox
@@ -160,25 +84,23 @@ jobs:
16084
run: |
16185
brew install ansible bash coreutils gnu-sed qemu
16286
pip3 install pywinrm
87+
echo "::add-path::/usr/local/bin:/usr/local/opt/gnu-sed/libexec/gnubin:/usr/local/opt/coreutils/libexec/gnubin:${PATH}"
16388
16489
- name: Build image - ${{ matrix.stage }}
16590
if: env.skip != 'true'
16691
run: |
167-
export PATH="/usr/local/bin:/usr/local/opt/gnu-sed/libexec/gnubin:/usr/local/opt/coreutils/libexec/gnubin:${PATH}"
16892
./build.sh ${{ matrix.stage }}
16993
17094
- name: Check the created box image - ${{ matrix.stage }}
171-
if: env.skip != 'true'
95+
if: env.skip != 'true' && contains( matrix.stage, 'virtualbox' )
17296
run: |
173-
export PATH="/usr/local/bin:/usr/local/opt/gnu-sed/libexec/gnubin:/usr/local/opt/coreutils/libexec/gnubin:${PATH}"
17497
./vagrant_init_destroy_boxes.sh "${PACKER_IMAGES_OUTPUT_DIR}/${{ matrix.stage }}.box"
17598
17699
- name: Upload box to Vagrant Cloud - ${{ matrix.stage }}
177100
if: env.skip != 'true' && ( github.event_name == 'schedule' || ( github.event_name == 'repository_dispatch' && github.event.action == 'build_release_upload' ) )
178101
env:
179102
BOX_VERSION: ${{ env.BOX_VERSION }}
180103
run: |
181-
export PATH="/usr/local/bin:/usr/local/opt/gnu-sed/libexec/gnubin:/usr/local/opt/coreutils/libexec/gnubin:${PATH}"
182104
./upload_box_to_vagrantcloud.sh "${VAGRANT_CLOUD_USER}@${PACKER_IMAGES_OUTPUT_DIR}/${{ matrix.stage }}.box"
183105
184106
cleanup:

0 commit comments

Comments
 (0)