Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
ci(workflow): enable community contributions (#1848)
Browse files Browse the repository at this point in the history
* ci: enable community contributions

Signed-off-by: Bence Csati <[email protected]>

* fix: remarks

Signed-off-by: Bence Csati <[email protected]>

* fix: improve image build

Signed-off-by: Bence Csati <[email protected]>

* feat: add manual build-and-push workflow

Signed-off-by: Bence Csati <[email protected]>

---------

Signed-off-by: Bence Csati <[email protected]>
  • Loading branch information
csatib02 authored Jul 8, 2024
1 parent c766ebe commit 3adddf7
Show file tree
Hide file tree
Showing 16 changed files with 303 additions and 560 deletions.
168 changes: 0 additions & 168 deletions .github/workflows/build-and-push-component.yaml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/build-and-push-components-manual.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Build and Push Components Manual

on:
workflow_dispatch:

permissions:
packages: write

jobs:
build-and-push:
uses: ./.github/workflows/build-and-push-components-registry.yml
with:
suffix: "-dev"
image_tag: latest
97 changes: 97 additions & 0 deletions .github/workflows/build-and-push-components-registry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Build and Push Components Registry

on:
workflow_call:
inputs:
image_tag:
required: true
type: string
description: 'Image tag to use.'
registry_name:
required: false
type: string
description: 'Name of the registry.'
default: ghcr.io/openclarity
suffix:
required: false
type: string
description: 'Suffix to append to the image name'
default: ""
bake-group:
required: false
type: string
description: 'Name of the Docker Bake group of targets'
default: default

jobs:
prepare-build:
runs-on: ubuntu-latest
outputs:
timestamp: ${{ steps.timestamp.outputs.timestamp }}
targets: ${{ steps.targets.outputs.targets }}
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Set timestamp
id: timestamp
run: |
##
## Set timestamp variable
##
echo "timestamp=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
- name: List targets
id: targets
uses: docker/bake-action/subaction/list-targets@7a5dfed3550ca014665af2a27af8fc9d7284b9b3 # v4.5.0
with:
target: ${{ inputs.bake-group }}

build-and-push:
needs: prepare-build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
targets: ${{ fromJson(needs.prepare-build.outputs.targets) }}
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0

- name: Cache Docker layers
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.ref }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GitHub Container Registry
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build
uses: docker/bake-action@7a5dfed3550ca014665af2a27af8fc9d7284b9b3 # v4.5.0
id: bake
with:
targets: ${{ matrix.targets }}
set: |
*.platform=linux/amd64,linux/arm64
*.output=type=image,name=${{ inputs.registry_name }}/${{ matrix.targets }},name-canonical=true,push=true
*.cache-to=type=local,dest=/tmp/.buildx-cache
*.cache-from=type=local,src=/tmp/.buildx-cache
env:
VERSION: ${{ inputs.image_tag }}
BUILD_TIMESTAMP: ${{ needs.prepare-build.outputs.timestamp }}
COMMIT_HASH: ${{ github.sha }}
DOCKER_REGISTRY: ${{ inputs.registry_name }}
SUFFIX: ${{ inputs.suffix }}
DOCKER_TAG: ${{ inputs.image_tag }}
BUILD_OPTS: -tags=exclude_graphdriver_btrfs,exclude_graphdriver_devicemapper
101 changes: 101 additions & 0 deletions .github/workflows/build-and-upload-components.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Build and Upload Components

on:
workflow_call:
inputs:
image_tag:
required: true
type: string
description: 'Image tag to use.'
registry_name:
required: false
type: string
description: 'Name of the registry.'
default: openclarity.io
bake-group:
required: false
type: string
description: 'Name of the Docker Bake group of targets'
default: default

jobs:
prepare-build:
runs-on: ubuntu-latest
outputs:
timestamp: ${{ steps.timestamp.outputs.timestamp }}
targets: ${{ steps.targets.outputs.targets }}
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Set timestamp
id: timestamp
run: |
##
## Set timestamp variable
##
echo "timestamp=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
- name: List targets
id: targets
uses: docker/bake-action/subaction/list-targets@7a5dfed3550ca014665af2a27af8fc9d7284b9b3 # v4.5.0
with:
target: ${{ inputs.bake-group }}

build-and-upload:
needs: prepare-build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
targets: ${{ fromJson(needs.prepare-build.outputs.targets) }}
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0

- name: Cache Docker layers
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.ref }}
restore-keys: ${{ runner.os }}-buildx-

- name: Build
uses: docker/bake-action@7a5dfed3550ca014665af2a27af8fc9d7284b9b3 # v4.5.0
id: bake
with:
targets: ${{ matrix.targets }}
set: |
*.platform=linux/amd64
*.output=type=docker,dest=/tmp/${{ matrix.targets }}.tar
*.cache-to=type=local,dest=/tmp/.buildx-cache
*.cache-from=type=local,src=/tmp/.buildx-cache
env:
VERSION: ${{ inputs.image_tag }}
BUILD_TIMESTAMP: ${{ needs.prepare-build.outputs.timestamp }}
COMMIT_HASH: ${{ github.sha }}
DOCKER_REGISTRY: ${{ inputs.registry_name }}
DOCKER_TAG: ${{ inputs.image_tag }}
BUILD_OPTS: -tags=exclude_graphdriver_btrfs,exclude_graphdriver_devicemapper

- name: Save artifact
run: |
mkdir -p /tmp/artifacts
mv "/tmp/${{ matrix.targets }}.tar" /tmp/artifacts/
ARTIFACT_NAME="$(echo ${{ matrix.targets }}-${{ inputs.image_tag }} | tr '/' '-')"
echo ARTIFACT_NAME="$ARTIFACT_NAME" >> "$GITHUB_ENV"
- name: Upload artifact
id: upload-artifacts
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: ${{ env.ARTIFACT_NAME }}
path: /tmp/artifacts/${{ matrix.targets }}.tar
if-no-files-found: error
retention-days: 1
compression-level: 0
overwrite: true
2 changes: 1 addition & 1 deletion .github/workflows/cache-cleanup.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
name: Cache Cleanup

name: Cache cleanup
on:
pull_request:
types:
Expand Down
Loading

0 comments on commit 3adddf7

Please sign in to comment.