chore: fixing (#1437)

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
This commit is contained in:
Alex Jones 2025-04-08 08:36:39 +01:00 committed by GitHub
parent 0c63044254
commit f68ff0efee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,13 +8,16 @@ on:
pull_request: pull_request:
branches: branches:
- 'main' - 'main'
- fix/build-branch
- '[0-9]+.[1-9][0-9]*.x' - '[0-9]+.[1-9][0-9]*.x'
paths-ignore: paths-ignore:
- "**.md" - "**.md"
env: env:
GO_VERSION: "~1.22" GO_VERSION: "~1.23"
IMAGE_NAME: "k8sgpt" IMAGE_NAME: "k8sgpt"
REGISTRY_IMAGE: ghcr.io/k8sgpt-ai/k8sgpt
defaults: defaults:
run: run:
shell: bash shell: bash
@ -33,7 +36,7 @@ jobs:
steps: steps:
- name: Check out code - name: Check out code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 uses: actions/checkout@v4
- name: Extract branch name - name: Extract branch name
id: extract_branch id: extract_branch
@ -51,101 +54,61 @@ jobs:
id: get_run_type id: get_run_type
run: | run: |
NON_FORKED_AND_NON_ROBOT_RUN=${{ ( github.actor != 'renovate[bot]' && github.actor != 'dependabot[bot]' ) && ( github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository ) }} NON_FORKED_AND_NON_ROBOT_RUN=${{ ( github.actor != 'renovate[bot]' && github.actor != 'dependabot[bot]' ) && ( github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository ) }}
echo "github.actor != 'renovate[bot]' = ${{ github.actor != 'renovate[bot]' }}"
echo "github.actor != 'dependabot[bot]' = ${{ github.actor != 'dependabot[bot]' }}"
echo "github.event_name == 'push' = ${{ github.event_name == 'push' }}"
echo "github.event.pull_request.head.repo.full_name == github.repository = ${{ github.event.pull_request.head.repo.full_name == github.repository }}"
echo "NON_FORKED_AND_NON_ROBOT_RUN = $NON_FORKED_AND_NON_ROBOT_RUN"
echo "NON_FORKED_AND_NON_ROBOT_RUN=$NON_FORKED_AND_NON_ROBOT_RUN" >> "$GITHUB_OUTPUT" echo "NON_FORKED_AND_NON_ROBOT_RUN=$NON_FORKED_AND_NON_ROBOT_RUN" >> "$GITHUB_OUTPUT"
build_image: build-and-push:
name: Build Container Image name: Build and Push Multi-arch Image
needs: prepare_ci_run needs: prepare_ci_run
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: ${{ needs.prepare_ci_run.outputs.NON_FORKED_AND_NON_ROBOT_RUN == 'true' }}
env: env:
BRANCH: ${{ needs.prepare_ci_run.outputs.BRANCH }}
DATETIME: ${{ needs.prepare_ci_run.outputs.DATETIME }} DATETIME: ${{ needs.prepare_ci_run.outputs.DATETIME }}
BUILD_TIME: ${{ needs.prepare_ci_run.outputs.BUILD_TIME }} BUILD_TIME: ${{ needs.prepare_ci_run.outputs.BUILD_TIME }}
GIT_SHA: ${{ needs.prepare_ci_run.outputs.GIT_SHA }} GIT_SHA: ${{ needs.prepare_ci_run.outputs.GIT_SHA }}
RELEASE_REGISTRY: "localhost:5000/k8sgpt"
steps: steps:
- name: Check out code - name: Check out code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 uses: actions/checkout@v4
- name: Set up Docker Buildx - name: Docker meta
id: buildx id: meta
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3 uses: docker/metadata-action@v5
- name: Build Docker Image
uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6
with: with:
context: . images: ${{ env.REGISTRY_IMAGE }}
platforms: linux/amd64
file: ./container/Dockerfile
target: production
tags: | tags: |
${{ env.RELEASE_REGISTRY }}/${{ env.IMAGE_NAME }}:dev-${{ env.DATETIME }} type=ref,event=branch
secrets: | type=ref,event=pr
GIT_AUTH_TOKEN=${{ secrets.K8SGPT_BOT_SECRET }} type=semver,pattern={{version}}
build-args: | type=semver,pattern={{major}}.{{minor}}
GIT_HASH=${{ env.GIT_SHA }} type=raw,value=dev-${{ env.DATETIME }}
RELEASE_VERSION=dev-${{ env.DATETIME }}
BUILD_TIME=${{ env.BUILD_TIME }}
builder: ${{ steps.buildx.outputs.name }}
push: false
cache-from: type=gha,scope=${{ github.ref_name }}-${{ env.IMAGE_NAME }}
cache-to: type=gha,scope=${{ github.ref_name }}-${{ env.IMAGE_NAME }}
outputs: type=docker,dest=/tmp/${{ env.IMAGE_NAME }}-image.tar
- name: Upload image as artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: ${{ env.IMAGE_NAME }}-image.tar
path: /tmp/${{ env.IMAGE_NAME }}-image.tar
upload_images:
name: Upload images to ghcr registry
needs: [ prepare_ci_run, build_image ]
if: github.event_name == 'push' && needs.prepare_ci_run.outputs.NON_FORKED_AND_NON_ROBOT_RUN == 'true' # only run on push to main/maintenance branches
runs-on: ubuntu-latest
env:
DATETIME: ${{ needs.prepare_ci_run.outputs.DATETIME }}
BUILD_TIME: ${{ needs.prepare_ci_run.outputs.BUILD_TIME }}
GIT_SHA: ${{ needs.prepare_ci_run.outputs.GIT_SHA }}
permissions:
packages: write # Needed for pushing images to the registry
contents: read # Needed for checking out the repository
steps:
- name: Check out code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Login to GitHub Container Registry - name: Login to GitHub Container Registry
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3 uses: docker/login-action@v3
with: with:
registry: "ghcr.io" registry: ghcr.io
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.K8SGPT_BOT_SECRET }} password: ${{ secrets.K8SGPT_BOT_SECRET }}
- name: Set up Docker Buildx - name: Set up QEMU
id: buildx uses: docker/setup-qemu-action@v3
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3
- name: Build Docker Image - name: Set up Docker Buildx
uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6 uses: docker/setup-buildx-action@v3
- name: Build and push multi-arch image
uses: docker/build-push-action@v6
with: with:
context: . context: .
file: ./container/Dockerfile file: ./container/Dockerfile
platforms: linux/amd64,linux/arm64 platforms: linux/amd64,linux/arm64
push: true
target: production target: production
tags: |
ghcr.io/k8sgpt-ai/${{ env.IMAGE_NAME }}:dev-${{ env.DATETIME }}
secrets: |
GIT_AUTH_TOKEN=${{ secrets.K8SGPT_BOT_SECRET }}
build-args: | build-args: |
GIT_HASH=${{ env.GIT_SHA }} GIT_HASH=${{ env.GIT_SHA }}
RELEASE_VERSION=dev-${{ env.DATETIME }} RELEASE_VERSION=dev-${{ env.DATETIME }}
BUILD_TIME=${{ env.BUILD_TIME }} BUILD_TIME=${{ env.BUILD_TIME }}
builder: ${{ steps.buildx.outputs.name }} tags: |
push: true ${{ env.REGISTRY_IMAGE }}:${{ env.DATETIME }}
cache-from: type=gha,scope=${{ github.ref_name }}-${{ env.IMAGE_NAME }} labels: ${{ steps.meta.outputs.labels }}
cache-to: type=gha,scope=${{ github.ref_name }}-${{ env.IMAGE_NAME }} secrets: |
GIT_AUTH_TOKEN=${{ secrets.K8SGPT_BOT_SECRET }}