-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,015 additions
and
69 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
--- | ||
name: "Configure Compose" | ||
description: "Configure Docker Compose for Nautobot App" | ||
inputs: | ||
db-backend: | ||
description: "Database Backend" | ||
required: false | ||
default: "" | ||
nautobot-version: | ||
description: "Nautobot Version" | ||
required: true | ||
python-version: | ||
description: "Python Version" | ||
required: true | ||
tag-prefix: | ||
description: "Docker Image Tag Prefix" | ||
required: true | ||
use-cache: | ||
description: "Use GitHub Actions Cache" | ||
required: false | ||
default: "false" | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: "Configure" | ||
id: "config" | ||
shell: "bash" | ||
run: | | ||
cd development | ||
cp creds.example.env creds.env | ||
GHCR_IMAGE_PREFIX="ghcr.io/${{ github.repository }}/nautobot-dev" | ||
GHCR_IMAGE_TAG="${{ inputs.tag-prefix }}-${{ inputs.nautobot-version }}-py${{ inputs.python-version }}" | ||
export COMPOSE_ANSI=0 | ||
COMPOSE_FILE="docker-compose.base.yml" | ||
if [[ -n "${{ inputs.db-backend }}" ]]; then | ||
COMPOSE_FILE="$COMPOSE_FILE:docker-compose.${{ inputs.db-backend }}.yml:docker-compose.redis.yml" | ||
fi | ||
export COMPOSE_FILE="$COMPOSE_FILE:docker-compose.dev.yml" | ||
export NAUTOBOT_VER="${{ inputs.nautobot-version }}" | ||
export PYTHON_VER="${{ inputs.python-version }}" | ||
COMPOSE_IMAGE="$(docker compose convert --format json | jq -r .services.nautobot.image)" | ||
echo "COMPOSE_FILE=$COMPOSE_FILE" | tee -a "$GITHUB_ENV" | ||
echo "NAUTOBOT_VER=$NAUTOBOT_VER" | tee -a "$GITHUB_ENV" | ||
echo "PYTHON_VER=$PYTHON_VER" | tee -a "$GITHUB_ENV" | ||
echo "compose-file=$COMPOSE_FILE" | tee -a "$GITHUB_OUTPUT" | ||
echo "compose-image=$COMPOSE_IMAGE" | tee -a "$GITHUB_OUTPUT" | ||
echo "ghcr-image=$GHCR_IMAGE_PREFIX:$GHCR_IMAGE_TAG" | tee -a "$GITHUB_OUTPUT" | ||
echo "ghcr-image-prefix=$GHCR_IMAGE_PREFIX" | tee -a "$GITHUB_OUTPUT" | ||
echo "ghcr-image-tag=$GHCR_IMAGE_TAG" | tee -a "$GITHUB_OUTPUT" | ||
if [[ -n "${{ inputs.db-backend }}" ]]; then | ||
DB_IMAGE="$(docker compose convert --format json | jq -r .services.db.image)" | ||
echo "db-image=$DB_IMAGE" | tee -a "$GITHUB_OUTPUT" | ||
fi | ||
- name: "Load Nautobot App Docker Image" | ||
id: "load" | ||
uses: "./.github/actions/docker-image" | ||
with: | ||
action: "${{ inputs.use-cache == 'true' && 'load-with-cache' || 'load' }}" | ||
image-prefix: "${{ steps.config.outputs.ghcr-image-prefix }}" | ||
image-tag: "${{ steps.config.outputs.ghcr-image-tag }}" | ||
nautobot-version: "${{ inputs.nautobot-version }}" | ||
python-version: "${{ inputs.python-version }}" | ||
- name: "Tag Nautobot App Docker Image" | ||
shell: "bash" | ||
run: | | ||
cd development | ||
docker tag "${{ steps.config.outputs.ghcr-image }}" "${{ steps.config.outputs.compose-image }}" | ||
- name: "Setup Database Services" | ||
if: | | ||
inputs.db-backend != '' | ||
id: "setup-db" | ||
shell: "bash" | ||
run: | | ||
cd development | ||
docker compose pull -- db redis | ||
docker compose up --detach -- db redis | ||
if [[ "${{ inputs.use-cache }}" == "true" ]]; then | ||
export NAUTOBOT_VERSION=$(docker image inspect --format '{{ index .Config.Labels "org.opencontainers.image.version" }}' '${{ steps.config.outputs.ghcr-image }}') | ||
CACHE_KEY="$(docker compose run --rm --entrypoint='' -- nautobot invoke calc-dbdump-cache-key --salt="$NAUTOBOT_VERSION-${{ steps.config.outputs.db-image }}")" | ||
echo "cache-key=db-dump-$CACHE_KEY" | tee -a "$GITHUB_OUTPUT" | ||
fi | ||
- name: "Cache Database Dump" | ||
if: | | ||
inputs.use-cache == 'true' && | ||
inputs.db-backend != '' | ||
id: "cache" | ||
uses: actions/cache@v3 | ||
with: | ||
path: "development/dump.sql" | ||
key: "${{ steps.setup-db.outputs.cache-key }}" | ||
restore-keys: "${{ steps.setup-db.outputs.cache-key }}" | ||
- name: "Use Cached Database Dump" | ||
if: | | ||
inputs.use-cache == 'true' && | ||
inputs.db-backend != '' && | ||
steps.cache.outputs.cache-hit == 'true' | ||
shell: "bash" | ||
run: | | ||
cd development | ||
docker compose exec -- db sh -c \ | ||
'${{ inputs.db-backend == 'mysql' && | ||
'mysql --user=nautobot --password=$MYSQL_PASSWORD' || | ||
'psql --username=nautobot postgres' | ||
}}' \ | ||
< dump.sql | ||
- name: "Build Database Dump" | ||
if: | | ||
inputs.use-cache == 'true' && | ||
inputs.db-backend != '' && | ||
steps.cache.outputs.cache-hit != 'true' | ||
shell: "bash" | ||
run: | | ||
cd development | ||
docker compose exec -- db sh -c \ | ||
'${{ inputs.db-backend == 'mysql' && | ||
'mysql -u nautobot -e "CREATE DATABASE test_nautobot;"' || | ||
'createdb --user=nautobot test_nautobot' | ||
}}' | ||
docker compose run --rm --entrypoint='' --env=NAUTOBOT_DB_NAME=test_nautobot -- nautobot \ | ||
nautobot-server migrate | ||
docker compose exec -- db sh -c \ | ||
'${{ inputs.db-backend == 'mysql' && | ||
'mysqldump --user=root --password=$MYSQL_ROOT_PASSWORD --databases test_nautobot' || | ||
'pg_dump --clean --create --username=nautobot --dbname=test_nautobot' | ||
}}' \ | ||
> dump.sql | ||
outputs: | ||
compose-file: | ||
description: "Docker Compose Files" | ||
value: "${{ steps.config.outputs.compose-file }}" | ||
compose-image: | ||
description: "Docker Compose Image Reference" | ||
value: "${{ steps.config.outputs.compose-image }}" | ||
ghcr-image: | ||
description: "Docker Image Reference" | ||
value: "${{ steps.config.outputs.ghcr-image }}" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
--- | ||
name: "Build" | ||
description: "Build Nautobot App Docker Image" | ||
inputs: | ||
action: | ||
description: "Action to Perform, (build | load | load-with-cache | pull | push)" | ||
required: true | ||
image-prefix: | ||
description: "Docker Image Prefix" | ||
required: true | ||
image-tag: | ||
description: "Docker Image Tag" | ||
required: true | ||
nautobot-version: | ||
description: "Nautobot Version" | ||
required: true | ||
password: | ||
description: "GitHub Token" | ||
required: false | ||
python-version: | ||
description: "Python Version" | ||
required: true | ||
username: | ||
description: "GitHub Username" | ||
required: false | ||
use-cache: | ||
description: "Use GitHub Actions Cache" | ||
required: false | ||
default: "false" | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: "Login to GitHub Container Registry" | ||
if: | | ||
inputs.password != '' && | ||
inputs.username != '' | ||
uses: "docker/login-action@v3" | ||
with: | ||
password: "${{ inputs.password }}" | ||
registry: "ghcr.io" | ||
username: "${{ inputs.username }}" | ||
- name: "Set up Docker Buildx" | ||
if: | | ||
inputs.action != 'pull' | ||
uses: "docker/setup-buildx-action@v3" | ||
- name: "Build" | ||
if: | | ||
inputs.action == 'build' | ||
uses: "docker/build-push-action@v5" | ||
with: | ||
context: "./" | ||
file: "./development/Dockerfile" | ||
tags: "${{ inputs.image-prefix }}:${{ inputs.image-tag }}" | ||
cache-from: "type=gha,scope=${{ inputs.image-tag }}" | ||
cache-to: "type=gha,scope=${{ inputs.image-tag }}" | ||
build-args: | | ||
NAUTOBOT_VER=${{ inputs.nautobot-version }} | ||
PYTHON_VER=${{ inputs.python-version }} | ||
- name: "Build and Load" | ||
if: | | ||
inputs.action == 'load' | ||
uses: "docker/build-push-action@v5" | ||
with: | ||
load: true | ||
context: "./" | ||
file: "./development/Dockerfile" | ||
tags: "${{ inputs.image-prefix }}:${{ inputs.image-tag }}" | ||
build-args: | | ||
NAUTOBOT_VER=${{ inputs.nautobot-version }} | ||
PYTHON_VER=${{ inputs.python-version }} | ||
- name: "Build and Load With Cache" | ||
if: | | ||
inputs.action == 'load-with-cache' | ||
uses: "docker/build-push-action@v5" | ||
with: | ||
load: true | ||
context: "./" | ||
file: "./development/Dockerfile" | ||
tags: "${{ inputs.image-prefix }}:${{ inputs.image-tag }}" | ||
cache-from: "type=gha,scope=${{ inputs.image-tag }}" | ||
cache-to: "type=gha,scope=${{ inputs.image-tag }}" | ||
build-args: | | ||
NAUTOBOT_VER=${{ inputs.nautobot-version }} | ||
PYTHON_VER=${{ inputs.python-version }} | ||
- name: "Build and Push" | ||
if: | | ||
inputs.action == 'push' | ||
uses: "docker/build-push-action@v5" | ||
with: | ||
push: true | ||
context: "./" | ||
file: "./development/Dockerfile" | ||
tags: "${{ inputs.image-prefix }}:${{ inputs.image-tag }}" | ||
cache-from: "type=gha,scope=${{ inputs.image-tag }}" | ||
cache-to: "type=gha,scope=${{ inputs.image-tag }}" | ||
build-args: | | ||
NAUTOBOT_VER=${{ inputs.nautobot-version }} | ||
PYTHON_VER=${{ inputs.python-version }} | ||
- name: "Pull" | ||
shell: "bash" | ||
if: | | ||
inputs.action == 'pull' | ||
run: | | ||
docker pull '${{ inputs.image-prefix }}:${{ inputs.image-tag }}' | ||
outputs: | ||
image: | ||
description: "Docker Image Reference" | ||
value: "${{ inputs.image-prefix }}:${{ inputs.image-tag }}" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
name: "Run Linters" | ||
description: "Run Linters for Nautobot App" | ||
inputs: | ||
compose-file: | ||
description: "Docker Compose File" | ||
required: true | ||
nautobot-version: | ||
description: "Nautobot Version" | ||
required: true | ||
python-version: | ||
description: "Python Version" | ||
required: true | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: "Run Linters" | ||
shell: "bash" | ||
env: | ||
COMPOSE_ANSI: "0" | ||
COMPOSE_FILE: "${{ inputs.compose-file }}" | ||
NAUTOBOT_VER: "${{ inputs.nautobot-version }}" | ||
PYTHON_VER: "${{ inputs.python-version }}" | ||
run: | | ||
cd development | ||
docker-compose run \ | ||
--rm \ | ||
--entrypoint='' \ | ||
-- \ | ||
nautobot \ | ||
invoke tests --lint-only --no-test-docs |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
name: "Unit Tests" | ||
description: "Run Unit Tests for Nautobot App" | ||
inputs: | ||
compose-file: | ||
description: "Docker Compose Files" | ||
required: true | ||
nautobot-version: | ||
description: "Nautobot Version" | ||
required: true | ||
python-version: | ||
description: "Python Version" | ||
required: true | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: "Unit Tests" | ||
shell: "bash" | ||
env: | ||
COMPOSE_ANSI: "0" | ||
COMPOSE_FILE: "${{ inputs.compose-file }}" | ||
NAUTOBOT_VER: "${{ inputs.nautobot-version }}" | ||
PYTHON_VER: "${{ inputs.python-version }}" | ||
run: | | ||
cd development | ||
docker compose run \ | ||
--rm \ | ||
--entrypoint='' \ | ||
-- \ | ||
nautobot \ | ||
invoke unittest --failfast --keepdb |
Oops, something went wrong.