diff --git a/.ci/spec/clean-packet.sh b/.ci/spec/clean-packet.sh new file mode 100755 index 000000000..66a40c69c --- /dev/null +++ b/.ci/spec/clean-packet.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +csource="${BASH_SOURCE[0]}" +while [ -h "$csource" ] ; do csource="$(readlink "$csource")"; done +root="$( cd -P "$( dirname "$csource" )/../../" && pwd )" + +. "${root}/.ci/spec/env.sh" +. "${root}/.ci/common.sh" + +pushd "${root}" > "${output}" + +echo "Cleaning up packet device..." + +export PKT_VAGRANT_HOST_BOXES="${VAGRANT_HOST_BOXES}" +export PKT_VAGRANT_GUEST_BOXES="${VAGRANT_GUEST_BOXES}" +export PKT_VAGRANT_CWD="test/vagrant-spec/" +export PKT_VAGRANT_VAGRANTFILE=Vagrantfile.spec +pkt_wrap_stream "vagrant destroy -f" \ + "Vagrant failed to destroy remaining vagrant-spec guests during clean up" + + +echo "Finished destroying spec test hosts" diff --git a/.ci/spec/create-hosts.sh b/.ci/spec/create-hosts.sh new file mode 100755 index 000000000..480cfab7c --- /dev/null +++ b/.ci/spec/create-hosts.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +csource="${BASH_SOURCE[0]}" +while [ -h "$csource" ] ; do csource="$(readlink "$csource")"; done +root="$( cd -P "$( dirname "$csource" )/../../" && pwd )" + +. "${root}/.ci/spec/env.sh" +. "${root}/.ci/common.sh" + +pushd "${root}" > "${output}" + +# Assumes packet is already set up + +# job_id is provided by common.sh +export PACKET_EXEC_REMOTE_DIRECTORY="${job_id}" + +# spec test configuration, defined by action runners, used by Vagrant on packet +export PKT_VAGRANT_HOST_BOXES="${VAGRANT_HOST_BOXES}" +export PKT_VAGRANT_GUEST_BOXES="${VAGRANT_GUEST_BOXES}" +# other vagrant-spec options +export PKT_VAGRANT_HOST_MEMORY="${VAGRANT_HOST_MEMORY:-10000}" +export PKT_VAGRANT_CWD="test/vagrant-spec/" +export PKT_VAGRANT_VAGRANTFILE=Vagrantfile.spec +### + +# Grab vagrant-spec gem and place inside root dir of Vagrant repo +download_assets "${ASSETS_PRIVATE_BUCKET}/vagrant-spec/vagrant-spec.gem" "." +### + +# Run the job + +echo "Creating vagrant spec guests..." +wrap_stream packet-exec run -upload -- "vagrant up --no-provision --provider vmware_desktop" \ + "Vagrant Blackbox host creation command failed" + + +echo "Finished bringing up vagrant spec guests" diff --git a/.ci/spec/create-packet.sh b/.ci/spec/create-packet.sh new file mode 100755 index 000000000..885b4a9b7 --- /dev/null +++ b/.ci/spec/create-packet.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +csource="${BASH_SOURCE[0]}" +while [ -h "$csource" ] ; do csource="$(readlink "$csource")"; done +root="$( cd -P "$( dirname "$csource" )/../../" && pwd )" + +. "${root}/.ci/spec/env.sh" +. "${root}/.ci/common.sh" + +pushd "${root}" > "${output}" + +# Ensure we have a packet device to connect +echo "Creating packet device if needed..." + +packet-exec info + +if [ $? -ne 0 ]; then + wrap_stream packet-exec create \ + "Failed to create packet device" +fi + +echo "Finished creating spec test packet instance" diff --git a/.ci/spec/env.sh b/.ci/spec/env.sh new file mode 100755 index 000000000..48d58dfa5 --- /dev/null +++ b/.ci/spec/env.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# packet and job configuration +export SLACK_USERNAME="Vagrant" +export SLACK_ICON="https://media.giphy.com/media/yIQ5glQeheYE0/200.gif" +export SLACK_TITLE="Vagrant-Spec Test Runner" +export PACKET_EXEC_DEVICE_NAME="${PACKET_EXEC_DEVICE_NAME:-spec-ci-boxes}" +export PACKET_EXEC_DEVICE_SIZE="${PACKET_EXEC_DEVICE_SIZE:-baremetal_0,baremetal_1,baremetal_1e}" +export PACKET_EXEC_PREFER_FACILITIES="${PACKET_EXEC_PREFER_FACILITIES:-iad1,iad2,ewr1,dfw1,dfw2,sea1,sjc1,lax1}" +export PACKET_EXEC_OPERATING_SYSTEM="${PACKET_EXEC_OPERATING_SYSTEM:-ubuntu_18_04}" +export PACKET_EXEC_PRE_BUILTINS="${PACKET_EXEC_PRE_BUILTINS:-InstallVagrant,InstallVirtualBox,InstallVmware,InstallHashiCorpTool,InstallVagrantVmware}" +export PACKET_EXEC_QUIET="1" +export PKT_VAGRANT_CLOUD_TOKEN="${VAGRANT_CLOUD_TOKEN}" +### diff --git a/.ci/spec/run-test.sh b/.ci/spec/run-test.sh new file mode 100755 index 000000000..f41d3a4e0 --- /dev/null +++ b/.ci/spec/run-test.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +csource="${BASH_SOURCE[0]}" +while [ -h "$csource" ] ; do csource="$(readlink "$csource")"; done +root="$( cd -P "$( dirname "$csource" )/../../" && pwd )" + +. "${root}/.ci/spec/env.sh" +. "${root}/.ci/common.sh" + +pushd "${root}" > "${output}" + +# Assumes packet is already set up + +# job_id is provided by common.sh +export PACKET_EXEC_REMOTE_DIRECTORY="${job_id}" + +# spec test configuration, defined by action runners, used by Vagrant on packet +export PKT_VAGRANT_HOST_BOXES="${VAGRANT_HOST_BOXES}" +export PKT_VAGRANT_GUEST_BOXES="${VAGRANT_GUEST_BOXES}" +# other vagrant-spec options +export PKT_VAGRANT_HOST_MEMORY=10000 +export PKT_VAGRANT_CWD="test/vagrant-spec/" +export PKT_VAGRANT_VAGRANTFILE=Vagrantfile.spec +### + +# Run the job + +echo "Running vagrant spec tests..." +# Need to make memory customizable for windows hosts +pkt_wrap_stream "vagrant provision --provider vmware_desktop" \ + "Vagrant Blackbox testing command failed" + + +echo "Finished vagrant spec tests" diff --git a/.ci/sync.sh b/.ci/sync.sh new file mode 100755 index 000000000..3f39af7ed --- /dev/null +++ b/.ci/sync.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +csource="${BASH_SOURCE[0]}" +while [ -h "$csource" ] ; do csource="$(readlink "$csource")"; done +root="$( cd -P "$( dirname "$csource" )/../../" && pwd )" + +. "${root}/.ci/common.sh" + +export PATH="${PATH}:${root}/.ci" + +pushd "${root}" > "${output}" + +if [ "${repo_name}" = "vagrant" ]; then + remote_repository="hashicorp/vagrant-blackbox" +else + fail "This repository is not configured to sync vagrant to mirror repository" +fi + +echo "Adding remote mirror repository '${remote_repository}'..." +wrap git remote add mirror "https://${HASHIBOT_USERNAME}:${HASHIBOT_TOKEN}@github.com/${remote_repository}" \ + "Failed to add mirror '${remote_repository}' for sync" + +echo "Updating configured remotes..." +wrap_stream git remote update mirror \ + "Failed to update mirror repository (${remote_repository}) for sync" + +rb=$(git branch -r --list "mirror/${ident_ref}") + +if [ "${rb}" != "" ]; then + echo "Pulling ${ident_ref} from mirror..." + wrap_stream git pull mirror "${ident_ref}" \ + "Failed to pull ${ident_ref} from mirror repository (${remote_repository}) for sync" +fi + +echo "Pushing ${ident_ref} to mirror..." +wrap_stream git push mirror "${ident_ref}" \ + "Failed to sync mirror repository (${remote_repository})" diff --git a/.github/workflows/code.yml b/.github/workflows/code.yml new file mode 100644 index 000000000..c9d332767 --- /dev/null +++ b/.github/workflows/code.yml @@ -0,0 +1,27 @@ +on: + push: + branches: + - 'master' + - 'spec-test-*' + +jobs: + sync-blackbox: + if: github.repository == 'hashicorp/vagrant' + runs-on: ubuntu-18.04 + steps: + - name: Code Checkout + uses: actions/checkout@v2 + with: + persist-credentials: false + fetch-depth: 0 + - name: Set Ruby + uses: actions/setup-ruby@v1 + with: + ruby-version: '2.6' + - name: Sync Blackbox Testing Repository + run: ./.ci/sync.sh + working-directory: ${{github.workspace}} + env: + HASHIBOT_TOKEN: ${{ secrets.HASHIBOT_TOKEN }} + HASHIBOT_USERNAME: ${{ secrets.HASHIBOT_USERNAME }} + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} diff --git a/.github/workflows/spectesting.yml b/.github/workflows/spectesting.yml new file mode 100644 index 000000000..93f433fad --- /dev/null +++ b/.github/workflows/spectesting.yml @@ -0,0 +1,66 @@ +on: + push: + branches: + - 'spec-test-*' + paths-ignore: + - 'CHANGELOG.md' + - 'website/**' + +jobs: + setup-packet: + if: github.repository == 'hashicorp/vagrant-blackbox' + runs-on: self-hosted + name: Build Packet Instance + steps: + - name: Create packet instance + run: .ci/spec/create-packet.sh + working-directory: ${{github.workspace}} + + setup-hosts: + if: github.repository == 'hashicorp/vagrant-blackbox' + runs-on: self-hosted + name: Vagrant-Spec Start Hosts + needs: setup-packet + strategy: + matrix: + host_os: ['hashicorp/bionic64'] + guest_os: ['hashicorp-vagrant/ubuntu-16.04'] + steps: + - name: Code Checkout + uses: actions/checkout@v1 + - name: Create packet host for tests + run: .ci/spec/create-hosts.sh + working-directory: ${{github.workspace}} + env: + VAGRANT_HOST_BOXES: ${{matrix.host_os}} + VAGRANT_GUEST_BOXES: ${{matrix.guest_os}} + + spec-tests: + if: github.repository == 'hashicorp/vagrant-blackbox' + runs-on: self-hosted + name: Vagrant-Spec Tests + needs: setup-hosts + strategy: + matrix: + host_os: ['hashicorp/bionic64'] + guest_os: ['hashicorp-vagrant/ubuntu-16.04'] + steps: + - name: Run Tests with host ${{ matrix.host_os }} using guest ${{ matrix.guest_os }} + run: .ci/spec/run-test.sh + working-directory: ${{github.workspace}} + env: + VAGRANT_HOST_BOXES: ${{matrix.host_os}} + VAGRANT_GUEST_BOXES: ${{matrix.guest_os}} + + cleanup: + if: github.repository == 'hashicorp/vagrant-blackbox' + runs-on: self-hosted + name: Cleanup Post Vagrant-Spec Tests + needs: spec-tests + steps: + - name: Clean Packet + if: always() + run: .ci/spec/clean-packet.sh + - name: Clean Workspace + if: always() + run: rm -rf ${{ github.workspace }}