Skip to content

Commit

Permalink
wip: Split build
Browse files Browse the repository at this point in the history
  • Loading branch information
snaselj committed Oct 10, 2023
1 parent 4833f7a commit feb9122
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 67 deletions.
35 changes: 26 additions & 9 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,50 @@
name: "Build"
description: "Build Docker Image for Nautobot App"
inputs:
"image":
description: "Docker Image URL"
"image-name":
description: "Docker Image Name"
required: true
"image-tag":
description: "Docker Image Tag"
required: true
"nautobot-version":
description: "Nautobot version"
description: "Nautobot Version"
required: true
"push":
description: "Push Docker Image"
description: "Push Docker Image to ghcr.io"
required: false
default: "false"
"python-version":
description: "Python version"
description: "Python Version"
required: true
"registry":
description: "Docker Registry"
required: false
default: "ghcr.io"
outputs:
"image":
description: "Docker Image URL"
value: "${{ inputs.image }}"
description: "Docker Image Reference"
value: "${{ inputs.image-name }}:${{ inputs.image-tag }}"
runs:
using: "composite"
steps:
- name: "Set up Docker Buildx"
id: "buildx"
uses: "docker/setup-buildx-action@v3"
- name: "Build"
uses: "docker/build-push-action@v5"
with:
context: "./"
push: "${{ inputs.push }}"
tags: "${{ inputs.image }}"
file: "./development/Dockerfile"
push: "${{ inputs.push }}"
registry: "${{ inputs.registry }}"
tags: "${{ inputs.image-name }}:${{ 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 }}
99 changes: 99 additions & 0 deletions .github/workflows/full-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
name: "Test Feature Pull Request"

on: # yamllint disable-line rule:truthy
# pull_request: {}
workflow_dispatch: {}

concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true

env:
DISABLE_MYSQL_TESTS: 1

jobs:
tests:
runs-on: "ubuntu-22.04"
strategy:
fail-fast: true
matrix:
nautobot-version: ["stable"]
python-version: ["3.11", "3.8"]
include:
- nautobot-version: "2.0.0"
python-version: "3.11"
env:
NAUTOBOT_VER: "${{ matrix.nautobot-version }}"
PYTHON_VER: "${{ matrix.python-version }}"
steps:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Configure"
id: "config"
env:
COMPOSE_FILE: "docker-compose.base.yml"
run: |
cd development
cp creds.example.env creds.env
# Read Docker image reference from Compose configuration
IMAGE="$(docker compose convert --format json | jq -r .services.nautobot.image)"
cd -
RUN_LINTERS=0
TEST_MYSQL=0
if [[ "${{ matrix.python-version }}" == "3.11" ]]; then
if [[ "${{ matrix.nautobot-version }}" == "stable" ]]; then
RUN_LINTERS=1
else
if [[ "${{ env.DISABLE_MYSQL_TESTS }}" != "1" ]]; then
TEST_MYSQL=1
fi
fi
fi
echo "image=${IMAGE}" | tee -a "$GITHUB_OUTPUT"
echo "run-linters=${RUN_LINTERS}" | tee -a "$GITHUB_OUTPUT"
echo "test-mysql=${TEST_MYSQL}" | tee -a "$GITHUB_OUTPUT"
- name: "Build"
uses: "./.github/actions/build"
with:
image: "${{ steps.config.outputs.image }}"
nautobot-version: "${{ matrix.nautobot-version }}"
python-version: "${{ matrix.python-version }}"
- name: "Run Linters"
if: |
steps.config.outputs.run-linters == '1'
run: |
docker run \
--rm \
--entrypoint='' \
--volume="$PWD:/source" \
--env-file development/creds.env \
--env-file development/development.env \
'${{ steps.config.outputs.image }}' \
invoke tests --lint-only --no-test-docs
- name: "Test with Postgres"
env:
COMPOSE_FILE: "docker-compose.base.yml:docker-compose.postgres.yml:docker-compose.redis.yml:docker-compose.dev.yml"
run: |
cd development
docker compose run \
--rm \
--entrypoint='' \
-- \
nautobot \
invoke unittest --failfast
- name: "Test with MySQL"
if: |
steps.config.outputs.test-mysql == '1'
env:
COMPOSE_FILE: "docker-compose.base.yml:docker-compose.mysql.yml:docker-compose.redis.yml:docker-compose.dev.yml"
run: |
cd development
docker compose run \
--rm \
--entrypoint='' \
-- \
nautobot \
invoke unittest --failfast
100 changes: 42 additions & 58 deletions .github/workflows/test-feature-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,92 +3,76 @@ name: "Test Feature Pull Request"

