Update and Build Nautobot Lab Container #192
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: Update and Build Nautobot Lab Container | |
on: # yamllint disable-line rule:truthy | |
workflow_dispatch: # yamllint disable-line rule:truthy | |
schedule: | |
- cron: "0 0 * * *" | |
env: | |
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | |
HUB_URL: "https://hub.docker.com/v2/repositories/networktocode/nautobot-lab" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Get latest Nautobot release | |
id: get_nautobot_release | |
run: | | |
latest_release=$(curl -s \ | |
https://api.github.com/repos/nautobot/nautobot/releases/latest \ | |
| jq -r '.tag_name' | cut -c 2-) | |
echo "Latest Nautobot Release: $latest_release" | |
echo "nautobot_release=$latest_release" >> "$GITHUB_ENV" | |
- name: Get Nautobot Lab image tag | |
id: get_nautobot_lab_tag | |
run: | | |
release="${{ env.nautobot_release }}" | |
latest_digest=$(curl -s "$HUB_URL/tags/" \ | |
| jq -r '.results[] | select(.name == "latest") | .images[0].digest') | |
tag_digest=$(curl -s "$HUB_URL/tags/" \ | |
| jq -r --arg var "$release" \ | |
'.results[] | select(.name == $var) | .images[0].digest') | |
if [ "$tag_digest" == "$latest_digest" ]; then | |
echo "Setting nautobot_lab_tag to $release" | |
echo "nautobot_lab_tag=$release" >> "$GITHUB_ENV" | |
break | |
else | |
echo "A container with $relase does not exist." | |
exit 0 | |
fi | |
- name: Compare versions and set environment variable | |
id: compare_versions | |
run: | | |
nautobot_release="${{ env.nautobot_release }}" | |
nautobot_lab_tag="${{ env.nautobot_lab_tag }}" | |
if [[ "$nautobot_release" == "$nautobot_lab_tag" ]]; then | |
echo "Nautobot and Nautobot Lab versions match." | |
exit 0 | |
else | |
echo "Setting NAUTOBOT_VERSION to $nautobot_release" | |
echo "NAUTOBOT_VERSION=$nautobot_release" >> "$GITHUB_ENV" | |
fi | |
- name: Build and push Nautobot Lab images | |
env: | |
NAUTOBOT_VERSION: ${{ env.NAUTOBOT_VERSION }} | |
run: | | |
if [[ -z "${NAUTOBOT_VERSION}" ]]; then | |
echo "Nautobot Lab is up to date." | |
exit 0 | |
else | |
echo "Building nautobot-lab:$NAUTOBOT_VERSION" | |
docker build \ | |
--build-arg NAUTOBOT_VERSION=${NAUTOBOT_VERSION} \ | |
-t networktocode/nautobot-lab:${NAUTOBOT_VERSION} . | |
echo "Building nautobot-lab:latest with $NAUTOBOT_VERSION" | |
docker build -t networktocode/nautobot-lab:latest . | |
echo "Logging into Docker Hub" | |
echo $DOCKERHUB_TOKEN \ | |
| docker login \ | |
--username $DOCKERHUB_USERNAME \ | |
--password-stdin | |
echo "Pushing nautobot-lab:${NAUTOBOT_VERSION} to Docker Hub" | |
docker push networktocode/nautobot-lab:${NAUTOBOT_VERSION} | |
echo "Pushing nautobot-lab:latest to Docker Hub" | |
docker push networktocode/nautobot-lab:latest | |
fi |