Skip to content

CI

CI #61

Workflow file for this run

name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: '0 1 * * 0'
env:
IMAGE_NAME: sjoshi10/ansible-core
LATEST_OS: alpine
LATEST_VERSION: v2.13
DOCKER_CLI_VERSION: "20.10.14"
GOSU_VERSION: "1.14"
jobs:
build_push_before_python38:
runs-on: ubuntu-latest
strategy:
matrix:
os: [almalinux8, alpine, ubuntu]
version: [v2.11]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Prepare
id: prep
run: |
cp requirements/${MATRIX_VERSION}/requirements.txt requirements/requirements.txt
TAGS="${IMAGE_NAME}:${MATRIX_VERSION}-${MATRIX_OS}"
if [[ "$MATRIX_OS" == "$LATEST_OS" ]]; then
TAGS="${TAGS},${IMAGE_NAME}:$MATRIX_VERSION"
elif [[ "$MATRIX_OS" == "almalinux8" && "$MATRIX_VERSION" == "v2.11" ]]; then
TAGS="${TAGS},${IMAGE_NAME}:latest-${MATRIX_OS}"
fi
echo "::set-output name=tags::${TAGS}"
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
env:
MATRIX_OS: ${{ matrix.os }}
MATRIX_VERSION: ${{ matrix.version }}
# Since sudo is used this will complain and suggest gosu but that
# needs to be tested if gosu can replace sudo for Ansible use-cases.
# - name: Lint Dockerfile
# uses: docker://replicated/dockerfilelint:latest
# with:
# args: Dockerfile.${{ matrix.os }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2.0.0
- name: Login to DockerHub
uses: docker/login-action@v2.0.0
if: ${{ endsWith(github.ref, '/main') }}
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and Push
uses: docker/build-push-action@v3.0.0
with:
labels: |
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.source=${{ github.repositoryUrl }}
org.opencontainers.image.version=${{ matrix.version }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.name }}
build-args: |
docker_version=${{ env.DOCKER_CLI_VERSION }}
gosu_version=${{ env.GOSU_VERSION }}
tags: ${{ steps.prep.outputs.tags }}
context: .
file: ./Dockerfile.${{ matrix.os }}
push: ${{ endsWith(github.ref, '/main') }}
build_push_python38_and_later:
needs: build_push_before_python38
runs-on: ubuntu-latest
strategy:
matrix:
os: [alpine, ubuntu]
version: [v2.12, v2.13,v2.15]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Prepare
id: prep
run: |
cp requirements/${MATRIX_VERSION}/requirements.txt requirements/requirements.txt
TAGS="${IMAGE_NAME}:${MATRIX_VERSION}-${MATRIX_OS}"
if [[ "$MATRIX_OS" == "$LATEST_OS" ]]; then
TAGS="${TAGS},${IMAGE_NAME}:$MATRIX_VERSION"
if [[ "$MATRIX_VERSION" == "$LATEST_VERSION" ]]; then
TAGS="${TAGS},${IMAGE_NAME}:latest-${MATRIX_OS},${IMAGE_NAME}:latest"
fi
elif [[ "$MATRIX_VERSION" == "$LATEST_VERSION" ]]; then
TAGS="${TAGS},${IMAGE_NAME}:latest-${MATRIX_OS}"
fi
echo "::set-output name=tags::${TAGS}"
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
env:
MATRIX_OS: ${{ matrix.os }}
MATRIX_VERSION: ${{ matrix.version }}
# Since sudo is used this will complain and suggest gosu but that
# needs to be tested if gosu can replace sudo for Ansible use-cases.
# - name: Lint Dockerfile
# uses: docker://replicated/dockerfilelint:latest
# with:
# args: Dockerfile.${{ matrix.os }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2.0.0
- name: Login to DockerHub
uses: docker/login-action@v2.0.0
if: ${{ endsWith(github.ref, '/main') }}
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and Push
uses: docker/build-push-action@v3.0.0
with:
labels: |
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.source=${{ github.repositoryUrl }}
org.opencontainers.image.version=${{ matrix.version }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.name }}
build-args: |
docker_version=${{ env.DOCKER_CLI_VERSION }}
gosu_version=${{ env.GOSU_VERSION }}
tags: ${{ steps.prep.outputs.tags }}
context: .
file: ./Dockerfile.${{ matrix.os }}
push: ${{ endsWith(github.ref, '/main') }}
update_docker_hub_description:
needs: build_push_python38_and_later
runs-on: ubuntu-latest
if: ${{ endsWith(github.ref, '/main') }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: ${{ env.IMAGE_NAME }}