Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor image publishing and PR validation workflows #43

Merged
merged 38 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
74a4cc8
Add ansible-builder configuration and Github Action workflows for ima…
wmudge Mar 8, 2023
3b22898
Update subworkflow to streamline build contexts
wmudge Mar 8, 2023
a698f28
Disable legacy publishing workflow
wmudge Mar 8, 2023
fff62c9
Create explicit workflow matrix for publishing images
wmudge Mar 8, 2023
9175a66
Update builder.sh script to segment context folders
wmudge Mar 8, 2023
27cc0b9
Update and add execution profiles
wmudge Mar 8, 2023
8294ca5
Update gitignore for pytest caches
wmudge Mar 8, 2023
2f07049
Add deprecation note
wmudge Mar 8, 2023
1905760
Update documentation for latest build process
wmudge Mar 8, 2023
411a630
Update validation workflow to latest build process
wmudge Mar 8, 2023
714e770
Remove legacy build workflow
wmudge Mar 8, 2023
647a506
Add workflow_dispatch trigger
wmudge Mar 8, 2023
3170c1c
Fix quote
wmudge Mar 8, 2023
b061b51
Update matrix variable
wmudge Mar 8, 2023
5b4e6d5
Change working directory for ansible-builder build command
wmudge Mar 8, 2023
f7471ac
Copy contents of source context folder
wmudge Mar 8, 2023
0df2cea
Set context directory to matrix variable
wmudge Mar 8, 2023
0ff230b
Set CWD for buildah action
wmudge Mar 8, 2023
92fe0e3
Remove invalid working-directory parameter
wmudge Mar 8, 2023
807efea
Add debugging to context creation step
wmudge Mar 8, 2023
7335ec6
Add context folder to buildah action
wmudge Mar 8, 2023
8f9840f
Set explicit context directory
wmudge Mar 8, 2023
748507c
Remove default context folder
wmudge Mar 8, 2023
21d1000
Move PR recording to a dependent step
wmudge Mar 8, 2023
36269dc
Add label and reset PR workflows
wmudge Mar 8, 2023
a1277e1
Unset fail-fast and label artifacts by matrix parameter
wmudge Mar 8, 2023
6d086df
Rebuild and rename individual build and publish subworkflow
wmudge Mar 8, 2023
1ddef1d
Rework image publisher to use a matrix
wmudge Mar 8, 2023
eaefd03
Fix invalid input reference
wmudge Mar 8, 2023
4286eb2
Update to use latest build-and-push subworkflow
wmudge Mar 8, 2023
ec8b2ba
Add global tag prefix
wmudge Mar 8, 2023
e892753
Update global tag prefix to have a separator
wmudge Mar 8, 2023
c29ce7f
Add prefix to latest tag and to SHA tag
wmudge Mar 8, 2023
eb88283
Remove working directory from summary step
wmudge Mar 8, 2023
9aa973e
Remove redundant usage docs
wmudge Mar 8, 2023
e3a50ea
Fix invalid ansible role list request
wmudge Mar 8, 2023
ddbe6c3
Add summary for Python and libraries
wmudge Mar 8, 2023
d342a96
Move Python library summary and remove extraneous Python version report
wmudge Mar 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions .github/workflows/build_push_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
# See https://github.com/cloin/ee-builds

name: Build and push Execution Environment image to Packages

on:
workflow_call:
inputs:
BRANCH:
description: 'Upstream collections branch'
required: true
type: string
PROFILE:
description: 'Execution profile'
required: true
type: string
outputs:
image-paths:
description: 'all the constructed and pushed image paths'
value: ${{ jobs.build-push.outputs.registry-paths }}
image-sha:
description: 'the SHA tagged image path'
value: ghcr.io/${{ github.repository }}:sha-${{ jobs.build-push.outputs.sha-short }}

permissions:
contents: read
packages: write

jobs:
build-push:
runs-on: ubuntu-latest
outputs:
sha-short: ${{ steps.sha.outputs.sha-short }}
registry-paths: ${{ steps.push-image.outputs.registry-paths }}
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install ansible-builder
run: pip install ansible-builder==1.2.0

- name: Construct image metadata
id: meta
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/${{ github.repository }}
flavor: |
latest=auto
prefix=${{ inputs.PROFILE }}-,onlatest=true
tags: |
type=sha,prefix=${{ inputs.PROFILE }}-sha-
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}

