Refactor Github Action
This commit is contained in:
parent
e18d9d14db
commit
8380b7ff94
|
@ -13,12 +13,15 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Checks syntax of our code
|
name: Checks syntax of our code
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
-
|
||||||
|
uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
# Full git history is needed to get a proper list of changed files within `super-linter`
|
# Full git history is needed to get a proper list of changed files within `super-linter`
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- uses: actions/setup-python@v2
|
-
|
||||||
- name: Lint Code Base
|
uses: actions/setup-python@v2
|
||||||
|
-
|
||||||
|
name: Lint Code Base
|
||||||
uses: github/super-linter@v4
|
uses: github/super-linter@v4
|
||||||
env:
|
env:
|
||||||
DEFAULT_BRANCH: develop
|
DEFAULT_BRANCH: develop
|
||||||
|
@ -35,6 +38,7 @@ jobs:
|
||||||
PYTHON_BLACK_CONFIG_FILE: pyproject.toml
|
PYTHON_BLACK_CONFIG_FILE: pyproject.toml
|
||||||
PYTHON_FLAKE8_CONFIG_FILE: .flake8
|
PYTHON_FLAKE8_CONFIG_FILE: .flake8
|
||||||
PYTHON_ISORT_CONFIG_FILE: pyproject.toml
|
PYTHON_ISORT_CONFIG_FILE: pyproject.toml
|
||||||
|
|
||||||
build:
|
build:
|
||||||
continue-on-error: ${{ matrix.docker_from == 'alpine:edge' }}
|
continue-on-error: ${{ matrix.docker_from == 'alpine:edge' }}
|
||||||
strategy:
|
strategy:
|
||||||
|
@ -54,33 +58,25 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Builds new NetBox Docker Images
|
name: Builds new NetBox Docker Images
|
||||||
steps:
|
steps:
|
||||||
- id: git-checkout
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
- id: get-version
|
-
|
||||||
name: Get Version of NetBox Docker
|
name: Get Version of NetBox Docker
|
||||||
run: |
|
run: |
|
||||||
echo "::set-output name=version::$(cat VERSION)"
|
echo "::set-output name=version::$(cat VERSION)"
|
||||||
shell: bash
|
shell: bash
|
||||||
- id: setup-cache
|
-
|
||||||
name: NetBox Docker Buildx Cache
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
.buildx-cache
|
|
||||||
key: ${{ steps.get-version.outputs.version }}-push-${{ matrix.platform }}-${{ hashFiles('Dockerfile','requirements-container.txt') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ steps.get-version.outputs.version }}-push-
|
|
||||||
${{ steps.get-version.outputs.version }}-
|
|
||||||
- id: qemu-setup
|
|
||||||
name: Set up QEMU
|
name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v1
|
uses: docker/setup-qemu-action@v1
|
||||||
- id: buildx-setup
|
-
|
||||||
|
id: buildx-setup
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v1
|
||||||
with:
|
with:
|
||||||
install: true
|
install: true
|
||||||
- id: docker-build
|
-
|
||||||
|
id: docker-build
|
||||||
name: Build the image from '${{ matrix.docker_from }}' with '${{ matrix.build_cmd }}'
|
name: Build the image from '${{ matrix.docker_from }}' with '${{ matrix.build_cmd }}'
|
||||||
run: ${{ matrix.build_cmd }}
|
run: ${{ matrix.build_cmd }}
|
||||||
env:
|
env:
|
||||||
|
@ -88,7 +84,7 @@ jobs:
|
||||||
GH_ACTION: enable
|
GH_ACTION: enable
|
||||||
BUILDX_BUILDER_NAME: ${{ steps.buildx-setup.outputs.name }}
|
BUILDX_BUILDER_NAME: ${{ steps.buildx-setup.outputs.name }}
|
||||||
BUILDX_PLATFORMS: ${{ matrix.platform }}
|
BUILDX_PLATFORMS: ${{ matrix.platform }}
|
||||||
- id: docker-test
|
-
|
||||||
name: Test the image
|
name: Test the image
|
||||||
run: IMAGE="${FINAL_DOCKER_TAG}" ./test.sh
|
run: IMAGE="${FINAL_DOCKER_TAG}" ./test.sh
|
||||||
if: steps.docker-build.outputs.skipped != 'true'
|
if: steps.docker-build.outputs.skipped != 'true'
|
||||||
|
|
|
@ -23,92 +23,94 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Builds new NetBox Docker Images
|
name: Builds new NetBox Docker Images
|
||||||
steps:
|
steps:
|
||||||
- id: git-checkout
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
- id: get-version
|
-
|
||||||
name: Get Version of NetBox Docker
|
name: Get Version of NetBox Docker
|
||||||
run: |
|
run: |
|
||||||
echo "::set-output name=version::$(cat VERSION)"
|
echo "::set-output name=version::$(cat VERSION)"
|
||||||
shell: bash
|
shell: bash
|
||||||
- id: setup-cache
|
-
|
||||||
name: NetBox Docker Buildx Cache
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
.buildx-cache
|
|
||||||
key: ${{ steps.get-version.outputs.version }}-release-${{ matrix.platform }}-${{ hashFiles('Dockerfile','requirements-container.txt') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ steps.get-version.outputs.version }}-release-
|
|
||||||
${{ steps.get-version.outputs.version }}-
|
|
||||||
- id: qemu-setup
|
|
||||||
name: Set up QEMU
|
name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v1
|
uses: docker/setup-qemu-action@v1
|
||||||
- id: buildx-setup
|
-
|
||||||
|
id: buildx-setup
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v1
|
||||||
with:
|
with:
|
||||||
install: true
|
install: true
|
||||||
- id: buildx-platforms
|
-
|
||||||
name: Available platforms
|
name: Available platforms
|
||||||
run: echo ${{ steps.buildx-setup.outputs.platforms }}
|
run: echo ${{ steps.buildx-setup.outputs.platforms }}
|
||||||
- id: docker-build
|
-
|
||||||
|
id: docker-build
|
||||||
name: Build the image with '${{ matrix.build_cmd }}'
|
name: Build the image with '${{ matrix.build_cmd }}'
|
||||||
run: ${{ matrix.build_cmd }}
|
run: ${{ matrix.build_cmd }}
|
||||||
env:
|
env:
|
||||||
GH_ACTION: enable
|
GH_ACTION: enable
|
||||||
BUILDX_BUILDER_NAME: ${{ steps.buildx-setup.outputs.name }}
|
BUILDX_BUILDER_NAME: ${{ steps.buildx-setup.outputs.name }}
|
||||||
BUILDX_PLATFORMS: ${{ matrix.platform }}
|
BUILDX_PLATFORMS: ${{ matrix.platform }}
|
||||||
- id: docker-test
|
-
|
||||||
name: Test the image
|
name: Test the image
|
||||||
run: IMAGE="${FINAL_DOCKER_TAG}" ./test.sh
|
run: IMAGE="${FINAL_DOCKER_TAG}" ./test.sh
|
||||||
if: steps.docker-build.outputs.skipped != 'true'
|
if: steps.docker-build.outputs.skipped != 'true'
|
||||||
- id: registry-login
|
-
|
||||||
name: Login to the Docker Registry
|
name: Login to docker.io
|
||||||
run: |
|
uses: docker/login-action@v1
|
||||||
echo "::add-mask::$DOCKERHUB_USERNAME"
|
with:
|
||||||
echo "::add-mask::$DOCKERHUB_PASSWORD"
|
registry: docker.io
|
||||||
docker login -u "$DOCKERHUB_USERNAME" --password "${DOCKERHUB_PASSWORD}" "${DOCKER_REGISTRY}"
|
username: ${{ secrets.dockerhub_username }}
|
||||||
env:
|
password: ${{ secrets.dockerhub_password }}
|
||||||
DOCKERHUB_USERNAME: ${{ secrets.dockerhub_username }}
|
|
||||||
DOCKERHUB_PASSWORD: ${{ secrets.dockerhub_password }}
|
|
||||||
if: steps.docker-build.outputs.skipped != 'true'
|
if: steps.docker-build.outputs.skipped != 'true'
|
||||||
- id: registry-push
|
-
|
||||||
|
id: registry-push
|
||||||
name: Push the image
|
name: Push the image
|
||||||
run: ${{ matrix.build_cmd }} --push-only
|
run: ${{ matrix.build_cmd }} --push-only
|
||||||
if: steps.docker-build.outputs.skipped != 'true'
|
if: steps.docker-build.outputs.skipped != 'true'
|
||||||
- id: registry-logout
|
|
||||||
name: Logout of the Docker Registry
|
|
||||||
run: docker logout "${DOCKER_REGISTRY}"
|
|
||||||
if: steps.docker-build.outputs.skipped != 'true'
|
|
||||||
|
|
||||||
# Quay.io
|
# quay.io
|
||||||
- id: quayio-docker-build
|
-
|
||||||
name: Build the image with '${{ matrix.build_cmd }}'
|
name: Build the image with '${{ matrix.build_cmd }}'
|
||||||
run: ${{ matrix.build_cmd }}
|
run: ${{ matrix.build_cmd }}
|
||||||
env:
|
env:
|
||||||
DOCKER_REGISTRY: quay.io
|
DOCKER_REGISTRY: quay.io
|
||||||
GH_ACTION: enable
|
GH_ACTION: enable
|
||||||
- id: quayio-registry-login
|
|
||||||
name: Login to the Quay.io Registry
|
|
||||||
run: |
|
|
||||||
echo "::add-mask::$QUAYIO_USERNAME"
|
|
||||||
echo "::add-mask::$QUAYIO_PASSWORD"
|
|
||||||
docker login -u "$QUAYIO_USERNAME" --password "${QUAYIO_PASSWORD}" "${DOCKER_REGISTRY}"
|
|
||||||
env:
|
|
||||||
DOCKER_REGISTRY: quay.io
|
|
||||||
QUAYIO_USERNAME: ${{ secrets.quayio_username }}
|
|
||||||
QUAYIO_PASSWORD: ${{ secrets.quayio_password }}
|
|
||||||
if: steps.docker-build.outputs.skipped != 'true'
|
if: steps.docker-build.outputs.skipped != 'true'
|
||||||
- id: quayio-registry-push
|
-
|
||||||
|
name: Login to Quay.io
|
||||||
|
uses: docker/login-action@v1
|
||||||
|
with:
|
||||||
|
registry: quay.io
|
||||||
|
username: ${{ secrets.quayio_username }}
|
||||||
|
password: ${{ secrets.quayio_password }}
|
||||||
|
if: steps.docker-build.outputs.skipped != 'true'
|
||||||
|
-
|
||||||
name: Push the image
|
name: Push the image
|
||||||
run: ${{ matrix.build_cmd }} --push-only
|
run: ${{ matrix.build_cmd }} --push-only
|
||||||
env:
|
env:
|
||||||
DOCKER_REGISTRY: quay.io
|
DOCKER_REGISTRY: quay.io
|
||||||
if: steps.docker-build.outputs.skipped != 'true'
|
if: steps.docker-build.outputs.skipped != 'true'
|
||||||
- id: quayio-registry-logout
|
|
||||||
name: Logout of the Docker Registry
|
# ghcr.io
|
||||||
run: docker logout "${DOCKER_REGISTRY}"
|
-
|
||||||
|
name: Build the image with '${{ matrix.build_cmd }}'
|
||||||
|
run: ${{ matrix.build_cmd }}
|
||||||
env:
|
env:
|
||||||
DOCKER_REGISTRY: quay.io
|
DOCKER_REGISTRY: ghcr.io
|
||||||
|
GH_ACTION: enable
|
||||||
|
if: steps.docker-build.outputs.skipped != 'true'
|
||||||
|
-
|
||||||
|
name: Login to GitHub Container Registry
|
||||||
|
uses: docker/login-action@v1
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.repository_owner }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
if: steps.docker-build.outputs.skipped != 'true'
|
||||||
|
-
|
||||||
|
name: Push the image
|
||||||
|
run: ${{ matrix.build_cmd }} --push-only
|
||||||
|
env:
|
||||||
|
DOCKER_REGISTRY: ghcr.io
|
||||||
if: steps.docker-build.outputs.skipped != 'true'
|
if: steps.docker-build.outputs.skipped != 'true'
|
||||||
|
|
13
build.sh
13
build.sh
|
@ -6,7 +6,7 @@ echo "▶️ $0 $*"
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
if [ "${1}x" == "x" ] || [ "${1}" == "--help" ] || [ "${1}" == "-h" ]; then
|
if [ "${1}x" == "x" ] || [ "${1}" == "--help" ] || [ "${1}" == "-h" ]; then
|
||||||
cat <<END_OF_DOCS
|
cat <<END_OF_DOCS
|
||||||
Usage: ${0} <branch> [--push|--push-only]
|
Usage: ${0} <branch> [--push|--push-only]
|
||||||
branch The branch or tag to build. Required.
|
branch The branch or tag to build. Required.
|
||||||
--push Pushes the built Docker image to the registry.
|
--push Pushes the built Docker image to the registry.
|
||||||
|
@ -184,7 +184,7 @@ if [ "${2}" != "--push-only" ] && [ -z "${SKIP_GIT}" ]; then
|
||||||
|
|
||||||
(
|
(
|
||||||
$DRY cd "${NETBOX_PATH}"
|
$DRY cd "${NETBOX_PATH}"
|
||||||
# shellcheck disable=SC2030
|
# shellcheck disable=SC2031
|
||||||
if [ -n "${HTTP_PROXY}" ]; then
|
if [ -n "${HTTP_PROXY}" ]; then
|
||||||
git config http.proxy "${HTTP_PROXY}"
|
git config http.proxy "${HTTP_PROXY}"
|
||||||
fi
|
fi
|
||||||
|
@ -444,13 +444,20 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
|
||||||
if [ -n "${BUILDX_PULL_REMOTE_CACHE}" ]; then
|
if [ -n "${BUILDX_PULL_REMOTE_CACHE}" ]; then
|
||||||
echo "📥 Pulling cache from '${CACHE_TO_DOCKER_TAG}' before build"
|
echo "📥 Pulling cache from '${CACHE_TO_DOCKER_TAG}' before build"
|
||||||
DOCKER_BUILD_ARGS+=("--cache-from=type=registry,ref=${CACHE_FROM_DOCKER_TAG},mode=max")
|
DOCKER_BUILD_ARGS+=("--cache-from=type=registry,ref=${CACHE_FROM_DOCKER_TAG},mode=max")
|
||||||
|
elif [ -n "${GH_ACTION}" ]; then
|
||||||
|
echo "📥 Pulling from GitHub Action cache before build"
|
||||||
else
|
else
|
||||||
|
echo "📥 Pulling buildx cache from '${BUILDX_LOCAL_CACHE-.buildx-cache}' before build"
|
||||||
DOCKER_BUILD_ARGS+=("--cache-from=type=local,src=${BUILDX_LOCAL_CACHE-.buildx-cache},mode=max")
|
DOCKER_BUILD_ARGS+=("--cache-from=type=local,src=${BUILDX_LOCAL_CACHE-.buildx-cache},mode=max")
|
||||||
fi
|
fi
|
||||||
if [ -n "${BUILDX_PUSH_REMOTE_CACHE}" ]; then
|
if [ -n "${BUILDX_PUSH_REMOTE_CACHE}" ]; then
|
||||||
echo "📤 Pushing cache to '${CACHE_TO_DOCKER_TAG}' after build"
|
echo "📤 Pushing buildx cache to '${CACHE_TO_DOCKER_TAG}' after build"
|
||||||
DOCKER_BUILD_ARGS+=("--cache-to=type=registry,ref=${CACHE_TO_DOCKER_TAG},mode=max")
|
DOCKER_BUILD_ARGS+=("--cache-to=type=registry,ref=${CACHE_TO_DOCKER_TAG},mode=max")
|
||||||
|
elif [ -n "${GH_ACTION}" ]; then
|
||||||
|
echo "📤 Pushing to GitHub Action cache after build"
|
||||||
|
DOCKER_BUILD_ARGS+=("--cache-to=type=gha")
|
||||||
else
|
else
|
||||||
|
echo "📤 Pushing buildx cache to '${BUILDX_LOCAL_CACHE-.buildx-cache}' after build"
|
||||||
DOCKER_BUILD_ARGS+=("--cache-to=type=local,dest=${BUILDX_LOCAL_CACHE-.buildx-cache},mode=max")
|
DOCKER_BUILD_ARGS+=("--cache-to=type=local,dest=${BUILDX_LOCAL_CACHE-.buildx-cache},mode=max")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue