Skip to content

ignore: update tag

ignore: update tag #23

Workflow file for this run

name: Build NBFC runners
on:
push:
branches:
- feat_nbfc_runners
workflow_dispatch:
env:
# Use docker.io for Docker Hub if empty
#REGISTRY: docker.io
REGISTRY: harbor.nbfc.io/nubificus
# github.repository as <account>/<repo>
IMAGE_NAME: gh-actions-runner-gcc-lite
# IMAGE_NAME: ${{ github.repository }}
#IMAGE_NAME: ananos/${{ github.repository }}
manifest_file: dockerImages_build_manifest.json
jobs:
prepare:
name: Generate matrix for build
runs-on: [ self-hosted ]
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
matrix2: ${{ steps.set-matrix.outputs.matrix2 }}
myvars: ${{ steps.set-matrix.outputs.myvars }}
files: ${{ steps.set-matrix.outputs.files}}
arch: ${{ steps.set-matrix.outputs.arch}}
registry: ${{ steps.dockerfiles.outputs.registry }}
manifest_matrix: ${{ steps.parse-manifest.outputs.matrix }}
build_level0: ${{ steps.parse-manifest.outputs.build_level0_matrix}}
build_level1: ${{ steps.parse-manifest.outputs.build_level1_matrix}}
output_tag: ${{ steps.parse-manifest.outputs.output_manifest_tag}}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Check files
id: dockerfiles
run: |
export dockerfiles=$( ls -1 Dockerfile.* )
echo "$dockerfiles"
# Escape newlines (replace \n with %0A)
echo "::set-output name=dockerfiles::$( echo "$dockerfiles" | sed ':a;N;$!ba;s/\n/%0A/g' )"
echo "registry=${{ env.REGISTRY }}" >> "$GITHUB_OUTPUT"
- name: Set matrix for build
id: set-matrix
run: |
dockerfiles="${{ steps.dockerfiles.outputs.dockerfiles }}"
JSON="{\"dockerfile\":["
# Loop by lines
while read path; do
# Add item to the matrix only if it is not already included and remove /
path=${path}
JSONline="\"$path\","
if [[ "$JSON" != *"$JSONline"* ]]; then
JSON="$JSON$JSONline"
fi
done <<< "$dockerfiles"
if [[ $JSON == *, ]]; then
JSON="${JSON%?}"
fi
JSON="$JSON], \"architecture\":[\"x86_64\", \"aarch64\", \"armv7l\"]}"
echo $JSON
# Set output
echo "::set-output name=matrix::$( echo "$JSON" )"
- name: parse manifest
id: parse-manifest
run: |
matrix=$(cat ${{github.workspace}}/${{env.manifest_file}}| tr -d '[:space:]')
echo "matrix=$matrix" >> $GITHUB_OUTPUT
echo $matrix
build_level0_matrix=$(jq -e .dockerfile_build_components[] | jq 'walk(if type == "object" and .build_level == 1 then del(.) else . end)' ${{github.workspace}}/${{env.manifest_file}} | tr -d '[:space:]' | sed -E 's/(,)?null(,)?//g')
echo "build_level0_matrix=$build_level0_matrix" >> $GITHUB_OUTPUT
build_level1_matrix=$(jq -e .dockerfile_build_components[] | jq 'walk(if type == "object" and .build_level == 0 then del(.) else . end)' ${{github.workspace}}/${{env.manifest_file}} | tr -d '[:space:]' | sed -E 's/(,)?null(,)?//g')
echo "build_level1_matrix=$build_level1_matrix" >> $GITHUB_OUTPUT
echo "build0:"
echo $build_level0_matrix
echo "build1:"
echo $build_level1_matrix
output_manifest_tag=$(cat ${{github.workspace}}/${{env.manifest_file}} | jq -rce .output_manifest_tag)
echo "output_manifest_tag:"
echo $output_manifest_tag
echo "output_manifest_tag=$output_manifest_tag" >> $GITHUB_OUTPUT
build-base:
needs: [prepare]
strategy:
matrix:
dockerfiles: ${{ fromJson(toJSON(fromJson(needs.prepare.outputs.build_level0).dockerfile_build_components)) }}
fail-fast: false
uses: ./.github/workflows/nbfc-build.yaml
with:
matrix: ${{ needs.prepare.outputs.matrix }}
dockerfile: ${{ matrix.dockerfiles.image_filename }}
registry: ${{ needs.prepare.outputs.registry }}
output_tag: ${{ needs.prepare.outputs.output_tag }}
base_dockerfile: ${{ matrix.dockerfiles.base_filename }}
tags: ${{ matrix.dockerfiles.tags }}
secrets:
nbfc_priv_secret: ${{ secrets.NBFC_BUILDER_TOKEN }}
harbor_user: ${{ secrets.HARBOR_USER }}
harbor_secret: ${{ secrets.HARBOR_SECRET }}
build:
needs: [prepare, build-base]
strategy:
matrix:
dockerfiles: ${{ fromJson(toJSON(fromJson(needs.prepare.outputs.build_level1).dockerfile_build_components)) }}
fail-fast: false
uses: ./.github/workflows/nbfc-build.yaml
with:
matrix: ${{ needs.prepare.outputs.matrix }}
dockerfile: ${{ matrix.dockerfiles.image_filename }}
registry: ${{ needs.prepare.outputs.registry }}
output_tag: ${{ needs.prepare.outputs.output_tag }}
base_dockerfile: ${{ matrix.dockerfiles.base_filename }}
tags: ${{ matrix.dockerfiles.tags }}
secrets:
nbfc_priv_secret: ${{ secrets.NBFC_BUILDER_TOKEN }}
harbor_user: ${{ secrets.HARBOR_USER }}
harbor_secret: ${{ secrets.HARBOR_SECRET }}
postCleanup:
name: post-cleanup
permissions: write-all
if: ${{ !cancelled() }}
needs: [ prepare, build-base, build ]
runs-on: [ self-hosted ]
steps:
- name: Purge current job variables
id: list_repo_variables
run: |
repo_var=$(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.NBFC_BUILDER_TOKEN }}" -H "X-GitHub-Api-Version: 2022-11-28" -H "per_page: 100" https://api.github.com/repos/${{github.repository}}/actions/variables)
echo $repo_var
job_vars_to_delete=`echo $repo_var | jq -r '.variables[] |select(.name |test("_${{ github.run_id }}."))' | jq -rc '.name'`
echo $job_vars_to_delete
for i in `echo $job_vars_to_delete`; do echo "deleting: " $i; curl -L -X DELETE -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.NBFC_BUILDER_TOKEN }}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/${{github.repository}}/actions/variables/$i ;done