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

Add workflow for devs to create debug images from PRs #115

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Changes from all commits
Commits
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
146 changes: 146 additions & 0 deletions .github/workflows/pr-debug-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: Produce PR dev images (on Request)

on:
workflow_dispatch:
inputs:
pr_number:
description: 'Pull Request Number to build image for'
required: true
type: number

concurrency:
group: prs-${{ github.event.inputs.pr_number }}
cancel-in-progress: true

env:
GHCR_REGISTRY: ghcr.io
REGISTRY: docker.io
IMAGE_NAME: ${{ github.repository }}
YQ_VERSION: v4.44.3
GH_TOKEN: ${{ github.token }}

jobs:
push-dev-images:
name: Build and push helm-locker & Helm-Project-Operator images
runs-on: ${{ github.repository == 'rancher/prometheus-federator' && format('runs-on,image=ubuntu22-full-x64,runner=4cpu-linux-x64,run-id={1}', github.run_id) || 'ubuntu-latest' }}
permissions:
contents: read
packages: write
attestations: write
id-token: write
pull-requests: write
steps:
# Checkout the code at the head of the specified PR
- name: Checkout the repository
uses: actions/checkout@v3
- name: Get Pull Request Head SHA
id: get_head_sha
run: |
pr_number=${{ github.event.inputs.pr_number }}
echo "Fetching details for PR #$pr_number"
pr_response=$(gh api repos/${{ github.repository }}/pulls/$pr_number)
head_sha=$(echo "$pr_response" | jq -r '.head.sha')
echo "::set-output name=head_sha::$head_sha"
- name: Checkout PR Head
uses: actions/checkout@v3
with:
ref: ${{ steps.get_head_sha.outputs.head_sha }}
# Proceed to build images
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.GHCR_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for helm-locker image
id: meta-helm-locker
uses: docker/metadata-action@v5
with:
images: ${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}/helm-locker
tags: |
type=sha,prefix=pr-${{ github.event.inputs.pr_number }}-
type=raw,value=pr-${{ github.event.inputs.pr_number }}
- name: Build and push helm-locker image
id: push
uses: docker/build-push-action@v5
with:
context: .
file: ./package/Dockerfile-helm-locker
push: true
tags: ${{ steps.meta-helm-locker.outputs.tags }}
labels: ${{ steps.meta-helm-locker.outputs.labels }}
platforms : linux/amd64,linux/arm64
- name: Extract metadata (tags, labels) for Helm-Project-Operator image
id: meta-helm-project-operator
uses: docker/metadata-action@v5
with:
images: ${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}/helm-project-operator
tags: |
type=sha,prefix=pr-${{ github.event.inputs.pr_number }}-
type=raw,value=pr-${{ github.event.inputs.pr_number }}
- name: Build Helm-Project-Operator image
uses: docker/build-push-action@v5
with:
context: .
file: ./package/Dockerfile-helm-project-operator
push: true
tags: ${{ steps.meta-helm-project-operator.outputs.tags }}
labels: ${{ steps.meta-helm-project-operator.outputs.labels }}
platforms: linux/amd64,linux/arm64
- name: Extract metadata (tags, labels) for Prometheus Federator image
id: meta-prometheus-federator
uses: docker/metadata-action@v5
with:
images: ${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,prefix=pr-${{ github.event.inputs.pr_number }}-
type=raw,value=pr-${{ github.event.inputs.pr_number }}
- name: Build Prometheus Federator image
uses: docker/build-push-action@v5
with:
context: .
file: ./package/Dockerfile-prometheus-federator
push: true
tags: ${{ steps.meta-prometheus-federator.outputs.tags }}
labels: ${{ steps.meta-prometheus-federator.outputs.labels }}
platforms: linux/amd64,linux/arm64

- name: Comment on PR with image details
uses: actions/github-script@v6
env:
meta-helm-locker: ${{ steps.meta-helm-locker.outputs.tags }}
meta-helm-project-operator: ${{ steps.meta-helm-project-operator.outputs.tags }}
meta-prometheus-federator: ${{ steps.meta-prometheus-federator.outputs.tags }}
with:
script: |
const prNumber = context.payload.inputs.pr_number;
const images = [
{
name: 'Helm Locker',
key: 'meta-helm-locker',
url: `https://github.com/${{ github.repository }}/pkgs/container/prometheus-federator%2Fhelm-locker`
},
{
name: 'Helm Project Operator',
key: 'meta-helm-project-operator',
url: `https://${process.env.GHCR_REGISTRY}/${{ github.repository }}/pkgs/container/prometheus-federator%2Fhelm-project-operator`
},
{
name: 'Prometheus Federator',
key: 'meta-prometheus-federator',
url: `https://${process.env.GHCR_REGISTRY}/${{ github.repository }}/pkgs/container/prometheus-federator`
}
];
const commentBody = images
.map(image => `- **${image.name}**: [Link to image](${image.url}):\n Tags: \`${process.env[image.key]}\``)
.join('\n\n');1
github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: `### Images built for PR #${prNumber}:\n\n${commentBody}`
});
Loading