Skip to content
130 changes: 130 additions & 0 deletions .github/workflows/build-images-on-PR.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: Build Images on PR
on:
pull_request:
paths-ignore:
- "LICENSE"
- "**/.gitignore"
- "**.md"
- "**.adoc"
- "*.txt"
types: [labeled, opened, synchronize, reopened]
jobs:
build-and-push-ci:
if: github.repository == 'trustyai-explainability/trustyai-service-operator'
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
pull-requests: write
steps: # Assign context variable for various action contexts (only 'CI', to guard against potential 'on:' additions later)
- name: Assigning CI context
if: github.head_ref != '' && github.head_ref != 'main' && !startsWith(github.ref, 'refs/tags/v')
run: echo "BUILD_CONTEXT=ci" >> $GITHUB_ENV

# Run checkouts
- uses: mheap/github-action-required-labels@v4
if: env.BUILD_CONTEXT == 'ci'
with:
mode: minimum
count: 1
labels: "ok-to-test, lgtm, approved"
- uses: actions/checkout@v4
if: env.BUILD_CONTEXT == 'ci'
with:
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
#
# Set environments depending on context
- name: Set CI environment
if: env.BUILD_CONTEXT == 'ci'
run: |
echo "OPERATOR_TAG=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
echo "IMAGE_NAME=quay.io/trustyai/trustyai-service-operator-ci" >> $GITHUB_ENV
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Outdated
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

- name: Set CI environment - LMES
if: env.BUILD_CONTEXT == 'ci' && contains(github.event.pull_request.labels.*.name, 'needs-lmes-build')
run: |
echo "LMES_DRIVER_TAG=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
echo "LMES_JOB_TAG=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
echo "LMES_DRIVER_IMAGE_NAME=quay.io/trustyai/ta-lmes-driver-ci" >> $GITHUB_ENV
echo "LMES_JOB_IMAGE_NAME=quay.io/trustyai/ta-lmes-job-ci" >> $GITHUB_ENV

- name: Set CI environment - Orchestrator
if: env.BUILD_CONTEXT == 'ci' && contains(github.event.pull_request.labels.*.name, 'needs-orchestrator-build')
run: |
echo "ORCH_IMAGE_NAME=quay.io/trustyai/ta-guardrails-orchestrator-ci" >> $GITHUB_ENV
echo "ORCH_TAG=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV

# Print variables for debugging
- name: Log reference variables
run: |
echo "CONTEXT: ${{ env.BUILD_CONTEXT }}"
echo "GITHUB.REF: ${{ github.ref }}"
echo "GITHUB.HEAD_REF: ${{ github.head_ref }}"
echo "SHA: ${{ github.event.pull_request.head.sha }}"
echo "MAIN IMAGE AT: ${{ env.OPERATOR_IMAGE_NAME }}:${{ env.OPERATOR_TAG }}"
echo "LMES DRIVER IMAGE AT: ${{ env.LMES_DRIVER_IMAGE_NAME }}:${{ env.LMES_DRIVER_TAG }}"
echo "LMES JOB IMAGE AT: ${{ env.LMES_JOB_IMAGE_NAME }}:${{ env.LMES_JOB_TAG }}"
echo "GUARDRAILS ORCH IMAGE AT: ${{ env.ORCH_IMAGE_NAME }}:${{ env.ORCH_TAG }}"
Comment thread
coderabbitai[bot] marked this conversation as resolved.

# Run docker commands
- name: Put expiry date on CI-tagged image
if: env.BUILD_CONTEXT == 'ci'
run: sed -i 's#summary="odh-trustyai-service-operator\"#summary="odh-trustyai-service-operator" \\ \n quay.expires-after=7d#' Dockerfile
- name: Log in to Quay
run: docker login -u ${{ secrets.QUAY_ROBOT_USERNAME }} -p ${{ secrets.QUAY_ROBOT_SECRET }} quay.io
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
- name: Build main image
run: docker build -t ${{ env.OPERATOR_IMAGE_NAME }}:${{ env.OPERATOR_TAG }} .
- name: Push main image to Quay
run: docker push ${{ env.OPERATOR_IMAGE_NAME }}:${{ env.OPERATOR_TAG }}

