diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f644c721..6cdc6f10 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,14 +1,11 @@ name: CI on: - push: - branches: [ master ] pull_request: branches: [ master ] jobs: build: runs-on: ubuntu-latest - steps: - uses: actions/checkout@v2 @@ -31,7 +28,37 @@ jobs: run: ./check-changelog.sh if: ${{ success() }} + - name: Create Preview + id: create_preview + run: | + echo ::set-output name=preview_id::$(./create-preview.sh | jq -r '.ID') + if: ${{ success() }} + + - name: Get PR number + id: get_pr_number + run: | + echo ::set-output name=pr_number::$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH") + if: ${{ success() }} + + - name: Build Preview Images + id: build_preview_images + run: | + curl -k -X POST https://abathur.nrelabs.io/api/v1/webhooks/preview_images_build -H "St2-Api-Key: $PREVIEWER_APIK" -H "Content-Type: application/json" \ + --data "{\"preview_id\": \"$PREVIEW_ID\", \"pr_number\": \"$PREVIEW_PR_NUMBER\", \"status_commit_id\": \"$PREVIEW_STATUS_COMMIT\", \"github_token\": \"$GH_TOKEN\"}" + env: + PREVIEW_ID: ${{ steps.create_preview.outputs.preview_id }} + PREVIEW_STATUS_COMMIT: ${{ github.event.pull_request.head.sha }} + PREVIEW_PR_NUMBER: ${{ steps.get_pr_number.outputs.pr_number }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # Locked down account which can only invoke preview webhook + PREVIEWER_APIK: MjE0ZTlkYWZjMDg1OTNkOWJkMjQxZDA0Mzk0NzIzNDI1MTc2Nzk0NDVkMjk0MGE5NTNhODkxOTNiMzVmNWM5Mg + if: ${{ success() }} + + - name: Wait for status + run: ./wait-for-status.sh ${{ github.event.pull_request.head.sha }} + if: ${{ success() }} + - name: Request preview - run: ./request-preview.sh + run: ./start-preview.sh ${{ steps.create_preview.outputs.preview_id }} if: ${{ success() }} - diff --git a/CHANGELOG.md b/CHANGELOG.md index 7daa4637..b192c77b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## In development +- Adding image build to preview pipeline [#352](https://github.com/nre-learning/nrelabs-curriculum/pull/352) ## v1.3.0 - December 13, 2020 diff --git a/request-preview.sh b/create-preview.sh similarity index 67% rename from request-preview.sh rename to create-preview.sh index 44f89664..3f2db2d1 100755 --- a/request-preview.sh +++ b/create-preview.sh @@ -2,10 +2,7 @@ set -e +o pipefail -url="https://preview.nrelabs.io/webhook" - -echo "ENV TO FOLLOW" -echo $(env) +url="https://preview.nrelabs.io/create" PR_ID=$(echo $GITHUB_REF | sed "s/refs\/pull\/\(.*\)\/merge/\1/") @@ -15,16 +12,12 @@ then exit 0 fi -echo "Requesting preview...." - -curl $url --header "Content-Type: application/json" \ +echo $(curl -s $url --header "Content-Type: application/json" \ --data "{ \"branch\":\"$GITHUB_HEAD_REF\", \"pullRequest\":\"$PR_ID\", \"repoSlug\":\"$GITHUB_REPOSITORY\", \"prSha\":\"$GITHUB_SHA\" - }" - -echo "DONE!" + }") exit 0 diff --git a/images/ansible/Makefile b/images/ansible/Makefile index f4df11ec..9b0b028d 100644 --- a/images/ansible/Makefile +++ b/images/ansible/Makefile @@ -6,5 +6,8 @@ all: docker docker: docker build --pull --no-cache -t antidotelabs/ansible:$(TARGET_VERSION) . - # docker build --pull -t antidotelabs/ansible:$(TARGET_VERSION) . + docker push antidotelabs/ansible:$(TARGET_VERSION) + +dockerfast: + docker build --pull -t antidotelabs/ansible:$(TARGET_VERSION) . docker push antidotelabs/ansible:$(TARGET_VERSION) diff --git a/images/ansible/requirements.txt b/images/ansible/requirements.txt index fe756283..f2127b94 100644 --- a/images/ansible/requirements.txt +++ b/images/ansible/requirements.txt @@ -1,2 +1,5 @@ +# https://github.com/Azure/azure-cli/issues/16858 +cryptography==3.3.2 + ansible==2.9.2 ncclient diff --git a/images/asterisk/Makefile b/images/asterisk/Makefile index a214d8a6..beb5493a 100644 --- a/images/asterisk/Makefile +++ b/images/asterisk/Makefile @@ -7,3 +7,7 @@ all: docker docker: docker build --pull --no-cache -t antidotelabs/asterisk:$(TARGET_VERSION) . docker push antidotelabs/asterisk:$(TARGET_VERSION) + +dockerfast: + docker build --pull -t antidotelabs/asterisk:$(TARGET_VERSION) . + docker push antidotelabs/asterisk:$(TARGET_VERSION) diff --git a/images/container-vqfx/Makefile b/images/container-vqfx/Makefile-disabled similarity index 100% rename from images/container-vqfx/Makefile rename to images/container-vqfx/Makefile-disabled diff --git a/images/crpd/Makefile b/images/crpd/Makefile index fe155f8a..445095de 100644 --- a/images/crpd/Makefile +++ b/images/crpd/Makefile @@ -10,3 +10,10 @@ docker: docker build --no-cache -t antidotelabs/crpd:$(TARGET_VERSION) . docker push antidotelabs/crpd:$(TARGET_VERSION) + +dockerfast: + gsutil cp "gs://nrelabs-curriculum-base-images/crpd/junos-routing-crpd-docker-20.2R1.10.tgz" "./crpd.tgz" + docker load -i crpd.tgz + + docker build -t antidotelabs/crpd:$(TARGET_VERSION) . + docker push antidotelabs/crpd:$(TARGET_VERSION) diff --git a/images/cvx/Makefile b/images/cvx/Makefile index 62169e6d..33b1b092 100644 --- a/images/cvx/Makefile +++ b/images/cvx/Makefile @@ -9,3 +9,8 @@ docker: docker build --pull --no-cache -t antidotelabs/cvx:$(TARGET_VERSION) . docker push antidotelabs/cvx:$(TARGET_VERSION) +dockerfast: + gsutil cp "gs://nrelabs-curriculum-base-images/cvx-3.7.8/cvx-3.7.8.qcow2" "./cvx.qcow2" + docker build --pull -t antidotelabs/cvx:$(TARGET_VERSION) . + docker push antidotelabs/cvx:$(TARGET_VERSION) + diff --git a/images/frr/Makefile b/images/frr/Makefile-disabled similarity index 100% rename from images/frr/Makefile rename to images/frr/Makefile-disabled diff --git a/images/gitea/Makefile b/images/gitea/Makefile index 8cd2c422..8e01b9a4 100644 --- a/images/gitea/Makefile +++ b/images/gitea/Makefile @@ -8,3 +8,8 @@ docker: docker build --pull --no-cache -t antidotelabs/gitea:$(TARGET_VERSION) . docker push antidotelabs/gitea:$(TARGET_VERSION) + +dockerfast: + + docker build --pull -t antidotelabs/gitea:$(TARGET_VERSION) . + docker push antidotelabs/gitea:$(TARGET_VERSION) diff --git a/images/gnmic/Makefile b/images/gnmic/Makefile index 6d35b6ed..2ca8b7a1 100644 --- a/images/gnmic/Makefile +++ b/images/gnmic/Makefile @@ -7,3 +7,7 @@ all: docker docker: docker build --pull --no-cache -t antidotelabs/gnmic:$(TARGET_VERSION) . docker push antidotelabs/gnmic:$(TARGET_VERSION) + +dockerfast: + docker build --pull -t antidotelabs/gnmic:$(TARGET_VERSION) . + docker push antidotelabs/gnmic:$(TARGET_VERSION) diff --git a/images/pjsua-lindsey/Makefile b/images/pjsua-lindsey/Makefile index 37102081..d59fad70 100644 --- a/images/pjsua-lindsey/Makefile +++ b/images/pjsua-lindsey/Makefile @@ -7,3 +7,7 @@ all: docker docker: docker build --pull --no-cache -t antidotelabs/pjsua-lindsey:$(TARGET_VERSION) . docker push antidotelabs/pjsua-lindsey:$(TARGET_VERSION) + +dockerfast: + docker build --pull -t antidotelabs/pjsua-lindsey:$(TARGET_VERSION) . + docker push antidotelabs/pjsua-lindsey:$(TARGET_VERSION) diff --git a/images/salt/Makefile b/images/salt/Makefile index 3d114c69..67a3c642 100644 --- a/images/salt/Makefile +++ b/images/salt/Makefile @@ -7,3 +7,7 @@ all: docker docker: docker build --pull --no-cache -t antidotelabs/salt:$(TARGET_VERSION) . docker push antidotelabs/salt:$(TARGET_VERSION) + +dockerfast: + docker build --pull -t antidotelabs/salt:$(TARGET_VERSION) . + docker push antidotelabs/salt:$(TARGET_VERSION) diff --git a/images/selfservice-flask-app/Makefile b/images/selfservice-flask-app/Makefile-disabled similarity index 100% rename from images/selfservice-flask-app/Makefile rename to images/selfservice-flask-app/Makefile-disabled diff --git a/images/stackstorm/Makefile b/images/stackstorm/Makefile index d4688ff3..74e72c44 100644 --- a/images/stackstorm/Makefile +++ b/images/stackstorm/Makefile @@ -7,3 +7,7 @@ all: docker docker: docker build --pull --no-cache -t antidotelabs/stackstorm:$(TARGET_VERSION) . docker push antidotelabs/stackstorm:$(TARGET_VERSION) + +dockerfast: + docker build --pull -t antidotelabs/stackstorm:$(TARGET_VERSION) . + docker push antidotelabs/stackstorm:$(TARGET_VERSION) diff --git a/images/terraform/Makefile b/images/terraform/Makefile index 15305a8f..f6ff6213 100644 --- a/images/terraform/Makefile +++ b/images/terraform/Makefile @@ -7,3 +7,7 @@ all: docker docker: docker build --pull --no-cache -t antidotelabs/terraform:$(TARGET_VERSION) . docker push antidotelabs/terraform:$(TARGET_VERSION) + +dockerfast: + docker build --pull -t antidotelabs/terraform:$(TARGET_VERSION) . + docker push antidotelabs/terraform:$(TARGET_VERSION) diff --git a/images/utility/Makefile b/images/utility/Makefile index 6b61e080..2c3b9517 100644 --- a/images/utility/Makefile +++ b/images/utility/Makefile @@ -7,3 +7,7 @@ all: docker docker: docker build --pull --no-cache -t antidotelabs/utility:$(TARGET_VERSION) . docker push antidotelabs/utility:$(TARGET_VERSION) + +dockerfast: + docker build --pull -t antidotelabs/utility:$(TARGET_VERSION) . + docker push antidotelabs/utility:$(TARGET_VERSION) diff --git a/images/utility/requirements.txt b/images/utility/requirements.txt index b2756c4b..675d5042 100644 --- a/images/utility/requirements.txt +++ b/images/utility/requirements.txt @@ -1,6 +1,6 @@ -# https://github.com/paramiko/paramiko/issues/1369 -# (I think this is fixed now, so commenting this out. I ran into issues with this restriction on) -# cryptography==2.4.2 +# https://github.com/Azure/azure-cli/issues/16858 +cryptography==3.3.2 + napalm netmiko jsnapy diff --git a/images/webserver/Makefile b/images/webserver/Makefile-disabled similarity index 100% rename from images/webserver/Makefile rename to images/webserver/Makefile-disabled diff --git a/images/wordpress/Makefile b/images/wordpress/Makefile-disabled similarity index 100% rename from images/wordpress/Makefile rename to images/wordpress/Makefile-disabled diff --git a/start-preview.sh b/start-preview.sh new file mode 100755 index 00000000..47202790 --- /dev/null +++ b/start-preview.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -e +o pipefail + +url="https://preview.nrelabs.io/start" + +if [ -z "$1" ] +then + echo "Must provide preview ID as parameter to this script" +fi + +curl -f -v -s $url --header "Content-Type: application/json" \ + --data "{ + \"previewID\":\"$1\" + }" + diff --git a/wait-for-status.sh b/wait-for-status.sh new file mode 100755 index 00000000..22c68b2d --- /dev/null +++ b/wait-for-status.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# set -e +o pipefail + +if [ -z "$1" ] +then + echo "Must provide status commit ID as parameter to this script" + exit 1 +fi + +for i in {1..120} +do + + # TODO - May want to consider checking for the status of the commit in general, which is always there - it's a key "state" + # at the top level of the returned object here, outside of the "statuses" array. + build_status=$(curl \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/nre-learning/nrelabs-curriculum/commits/$1/status | jq -r '.statuses[] | select(.context=="Building Endpoint Images").state') + + if [[ "$build_status" == "failure" ]] + then + echo "Status failed" + exit 1 + elif [[ "$build_status" == "success" ]] + then + echo "Status succeeded" + exit 0 + fi + + echo "Sleeping for 10 seconds..." + sleep 10 + +done + +echo "Timed out" +exit 1