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

Push PR image #185

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
48 changes: 44 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Build

permissions:
contents: read
packages: write

on:
push:
branches:
Expand Down Expand Up @@ -38,6 +42,19 @@ jobs:
if: github.event_name == 'release'
run: echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Get merge request latest commit
if: ${{ github.event_name == 'pull_request' }}
id: parse-commit-sha
run: |
head=$(git rev-parse HEAD)
echo "head_commit_sha=${head}" >> $GITHUB_ENV
echo "Head commit sha ${head}"

- name: Secret Scanning
uses: trufflesecurity/trufflehog@main
with:
extra_args: --only-verified

- name: Build Go binary amd64
run: go build -ldflags "-s -w -X main.GitCommit=$GITHUB_SHA -X main.GitRef=$GITHUB_REF -X main.Version=${RELEASE_TAG:-commit-$GITHUB_SHA}" -o bin/castai-agent-amd64 .
env:
Expand All @@ -56,19 +73,36 @@ jobs:
run: go test -race ./...

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Login to Google Artifact Registry
if: github.event_name == 'release'
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: us-docker.pkg.dev
username: _json_key
password: ${{ secrets.ARTIFACT_BUILDER_JSON_KEY }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
if: ${{ github.event_name == 'pull_request' }}
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push pr
if: ${{ github.event_name == 'pull_request' }}
uses: docker/build-push-action@v3
with:
context: .
push: true
platforms: linux/arm64,linux/amd64
tags: ghcr.io/castai/k8s-agent:${{ env.head_commit_sha }}

- name: Build and push main
if: github.event_name != 'release'
uses: docker/build-push-action@v3
Expand Down Expand Up @@ -141,4 +175,10 @@ jobs:
with:
files: |
bin/castai-agent-amd64
bin/castai-agent-arm64
bin/castai-agent-arm64

- name: Summary
if: ${{ github.event_name == 'pull_request' }}
run: |
echo "**Pushed docker images:**" >> $GITHUB_STEP_SUMMARY
echo "ghcr.io/castai/k8s-agent:${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
Loading