Skip to content

Replace unsafe pyyaml loader with SafeLoader #381

Replace unsafe pyyaml loader with SafeLoader

Replace unsafe pyyaml loader with SafeLoader #381

Workflow file for this run

name: CI
on:
push:
branches: [main]
pull_request:
release:
types: [published]
jobs:
# Run black linting
# https://github.com/psf/black
lint-black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: "3.8"
cache: 'pip'
- name: Cache Python Dependencies and Env
uses: actions/cache@v3
with:
path: |
~/.cache/pip
.tox
key: ${{ runner.os }}-v1-python-3.8-black-${{ hashFiles('test-requirements.txt', 'pyproject.toml', 'tox.ini') }}
- name: Install Python test dependencies
run: python -m pip install tox
- name: Run black formatting
run: |
echo "::add-matcher::.github/matchers/black.json"
tox -e black
# Run pylint static code analysis
# https://www.pylint.org/
lint-pylint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: "3.8"
cache: 'pip'
- name: Cache Python Dependencies and Env
uses: actions/cache@v3
with:
path: |
~/.cache/pip
.tox
key: ${{ runner.os }}-v1-python-3.8-pylint-${{ hashFiles('requirements.txt', 'test-requirements.txt', 'tox.ini') }}
- name: Install Python test dependencies
run: python -m pip install tox
- name: Run pylint
run: |
echo "::add-matcher::.github/matchers/pylint.json"
tox -e pylint
# Run python unit tests
# https://docs.python.org/3/library/unittest.html
tests-unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: "3.8"
cache: 'pip'
- name: Cache Python Dependencies and Env
uses: actions/cache@v3
with:
path: |
~/.cache/pip
.tox
key: ${{ runner.os }}-v1-python-3.8-pylint-${{ hashFiles('requirements.txt', 'test-requirements.txt', 'tox.ini') }}
- name: Install Python test dependencies
run: python -m pip install tox
- name: Run unit tests
run: |
tox -e unit
# Build and Push the base Docker image with no plugins
build-base-image:
runs-on: ubuntu-latest
needs:
- lint-black
- lint-pylint
- tests-unit
steps:
-
uses: actions/checkout@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Tag the base image
id: meta
uses: docker/metadata-action@v4
with:
images: |
bitovi/bitops
# disable automatic 'latest' tag generation
flavor: latest=false
# https://bitops.sh/versioning/
tags: |
# On 'main' branch update push 'dev-base' Docker tag
type=raw,value=dev-base,enable=${{ github.ref_name == 'main' }}
# On release push versioned '1.2.3-base' Docker tag
type=semver,pattern={{version}}-base,enable=${{ github.event_name == 'release' }}
# On release update additional 'base' Docker tag to refer to the latest stable base
type=raw,value=base,enable=${{ github.event_name == 'release' }}
-
name: Login to Docker Hub
uses: docker/login-action@v2
if: github.event_name != 'pull_request'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
-
name: Build base Docker image
uses: docker/build-push-action@v4
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
-
# TODO: Save the image as a GitHub artifact on a PR
# See: https://github.com/docker/build-push-action/issues/225#issuecomment-727639184
name: Push base Docker image
uses: docker/build-push-action@v4
if: ${{ (github.ref_name == 'main') || (github.event_name == 'release') }}
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
push: true
# Build and Push the predefined BitOps Docker image(s)
build-prebuilt-images:
runs-on: ubuntu-latest
needs:
- build-base-image
strategy:
fail-fast: false
matrix:
target:
- aws-ansible
- aws-helm
- aws-terraform
- omnibus
steps:
-
uses: actions/checkout@v3
-
name: Build FROM 'dev-base' Dockerfile
uses: cuchi/[email protected]
if: ${{ (github.ref_name == 'main') || (github.event_name == 'pull_request') }}
with:
template: prebuilt-config/dockerfile.template
output_file: ./Dockerfile
variables: tag=dev-base
-
name: Build FROM '1.2.3-base' Dockerfile
uses: cuchi/[email protected]
if: github.event_name == 'release'
with:
template: prebuilt-config/dockerfile.template
output_file: ./Dockerfile
# tag=v1.2.3-base -> tag=1.2.3-base is converted in the Dockerfile.template Jinja
variables: tag=${{ github.event.release.tag_name }}-base
-
name: Use ${{ matrix.target }} bitops.config.yaml
run: cp ./prebuilt-config/${{ matrix.target }}/bitops.config.yaml ./bitops.config.yaml
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Tag the Docker image
id: meta
uses: docker/metadata-action@v4
with:
images: |
bitovi/bitops
# disable automatic 'latest' tag generation
flavor: latest=false
# https://bitops.sh/versioning/
tags: |
# DEVELOPMENT
# On 'main' branch push, - build 'omnibus' image and publish it as 'dev' Docker tag
type=raw,value=dev,enable=${{ (github.ref_name == 'main') && (matrix.target == 'omnibus') }}
# RELEASE
# On a versioned release push '2.0.0-omnibus', '2.0.0-aws-ansible', etc Docker tags
type=semver,pattern={{version}}-${{ matrix.target }},enable=${{ github.event_name == 'release' }}
# If omnibus release, push additional versioned '1.2.3' Docker tag
type=semver,pattern={{version}},enable=${{ (github.event_name == 'release') && (matrix.target == 'omnibus') }}
# On release update additional 'latest' Docker tag for Omnibus image
type=raw,value=latest,enable=${{ (github.event_name == 'release') && (matrix.target == 'omnibus') }}
-
name: Login to Docker Hub
uses: docker/login-action@v2
if: github.event_name != 'pull_request'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
-
name: Build Docker image
uses: docker/build-push-action@v4
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
-
name: Push Docker image
uses: docker/build-push-action@v4
if: ${{ (github.ref_name == 'main') && (matrix.target == 'omnibus') || (github.event_name == 'release') }}
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
push: true