Skip to content

Commit

Permalink
combining tags and use combined tags
Browse files Browse the repository at this point in the history
Signed-off-by: greg pereira <[email protected]>
  • Loading branch information
Gregory-Pereira committed Nov 12, 2024
1 parent a9c4b76 commit fd3ba69
Show file tree
Hide file tree
Showing 2 changed files with 332 additions and 62 deletions.
128 changes: 113 additions & 15 deletions .github/workflows/pr-images.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
name: Publish container images
name: Publish QA Container Images

on:
push:
branches:
- main
- release-1.0
tags:
- v*

env:
GHCR_REGISTRY: ghcr.io
GHCR_UI_IMAGE_NAME: ${{ github.repository }}/ui
QUAY_REGISTRY: quay.io
QUAY_UI_IMAGE_NAME: instructlab-ui/ui
GHCR_PATHSERVICE_IMAGE_NAME: ${{ github.repository }}/pathservice
QUAY_PATHSERVICE_IMAGE_NAME: instructlab-ui/pathservice
GHCR_PS_IMAGE_NAME: ${{ github.repository }}/pathservice
QUAY_PS_IMAGE_NAME: instructlab-ui/pathservice

jobs:
build_and_publish_ui_image:
build_and_publish_ui_qa_image:
name: Push UI container image to GHCR and QUAY
runs-on: ubuntu-latest
environment: registry-creds
Expand Down Expand Up @@ -56,25 +53,72 @@ jobs:
restore-keys: |
${{ runner.os }}-buildx-
- name: Get Pull Request Number from Commit
id: get_pr_number
uses: actions/github-script@v6
with:
script: |
console.log("Repository owner:", context.repo.owner);
console.log("Repository name:", context.repo.repo);
console.log("Current commit SHA:", context.sha);
const prs = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed',
sort: 'updated',
direction: 'desc'
});
console.log("Number of closed PRs fetched:", prs.data.length);
for (const pr of prs.data) {
console.log("Checking PR #", pr.number, "- Merged:");
if (pr.merged_at != "") {
console.log("Found merged PR:", pr.number);
return pr.number;
}
}
console.log("No merged PR found in the recent closed PRs.");
return '';
- name: Extract metadata (tags, labels) for UI image
id: ghcr_ui_meta
uses: docker/metadata-action@v5
with:
images: ${{ env.GHCR_REGISTRY }}/${{ env.GHCR_UI_IMAGE_NAME }}

- name: Combine GHCR Tags with PR Tag
id: combined_ghcr_ui_tags
if: ${{ steps.get_pr_number.outputs.result }} != ""

Check failure on line 93 in .github/workflows/pr-images.yml

View workflow job for this annotation

GitHub Actions / actionlint

if: condition "${{ steps.get_pr_number.outputs.result }} != \"\"" is always evaluated to true because extra characters are around ${{ }}
run: |

Check failure on line 94 in .github/workflows/pr-images.yml

View workflow job for this annotation

GitHub Actions / actionlint

shellcheck reported issue in this script: SC2086:info:4:40: Double quote to prevent globbing and word splitting
TAGS="${{ steps.ghcr_ui_meta.outputs.tags }}"
PR_TAG="pr-${{ steps.get_pr_number.outputs.result }}"
COMBINED_TAGS="${PR_TAG},${TAGS}"
echo "COMBINED_TAGS=$COMBINED_TAGS" >> $GITHUB_ENV
- name: Extract metadata (tags, labels) for UI image
id: quay_ui_meta
uses: docker/metadata-action@v5
with:
images: ${{ env.QUAY_REGISTRY }}/${{ env.QUAY_UI_IMAGE_NAME }}

- name: Combine GHCR Tags with PR Tag
id: combined_quay_ui_tags
if: ${{ steps.get_pr_number.outputs.result }} != ""

Check failure on line 108 in .github/workflows/pr-images.yml

View workflow job for this annotation

GitHub Actions / actionlint

if: condition "${{ steps.get_pr_number.outputs.result }} != \"\"" is always evaluated to true because extra characters are around ${{ }}
run: |

Check failure on line 109 in .github/workflows/pr-images.yml

View workflow job for this annotation

GitHub Actions / actionlint

