Skip to content
This repository has been archived by the owner on Dec 3, 2021. It is now read-only.

Commit

Permalink
Adding image build support to the preview system
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Oswalt <[email protected]>
  • Loading branch information
Mierdin committed Mar 19, 2021
1 parent 8023e43 commit 7406a5b
Show file tree
Hide file tree
Showing 23 changed files with 143 additions and 19 deletions.
37 changes: 32 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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() }}

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 3 additions & 10 deletions request-preview.sh → create-preview.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/")

Expand All @@ -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
5 changes: 4 additions & 1 deletion images/ansible/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 3 additions & 0 deletions images/ansible/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# https://github.com/Azure/azure-cli/issues/16858
cryptography==3.3.2

ansible==2.9.2
ncclient
4 changes: 4 additions & 0 deletions images/asterisk/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
File renamed without changes.
7 changes: 7 additions & 0 deletions images/crpd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 5 additions & 0 deletions images/cvx/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

File renamed without changes.
5 changes: 5 additions & 0 deletions images/gitea/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions images/gnmic/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions images/pjsua-lindsey/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions images/salt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions images/stackstorm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions images/terraform/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions images/utility/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 3 additions & 3 deletions images/utility/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions start-preview.sh
Original file line number Diff line number Diff line change
@@ -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\"
}"

36 changes: 36 additions & 0 deletions wait-for-status.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7406a5b

Please sign in to comment.