# LMES Driver Builds
- name: Build LMES driver image
if: contains(github.event.pull_request.labels.*.name, 'needs-lmes-build') || env.BUILD_CONTEXT == 'main' || env.BUILD_CONTEXT == 'tag'
run: docker build -f Dockerfile.driver -t ${{ env.LMES_DRIVER_IMAGE_NAME }}:${{ env.LMES_DRIVER_TAG }} .
- name: Push LMES driver image to Quay
if: contains(github.event.pull_request.labels.*.name, 'needs-lmes-build') || env.BUILD_CONTEXT == 'main' || env.BUILD_CONTEXT == 'tag'
run: docker push ${{ env.LMES_DRIVER_IMAGE_NAME }}:${{ env.LMES_DRIVER_TAG }}

# LMES Job Builds
- name: Build LMES job image
if: contains(github.event.pull_request.labels.*.name, 'needs-lmes-build') || env.BUILD_CONTEXT == 'main' || env.BUILD_CONTEXT == 'tag'
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Outdated
run: docker build -f Dockerfile.lmes-job -t ${{ env.LMES_JOB_IMAGE_NAME }}:${{ env.LMES_JOB_TAG }} .
- name: Push LMES job image to Quay
if: contains(github.event.pull_request.labels.*.name, 'needs-lmes-build') || env.BUILD_CONTEXT == 'main' || env.BUILD_CONTEXT == 'tag'
run: docker push ${{ env.LMES_JOB_IMAGE_NAME }}:${{ env.LMES_JOB_TAG }}

# Orchestrator Builds
- name: Build Guardrails orchestrator image
if: contains(github.event.pull_request.labels.*.name, 'needs-orchestrator-build') || env.BUILD_CONTEXT == 'main' || env.BUILD_CONTEXT == 'tag'
run: docker build -f Dockerfile.orchestrator -t ${{ env.ORCH_IMAGE_NAME }}:${{ env.ORCH_TAG }} .
- name: Push Guardrails orchestrator image to Quay
if: contains(github.event.pull_request.labels.*.name, 'needs-orchestrator-build') || env.BUILD_CONTEXT == 'main' || env.BUILD_CONTEXT == 'tag'
run: docker push ${{ env.ORCH_IMAGE_NAME }}:${{ env.ORCH_TAG }}

# Leave comment
- uses: peter-evans/find-comment@v3
name: Find Comment
id: fc
if: env.BUILD_CONTEXT == 'ci'
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: PR image build and manifest generation completed successfully
- uses: peter-evans/create-or-update-comment@v4
name: Generate/update success message comment
if: env.BUILD_CONTEXT == 'ci'
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body: |
PR image build and manifest generation completed successfully!

📦 [PR image](https://${{ env.OPERATOR_IMAGE_NAME }}:${{ env.OPERATOR_TAG }}): `${{ env.OPERATOR_IMAGE_NAME }}:${{ env.OPERATOR_TAG }}`

📦 [LMES driver image](https://${{ env.LMES_DRIVER_IMAGE_NAME }}:${{ env.LMES_DRIVER_TAG }}): `${{ env.LMES_DRIVER_IMAGE_NAME }}:${{ env.LMES_DRIVER_TAG }}`

📦 [LMES job image](https://${{ env.LMES_JOB_IMAGE_NAME }}:${{ env.LMES_JOB_TAG }}): `${{ env.LMES_JOB_IMAGE_NAME }}:${{ env.LMES_JOB_TAG }}`

📦 [Guardrails orchestrator image](https://${{ env.ORCH_IMAGE_NAME }}:${{ env.ORCH_TAG }}): `${{ env.ORCH_IMAGE_NAME }}:${{ env.ORCH_TAG }}`
Comment thread
tarilabs marked this conversation as resolved.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Comment thread
tarilabs marked this conversation as resolved.
Loading