Skip to content
Closed
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
75 changes: 75 additions & 0 deletions .github/workflows/ibm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# This workflow will build a docker container, publish it to IBM Container Registry, and deploy it to IKS when there is a push to the "master" branch.
#
# To configure this workflow:
#
# 1. Ensure that your repository contains a Dockerfile
# 2. Setup secrets in your repository by going to settings: Create ICR_NAMESPACE and IBM_CLOUD_API_KEY
# 3. Change the values for the IBM_CLOUD_REGION, REGISTRY_HOSTNAME, IMAGE_NAME, IKS_CLUSTER, DEPLOYMENT_NAME, and PORT

name: Build and Deploy to IKS

on:
push:
branches: [ "master" ]

# Environment variables available to all jobs and steps in this workflow
env:
GITHUB_SHA: ${{ github.sha }}
IBM_CLOUD_API_KEY: ${{ secrets.IBM_CLOUD_API_KEY }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 security Cloud key has workflow scope

The IBM Cloud API key is exposed to every step, including the mutable checkout action and unverified installer and plugin code that execute before authentication; scope it to the authentication step to reduce the credential-exfiltration surface.

How this was verified: The workflow-level secret is available to the checkout and installer steps before it is consumed for IBM Cloud authentication.

Prompt To Fix With AI
This is a comment left during a code review.
Path: .github/workflows/ibm.yml
Line: 18

Comment:
**Cloud key has workflow scope**

The IBM Cloud API key is exposed to every step, including the mutable checkout action and unverified installer and plugin code that execute before authentication; scope it to the authentication step to reduce the credential-exfiltration surface.

**How this was verified:** The workflow-level secret is available to the checkout and installer steps before it is consumed for IBM Cloud authentication.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

IBM_CLOUD_REGION: us-south
ICR_NAMESPACE: ${{ secrets.ICR_NAMESPACE }}
REGISTRY_HOSTNAME: us.icr.io
IMAGE_NAME: iks-test
IKS_CLUSTER: example-iks-cluster-name-or-id

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Placeholder cluster blocks deployment

When the deployment step runs, it passes the literal template value example-iks-cluster-name-or-id to ibmcloud ks cluster config, causing cluster configuration to fail before the Kubernetes resources are applied.

Prompt To Fix With AI
This is a comment left during a code review.
Path: .github/workflows/ibm.yml
Line: 23

Comment:
**Placeholder cluster blocks deployment**

When the deployment step runs, it passes the literal template value `example-iks-cluster-name-or-id` to `ibmcloud ks cluster config`, causing cluster configuration to fail before the Kubernetes resources are applied.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

DEPLOYMENT_NAME: iks-test
PORT: 5001

jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
environment: production
steps:

- name: Checkout
uses: actions/checkout@v4

# Download and Install IBM Cloud CLI
- name: Install IBM Cloud CLI
run: |
curl -fsSL https://clis.cloud.ibm.com/install/linux | sh
ibmcloud --version
ibmcloud config --check-version=false
ibmcloud plugin install -f kubernetes-service
ibmcloud plugin install -f container-registry

# Authenticate with IBM Cloud CLI
- name: Authenticate with IBM Cloud CLI
run: |
ibmcloud login --apikey "${IBM_CLOUD_API_KEY}" -r "${IBM_CLOUD_REGION}" -g default
ibmcloud cr region-set "${IBM_CLOUD_REGION}"
ibmcloud cr login

# Build the Docker image
- name: Build with Docker
run: |
docker build -t "$REGISTRY_HOSTNAME"/"$ICR_NAMESPACE"/"$IMAGE_NAME":"$GITHUB_SHA" \
--build-arg GITHUB_SHA="$GITHUB_SHA" \
--build-arg GITHUB_REF="$GITHUB_REF" .
Comment on lines +56 to +58

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Docker build has no Dockerfile

On every master push, this step builds the repository root without specifying another Dockerfile, but the repository contains no Dockerfile, causing the workflow to stop before publishing or deploying an image.

Prompt To Fix With AI
This is a comment left during a code review.
Path: .github/workflows/ibm.yml
Line: 56-58

Comment:
**Docker build has no Dockerfile**

On every `master` push, this step builds the repository root without specifying another Dockerfile, but the repository contains no Dockerfile, causing the workflow to stop before publishing or deploying an image.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.


# Push the image to IBM Container Registry
- name: Push the image to ICR
run: |
docker push $REGISTRY_HOSTNAME/$ICR_NAMESPACE/$IMAGE_NAME:$GITHUB_SHA

# Deploy the Docker image to the IKS cluster
- name: Deploy to IKS
run: |
ibmcloud ks cluster config --cluster $IKS_CLUSTER
kubectl config current-context
kubectl create deployment $DEPLOYMENT_NAME --image=$REGISTRY_HOSTNAME/$ICR_NAMESPACE/$IMAGE_NAME:$GITHUB_SHA --dry-run -o yaml > deployment.yaml
kubectl apply -f deployment.yaml
kubectl rollout status deployment/$DEPLOYMENT_NAME
kubectl create service loadbalancer $DEPLOYMENT_NAME --tcp=80:$PORT --dry-run -o yaml > service.yaml
kubectl apply -f service.yaml
kubectl get services -o wide