Skip to content

Commit

Permalink
Merge pull request #20 from nokia/container
Browse files Browse the repository at this point in the history
Container build workflow
  • Loading branch information
hellt authored Oct 12, 2023
2 parents a93edda + 9a3c077 commit 24a116d
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 16 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.log
25 changes: 25 additions & 0 deletions .github/container-matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2023 Nokia
# Licensed under the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause

# a matrix list of variables used in the container build process
#
# python version are taken from ansible's support matrix - https://docs.ansible.com/ansible/latest/reference_appendices/release_and_maintenance.html#support-life
include:
# 2.14.10
- ansible-core-image: "2.14.10:pypy3.10"
runs-on: "ubuntu-22.04"

- ansible-core-image: "2.14.10:py3.11"
runs-on: "ubuntu-22.04"
addional-tags: "latest"

# 2.15.4
# - base-image: "pypy:3.10-slim"
# ansible-core-version: "2.15.4"
# runs-on: "ubuntu-22.04"

# - base-image: "python:3.11-slim"
# ansible-core-version: "2.15.4"
# runs-on: "ubuntu-22.04"
# addional-tags: "latest"
16 changes: 0 additions & 16 deletions .github/matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,7 @@
# kind of a manual way of creating a testing matrix with a flexibility of selecting permuatations
# support matrix for ansible control node - https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#node-requirement-summary
include:
# Python 3.6
- python-version: "3.6.15"
ansible-core-version: "2.11.11"
runs-on: "ubuntu-20.04"

# Python 3.7
- python-version: "3.7"
ansible-core-version: "2.11.11"
runs-on: "ubuntu-22.04"

# Python 3.8
- python-version: "3.8"
ansible-core-version: "2.11.11"
runs-on: "ubuntu-22.04"
- python-version: "3.8"
ansible-core-version: "2.12.10"
runs-on: "ubuntu-22.04"
Expand All @@ -28,9 +15,6 @@ include:
runs-on: "ubuntu-22.04"

# Python 3.9
- python-version: "3.9"
ansible-core-version: "2.11.11"
runs-on: "ubuntu-22.04"
- python-version: "3.9"
ansible-core-version: "2.12.10"
runs-on: "ubuntu-22.04"
Expand Down
100 changes: 100 additions & 0 deletions .github/workflows/container-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Container build
"on":
release:
types:
- released
workflow_dispatch:

jobs:
prepare-matrix:
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.matrix.outputs.output }}
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: |
echo "$GITHUB_CONTEXT"
- uses: actions/checkout@v3
- uses: fabasoad/data-format-converter-action@main
id: matrix
with:
input: ".github/container-matrix.yml"
from: "yaml"
to: "json"

build:
name: Build container
runs-on: ubuntu-22.04
needs: prepare-matrix
strategy:
# fail-fast: false
matrix: ${{ fromJson(needs.prepare-matrix.outputs.matrix) }}

steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: |
echo "$GITHUB_CONTEXT"
- name: Checkout
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Process ansible core image version
id: core-image
run: |
CORE_VERSION=$(./run.sh _transformAnsibleCoreVersion "${{ matrix.ansible-core-image }}")
echo "::set-output name=core-version::$CORE_VERSION"
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository }}/${{ steps.core-image.outputs.core-version }}
tags: |
type=ref,event=tag
type=ref,event=branch
# git short commit
type=sha
- name: Build
uses: docker/build-push-action@v4
with:
context: .
load: true
build-args: |
BASE_IMAGE=ghcr.io/srl-labs/ansible-core/${{ matrix.ansible-core-image }}
tags: app:latest

- name: Test
run: |
sudo docker run --rm app:latest ansible-galaxy collection list | grep -q 'nokia.srlinux' || exit 1
- name: Login to GitHub Container Registry
if: "!github.event.act"
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
if: "!github.event.act"
uses: docker/setup-qemu-action@v3

- name: Build and Push
if: "!github.event.act"
uses: docker/build-push-action@v4
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
build-args: |
BASE_IMAGE=ghcr.io/srl-labs/ansible-core/${{ matrix.ansible-core-image }}
tags: ${{ steps.meta.outputs.tags }}
9 changes: 9 additions & 0 deletions .github/workflows/release-event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"act": true,
"action": "created",
"ref": "refs/tags/v0.0.1",
"sha": "b7e12928f13caf61af40d3e8788649a1a8f24c22",
"release": {
"tag_name": "v0.0.1"
}
}
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ARG BASE_IMAGE=ghcr.io/srl-labs/ansible-core/2.14.10:pypy3.10

FROM ${BASE_IMAGE} as builder

COPY . /work

WORKDIR /work

RUN ansible-galaxy collection install --no-cache ..

FROM ${BASE_IMAGE}

COPY --from=builder /root/.ansible/collections /root/.ansible/collections

WORKDIR /ansible

CMD [ "ansible-playbook" ]
10 changes: 10 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ function _cdTests() {
fi
}

# transoforms ansible core version by swapping : with /
function _transformAnsibleCoreVersion() {
echo "${1}" | sed 's/:/\//g'
}

# -----------------------------------------------------------------------------
# Install functions.
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -311,6 +316,11 @@ function sanity-test {
remove-local-collection
}

# testing gh workflow
function test-act-release {
gh act release -W '.github/workflows/container-build.yml' -e .github/workflows/release-event.json -s GITHUB_TOKEN="$(gh auth token)" --matrix ansible-core-image:2.14.10:py3.11
}

# -----------------------------------------------------------------------------
# Publish functions.
# -----------------------------------------------------------------------------
Expand Down

0 comments on commit 24a116d

Please sign in to comment.