- name: Construct short SHA
id: sha
run: echo "sha-short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Set up context
run: |
mkdir -p ${{ inputs.PROFILE }}
cp -R builder/${{ inputs.BRANCH }}/* ${{ inputs.PROFILE }}
cp builder/ee-${{ inputs.PROFILE }}.yml ${{ inputs.PROFILE }}/execution-environment.yml
cp -R builder/env builder/inventory builder/repo builder/bashrc ${{ inputs.PROFILE }}

- name: Create Containerfile
run: |
ansible-builder create --context ${{ inputs.PROFILE }} --file ${{ inputs.PROFILE }}/execution-environment.yml

- name: Build image from context
uses: redhat-actions/buildah-build@v2
with:
context: ${{ inputs.PROFILE }}
image: ${{ github.repository }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
containerfiles: |
${{ inputs.PROFILE }}/Containerfile

- name: Push image
id: push-image
uses: redhat-actions/push-to-registry@v2
with:
tags: ${{ steps.meta.outputs.tags }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Print summary
working-directory: ${{ inputs.PROFILE }}
run: |
echo "## :rocket: Usage" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Image pushed to repository: [${{ steps.push-image.outputs.registry-path }}](https://${{ steps.push-image.outputs.registry-path }})" >> $GITHUB_STEP_SUMMARY
echo "> \`podman pull ${{ steps.push-image.outputs.registry-path }}\`" >> $GITHUB_STEP_SUMMARY
echo "## :pushpin: Ansible info:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "`podman run ${{ steps.push-image.outputs.registry-path }} ansible --version`" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "## :pushpin: Installed Python libraries:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "`podman run ${{ steps.push-image.outputs.registry-path }} pip freeze | sort`" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "## :pushpin: Installed collections:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "`podman run ${{ steps.push-image.outputs.registry-path }} ansible-galaxy collection list`" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "## :pushpin: Installed roles:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "`podman run ${{ steps.push-image.outputs.registry-path }} ansible-galaxy role list`" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "## :pushpin: Containerfile:" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "`cat Containerfile`" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
54 changes: 54 additions & 0 deletions .github/workflows/label_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
# See https://securitylab.github.com/research/github-actions-preventing-pwn-requests/

name: Label validated Pull Request

on:
workflow_run:
workflows: ["Validate Pull Request"]
types:
- completed

jobs:
label:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: Download the PR number artifact
uses: actions/github-script@v6
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr_number"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_number.zip`, Buffer.from(download.data));

- name: 'Unzip artifact'
run: unzip pr_number.zip

- name: Read the PR number
id: read
run: echo "pr_number=$(cat pr_number)" >> $GITHUB_OUTPUT

- name: Label the PR
uses: actions-ecosystem/action-add-labels@v1
with:
labels: validated
number: ${{ steps.read.outputs.pr_number }}
28 changes: 28 additions & 0 deletions .github/workflows/publish_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---

name: Publish a single Execution Environment image

on:
workflow_dispatch:
inputs:
BRANCH:
description: 'Upstream collections branch'
default: 'main'
required: false
type: string
PROFILE:
description: 'Execution profile'
default: 'base'
required: false
type: string

permissions:
contents: read
packages: write

jobs:
publish:
uses: ./.github/workflows/build_push_image.yml
with:
BRANCH: ${{ inputs.BRANCH }}
PROFILE: ${{ inputs.PROFILE }}
119 changes: 0 additions & 119 deletions .github/workflows/publish_image_github_packages.yml

This file was deleted.

22 changes: 22 additions & 0 deletions .github/workflows/publish_images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---

name: Publish Execution Environment images

on:
release:
types: [published]

permissions:
contents: read
packages: write

jobs:
publish:
uses: ./.github/workflows/build_push_image.yml
strategy:
fail-fast: false
matrix:
ee_profile: ["full", "base", "aws", "azure", "gcp"]
with:
BRANCH: main
PROFILE: ${{ matrix.ee_profile }}
26 changes: 26 additions & 0 deletions .github/workflows/reset_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---

name: Reset Pull Request validation label

on:
pull_request_target:
types:
- reopened
- synchronize
- ready_for_review
branches:
- 'release/**'
- 'devel'
- 'devel-pvc-base'

jobs:
reset:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Reset the PR label
uses: actions-ecosystem/action-remove-labels@v1
with:
labels: validated
Loading