on: # yamllint disable-line rule:truthy
pull_request: {}
# workflow_dispatch: {}

concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true

env:
DISABLE_MYSQL_TESTS: 1
NAUTOBOT_VER: "stable"
PYTHON_VER: "3.11"

jobs:
tests:
build:
runs-on: "ubuntu-22.04"
strategy:
fail-fast: true
matrix:
nautobot-version: ["stable"]
# python-version: ["3.11"]
python-version: ["3.11", "3.8"]
include:
- nautobot-version: "2.0.0"
python-version: "3.11"
env:
NAUTOBOT_VER: "${{ matrix.nautobot-version }}"
PYTHON_VER: "${{ matrix.python-version }}"
outputs:
image: ${{ steps.build.outputs.image }}
steps:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Configure"
id: "config"
env:
COMPOSE_FILE: "docker-compose.base.yml"
run: |
cd development
cp creds.example.env creds.env
# Read Docker image reference from Compose configuration
IMAGE="$(docker compose convert --format json | jq -r .services.nautobot.image)"
cd -
RUN_LINTERS=0
TEST_MYSQL=0
if [[ "${{ matrix.python-version }}" == "3.11" ]]; then
if [[ "${{ matrix.nautobot-version }}" == "stable" ]]; then
RUN_LINTERS=1
else
if [[ "${{ env.DISABLE_MYSQL_TESTS }}" != "1" ]]; then
TEST_MYSQL=1
fi
fi
fi
echo "image=${IMAGE}" | tee -a "$GITHUB_OUTPUT"
echo "run-linters=${RUN_LINTERS}" | tee -a "$GITHUB_OUTPUT"
echo "test-mysql=${TEST_MYSQL}" | tee -a "$GITHUB_OUTPUT"
- name: "Build"
uses: "./.github/actions/build"
with:
image: "${{ steps.config.outputs.image }}"
nautobot-version: "${{ matrix.nautobot-version }}"
python-version: "${{ matrix.python-version }}"
image-name: "${{ github.repository }}/nautobot-dev"
image-tag: "${{ github.ref_name }}-py${{ env.PYTHON_VER }}-${{ env.NAUTOBOT_VER }}"
nautobot-version: "${{ env.NAUTOBOT_VER }}"
python-version: "${{ env.PYTHON_VER }}"
push: true

linters:
needs: build
runs-on: "ubuntu-22.04"
steps:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Pull Image"
run: |
docker pull '${{ needs.build.outputs.image }}'
- name: "Run Linters"
if: |
steps.config.outputs.run-linters == '1'
run: |
docker run \
--rm \
--entrypoint='' \
--volume="$PWD:/source" \
--env-file development/creds.env \
--env-file development/development.env \
'${{ steps.config.outputs.image }}' \
'${{ needs.build.outputs.image }}' \
invoke tests --lint-only --no-test-docs
- name: "Test with Postgres"
test-postgres:
needs: build
runs-on: "ubuntu-22.04"
steps:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Configure"
id: "config"
env:
COMPOSE_FILE: "docker-compose.base.yml:docker-compose.postgres.yml:docker-compose.redis.yml:docker-compose.dev.yml"
COMPOSE_FILE: "docker-compose.base.yml"
run: |
cd development
docker compose run \
--rm \
--entrypoint='' \
-- \
nautobot \
invoke unittest --failfast
- name: "Test with MySQL"
if: |
steps.config.outputs.test-mysql == '1'
cp creds.example.env creds.env
IMAGE="$(docker compose convert --format json | jq -r .services.nautobot.image)"
echo "image=$IMAGE" >> $GITHUB_ENV
cd -
- name: "Pull Image"
run: |
docker pull '${{ needs.build.outputs.image }}'
docker tag '${{ needs.build.outputs.image }}' '${{ steps.config.outputs.image }}'
- name: "Test with Postgres"
env:
COMPOSE_FILE: "docker-compose.base.yml:docker-compose.mysql.yml:docker-compose.redis.yml:docker-compose.dev.yml"
COMPOSE_FILE: "docker-compose.base.yml:docker-compose.postgres.yml:docker-compose.redis.yml:docker-compose.dev.yml"
run: |
cd development
docker compose run \
Expand Down

0 comments on commit feb9122

Please sign in to comment.