shellcheck reported issue in this script: SC2086:info:4:40: Double quote to prevent globbing and word splitting
TAGS="${{ steps.quay_ui_meta.outputs.tags }}"
PR_TAG="pr-${{ steps.get_pr_number.outputs.result }}"
COMBINED_TAGS="${PR_TAG},${TAGS}"
echo "COMBINED_TAGS=$COMBINED_TAGS" >> $GITHUB_ENV
- name: Build and push ui image to ghcr.io
id: push-ui-ghcr
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.ghcr_ui_meta.outputs.tags }}
tags: ${{ steps.combined_ghcr_ui_tags.outputs.COMBINED_TAGS }}
labels: ${{ steps.ghcr_ui_meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
Expand All @@ -94,14 +138,14 @@ jobs:
with:
context: .
push: true
tags: ${{ steps.quay_ui_meta.outputs.tags }}
tags: ${{ steps.combined_quay_ui_tags.outputs.COMBINED_TAGS }}
labels: ${{ steps.quay_ui_meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
file: Containerfile

build_and_publish_pathservice_image:
build_and_publish_ps_qa_image:
name: Push pathservice container image to GHCR and QUAY
runs-on: ubuntu-latest
environment: registry-creds
Expand Down Expand Up @@ -140,25 +184,72 @@ jobs:
restore-keys: |
${{ runner.os }}-buildx-
- name: Get Pull Request Number from Commit
id: get_pr_number
uses: actions/github-script@v6
with:
script: |
console.log("Repository owner:", context.repo.owner);
console.log("Repository name:", context.repo.repo);
console.log("Current commit SHA:", context.sha);
const prs = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed',
sort: 'updated',
direction: 'desc'
});
console.log("Number of closed PRs fetched:", prs.data.length);
for (const pr of prs.data) {
console.log("Checking PR #", pr.number, "- Merged:");
if (pr.merged_at != "") {
console.log("Found merged PR:", pr.number);
return pr.number;
}
}
console.log("No merged PR found in the recent closed PRs.");
return '';
- name: Extract metadata (tags, labels) for pathservice image
id: ghcr_ps_meta
uses: docker/metadata-action@v5
with:
images: ${{ env.GHCR_REGISTRY }}/${{ env.GHCR_PATHSERVICE_IMAGE_NAME }}
images: ${{ env.GHCR_REGISTRY }}/${{ env.GHCR_PS_IMAGE_NAME }}

- name: Combine GHCR Tags with PR Tag
id: combined_ghcr_ps_tags
if: ${{ steps.get_pr_number.outputs.result }} != ""

Check failure on line 224 in .github/workflows/pr-images.yml

View workflow job for this annotation

GitHub Actions / actionlint

if: condition "${{ steps.get_pr_number.outputs.result }} != \"\"" is always evaluated to true because extra characters are around ${{ }}
run: |

Check failure on line 225 in .github/workflows/pr-images.yml

View workflow job for this annotation

GitHub Actions / actionlint

shellcheck reported issue in this script: SC2086:info:4:40: Double quote to prevent globbing and word splitting
TAGS="${{ steps.ghcr_ps_meta.outputs.tags }}"
PR_TAG="pr-${{ steps.get_pr_number.outputs.result }}"
COMBINED_TAGS="${PR_TAG},${TAGS}"
echo "COMBINED_TAGS=$COMBINED_TAGS" >> $GITHUB_ENV
- name: Extract metadata (tags, labels) for pathservice image
id: quay_ps_meta
uses: docker/metadata-action@v5
with:
images: ${{ env.QUAY_REGISTRY }}/${{ env.QUAY_PATHSERVICE_IMAGE_NAME }}
images: ${{ env.QUAY_REGISTRY }}/${{ env.QUAY_PS_IMAGE_NAME }}

- name: Combine GHCR Tags with PR Tag
id: combined_quay_ps_tags
if: ${{ steps.get_pr_number.outputs.result }} != ""

Check failure on line 239 in .github/workflows/pr-images.yml

View workflow job for this annotation

GitHub Actions / actionlint

if: condition "${{ steps.get_pr_number.outputs.result }} != \"\"" is always evaluated to true because extra characters are around ${{ }}
run: |

Check failure on line 240 in .github/workflows/pr-images.yml

View workflow job for this annotation

GitHub Actions / actionlint

shellcheck reported issue in this script: SC2086:info:4:40: Double quote to prevent globbing and word splitting
TAGS="${{ steps.quay_ps_meta.outputs.tags }}"
PR_TAG="pr-${{ steps.get_pr_number.outputs.result }}"
COMBINED_TAGS="${PR_TAG},${TAGS}"
echo "COMBINED_TAGS=$COMBINED_TAGS" >> $GITHUB_ENV
- name: Build and push pathservice image to ghcr.io
id: push-ps-ghcr
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.ghcr_ps_meta.outputs.tags }}
tags: ${{ steps.combined_ghcr_ps_tags.outputs.COMBINED_TAGS }}
labels: ${{ steps.ghcr_ps_meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
Expand All @@ -168,7 +259,7 @@ jobs:
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.GHCR_REGISTRY }}/${{ env.GHCR_PATHSERVICE_IMAGE_NAME}}
subject-name: ${{ env.GHCR_REGISTRY }}/${{ env.GHCR_PS_IMAGE_NAME}}
subject-digest: ${{ steps.push-ps-ghcr.outputs.digest }}
push-to-registry: true

Expand All @@ -178,9 +269,16 @@ jobs:
with:
context: .
push: true
tags: ${{ steps.quay_ps_meta.outputs.tags }}
tags: ${{ steps.combined_ghcr_ps_tags.outputs.COMBINED_TAGS }}
labels: ${{ steps.quay_ps_meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
file: Containerfile.ps

- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.GHCR_REGISTRY }}/${{ env.GHCR_PS_IMAGE_NAME}}
subject-digest: ${{ steps.push-ps-ghcr.outputs.digest }}
push-to-registry: true
Loading

0 comments on commit fd3ba69

Please sign in to comment.