Skip to content

Commit

Permalink
WIP: Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
snaselj committed Oct 18, 2023
1 parent 0b1c5ad commit ca732b2
Show file tree
Hide file tree
Showing 23 changed files with 1,015 additions and 69 deletions.
27 changes: 0 additions & 27 deletions .dockerignore

This file was deleted.

31 changes: 10 additions & 21 deletions .github/PULL_REQUEST_TEMPLATE/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
<!--
Thank you for your interest in contributing to Nautobot! Please note
that our contribution policy recommends that a feature request or bug
report be opened for approval prior to filing a pull request. This
helps avoid wasting time and effort on something that we might not
be able to accept.
# Closes: NaN

Please indicate the relevant feature request or bug report below.
-->

# Closes: #<ISSUE NUMBER GOES HERE>
Optimize CI time.

## What's Changed

<!--
Please include:
- A summary of the proposed changes
- A sectioned breakdown for larger features under ## subheadings
- Screenshots, example payloads where relevant:
- Before/After for bugfixes
- Using a new feature
-->
- Added `build` GitHub action.
- Added simple `test-feature-pr.yml` GitHub workflow.
- Bumped CI `uses` versions to the latest major version each.
- Bumped CI image version to `ubuntu-22.04`.
- Disabled `ci.yml` GitHub workflow.
- Moved Compose dependencies to database `yaml` files.
- Added `--test-docs` to `invoke tests`.
- Fixed `invoke tests --lint-only` not to run coverage.

## To Do

<!--
Please feel free to update todos to keep track of your own notes for WIP PRs.
-->
- [ ] Explanation of Change(s)
- [ ] Added change log fragment(s) (for more information see [the documentation](https://docs.nautobot.com/projects/core/en/stable/development/#creating-changelog-fragments))
- [ ] Attached Screenshots, Payload Example
Expand Down
146 changes: 146 additions & 0 deletions .github/actions/config-compose/action.yml
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 }}"
108 changes: 108 additions & 0 deletions .github/actions/docker-image/action.yml
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 }}"
31 changes: 31 additions & 0 deletions .github/actions/run-linters/action.yml
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
31 changes: 31 additions & 0 deletions .github/actions/unittests/action.yml
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
Loading

0 comments on commit ca732b2

Please sign in to comment.