Skip to content
Open
Show file tree
Hide file tree
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
125 changes: 125 additions & 0 deletions .github/workflows/push-to-gar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: Push to GAR

# Triggers when a PR is merged
on:
pull_request:
types: [closed]
branches: [main]

jobs:
# Determine which service to push based on PR labels
determine-service:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
outputs:
service: ${{ steps.detect.outputs.service }}
should_push: ${{ steps.detect.outputs.should_push }}
steps:
- name: Detect service from labels
id: detect
run: |
LABELS='${{ toJSON(github.event.pull_request.labels.*.name) }}'

if echo "$LABELS" | grep -q '"minio"'; then
echo "service=minio" >> "$GITHUB_OUTPUT"
echo "should_push=true" >> "$GITHUB_OUTPUT"
elif echo "$LABELS" | grep -q '"mongodb"'; then
echo "service=mongodb" >> "$GITHUB_OUTPUT"
echo "should_push=true" >> "$GITHUB_OUTPUT"
elif echo "$LABELS" | grep -q '"postgresql"'; then
echo "service=postgresql" >> "$GITHUB_OUTPUT"
echo "should_push=true" >> "$GITHUB_OUTPUT"
elif echo "$LABELS" | grep -q '"kubectl"'; then
echo "service=kubectl" >> "$GITHUB_OUTPUT"
echo "should_push=true" >> "$GITHUB_OUTPUT"
else
echo "service=none" >> "$GITHUB_OUTPUT"
echo "should_push=false" >> "$GITHUB_OUTPUT"
fi

# Push to GAR
push-to-gar:
needs: determine-service
if: needs.determine-service.outputs.should_push == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
env:
GAR_LOCATION: us-east1
GAR_PROJECT_ID: testkube-cloud-372110
GAR_REPOSITORY: testkube
SERVICE: ${{ needs.determine-service.outputs.service }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get version from Chart.yaml
id: version
run: |
VERSION=$(grep "^appVersion:" ${SERVICE}/helm/Chart.yaml | sed 's/appVersion: "//' | sed 's/"//')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "📦 ${SERVICE} version: $VERSION"

- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GKE_SA_KEY_PROD }}

- name: Configure Docker for GAR
run: gcloud auth configure-docker ${{ env.GAR_LOCATION }}-docker.pkg.dev -q

- name: Get Dockerfile name
id: dockerfile
run: |
DOCKERFILE=$(grep "^dockerfile:" ${SERVICE}/service.yaml | sed 's/dockerfile: //')
echo "name=$DOCKERFILE" >> "$GITHUB_OUTPUT"

- name: Build image
run: |
echo "=== Building ${SERVICE} image ==="
docker build -t testkube/${SERVICE}:${{ steps.version.outputs.version }} \
-f ${SERVICE}/${{ steps.dockerfile.outputs.name }} \
${SERVICE}/
echo "✅ Image built: testkube/${SERVICE}:${{ steps.version.outputs.version }}"

- name: Tag for GAR
run: |
GAR_IMAGE="${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GAR_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${SERVICE}"

# Tag with version
docker tag testkube/${SERVICE}:${{ steps.version.outputs.version }} \
${GAR_IMAGE}:${{ steps.version.outputs.version }}

# Tag as latest
docker tag testkube/${SERVICE}:${{ steps.version.outputs.version }} \
${GAR_IMAGE}:latest

echo "✅ Tagged:"
echo " - ${GAR_IMAGE}:${{ steps.version.outputs.version }}"
echo " - ${GAR_IMAGE}:latest"

- name: Push to GAR
run: |
GAR_IMAGE="${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GAR_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${SERVICE}"

echo "=== Pushing to GAR ==="
docker push ${GAR_IMAGE}:${{ steps.version.outputs.version }}
docker push ${GAR_IMAGE}:latest

echo "✅ Pushed successfully!"

- name: Summary
run: |
GAR_IMAGE="${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GAR_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${SERVICE}"

echo "### 🚀 Image Pushed to GAR" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Property | Value |" >> $GITHUB_STEP_SUMMARY
echo "|----------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Service | **${SERVICE}** |" >> $GITHUB_STEP_SUMMARY
echo "| Image | \`${GAR_IMAGE}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Version | \`${{ steps.version.outputs.version }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Tags | \`${{ steps.version.outputs.version }}\`, \`latest\` |" >> $GITHUB_STEP_SUMMARY
echo "| PR | #${{ github.event.pull_request.number }} |" >> $GITHUB_STEP_SUMMARY

Loading