Skip to content
Merged
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
155 changes: 89 additions & 66 deletions .github/workflows/docker-smurf.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
---
name: 🦸‍♂️ Smurf-Docker
'on':
# Reusable Smurf SDKR workflow — build, scan, and push Docker images.
# Docs: docs/docker-smurf.md
name: 🐳 Smurf-Docker

on:
workflow_call:
inputs:
# ── General toggles ──────────────────────────────────────────────
docker_enable:
description: Set to true to run docker commands
type: string
required: false
aws_auth_method:
description: AWS auth method to use like oidc and keys
type: string
required: false
aws_eks_cluster_name:
description: AWS eks cluster name
docker_push:
description: Set true for docker push
type: string
required: false
aws_role:
description: AWS OIDC role for aws authentication.
type: string
default: 'false'
provider:
description: Cloud provider (aws, azure, gcp, digitalocean)
type: string
required: false
default: aws

# ── Docker image & build ─────────────────────────────────────────
docker_image_name:
description: Docker image name
type: string
Expand All @@ -37,15 +35,6 @@ name: 🦸‍♂️ Smurf-Docker
type: string
required: false
default: image
docker_push:
description: Set true for docker push
type: string
required: false
docker_buildkit_enable:
description: Set true to enable docker buildkit
type: string
required: false
default: 'false'
docker_registry:
description: 'The registry to Push Docker Image (aws, az, gcp, hub)'
type: string
Expand All @@ -54,7 +43,7 @@ name: 🦸‍♂️ Smurf-Docker
description: 'The URL of the container registry (e.g., Docker Hub, ECR, GCR, ACR).'
type: string
dockerfile_path:
description: Docker file directory
description: Docker file path (relative to repo root)
type: string
default: Dockerfile
docker_build_args:
Expand All @@ -66,6 +55,13 @@ name: 🦸‍♂️ Smurf-Docker
description: Docker Image Build Platform
type: string
default: linux/amd64
docker_buildkit_enable:
description: Set true to enable docker buildkit
type: string
required: false
default: 'false'

# ── AWS ──────────────────────────────────────────────────────────
aws_region:
required: false
type: string
Expand All @@ -80,6 +76,8 @@ name: 🦸‍♂️ Smurf-Docker
type: string
description: AWS assume role
required: false

# ── GCP ──────────────────────────────────────────────────────────
gcp_project_id:
required: false
type: string
Expand All @@ -93,17 +91,9 @@ name: 🦸‍♂️ Smurf-Docker
type: string
required: false
default: 'false'
gcp_region:
required: false
type: string
description: GCP Region
default: 'us-central1'
gcp_gke_cluster_name:
description: GCP gke cluster name
type: string
required: false

secrets:
# ── AWS secrets ──────────────────────────────────────────────────
AWS_ACCESS_KEY_ID:
required: false
description: AWS Access Key ID for direct authentication
Expand All @@ -113,6 +103,11 @@ name: 🦸‍♂️ Smurf-Docker
AWS_SESSION_TOKEN:
required: false
description: AWS Session Token for direct authentication
BUILD_ROLE:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we make it AWS_BUILD_ROLE

required: false
description: AWS OIDC role for aws authentication

# ── GCP secrets ──────────────────────────────────────────────────
GCP_WIP:
required: false
description: 'WIP Connected with Service Account'
Expand All @@ -125,11 +120,23 @@ name: 🦸‍♂️ Smurf-Docker
GCP_SERVICE_ACCOUNT_KEY:
required: false
description: 'GCP service account JSON Key'

# ── Docker Hub secrets ───────────────────────────────────────────
DOCKER_USERNAME:
required: false
description: Docker Hub username
DOCKER_PASSWORD:
required: false
description: Docker Hub access token or password

aws_set_parameters:
required: false
description: Overriding the default values using --set flag

jobs:
###############################################
# BUILD → SAVE → UPLOAD ARTIFACT
###############################################
docker_build:
if: inputs.docker_enable == 'true'
runs-on: ubuntu-latest
Expand All @@ -140,35 +147,40 @@ jobs:
- name: 📦 Checkout
uses: actions/checkout@v6

# - Setup smurf CLI
- name: Setup Smurf
uses: clouddrove/smurf@v1.1.3
- name: ⚙️ Setup Smurf
uses: clouddrove/smurf@v1.1.5

- name: 🐳 Docker Image Build
if: inputs.docker_buildkit_enable != 'true'
run: |
smurf sdkr build ${{ inputs.docker_image_name }}:${{ inputs.docker_image_tag }} -f ${{
inputs.dockerfile_path }} --platform ${{ inputs.docker_build_platform }}
smurf sdkr build ${{ inputs.docker_image_name }}:${{ inputs.docker_image_tag }} \
-f ${{ inputs.dockerfile_path }} \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please corss check indentation here

--platform ${{ inputs.docker_build_platform }} \
--build-arg ${{ inputs.docker_build_args }}

- name: 🐳 Docker Image Build with Buildkit
if: inputs.docker_buildkit_enable == 'true'
run: |
smurf sdkr build ${{ inputs.docker_image_name }}:${{ inputs.docker_image_tag }} -f ${{
inputs.dockerfile_path }} --platform ${{ inputs.docker_build_platform }}
--build-arg ${{ inputs.docker_build_args }} --buildkit
smurf sdkr build ${{ inputs.docker_image_name }}:${{ inputs.docker_image_tag }} \
-f ${{ inputs.dockerfile_path }} \
--platform ${{ inputs.docker_build_platform }} \
--build-arg ${{ inputs.docker_build_args }} \
--buildkit

- name: 💾 Save Docker Image as Artifact
run: >
docker save ${{ inputs.docker_image_name }}:${{ inputs.docker_image_tag }} -o ${{
inputs.docker_image_tar }}
run: |
docker save ${{ inputs.docker_image_name }}:${{ inputs.docker_image_tag }} \
-o ${{ inputs.docker_image_tar }}

- name: ⬆️ Upload Docker Image Artifact
- name: 📤 Upload Docker Image Artifact
uses: actions/upload-artifact@v7
with:
name: '${{ inputs.docker_image_name }}'
path: '${{ inputs.docker_image_tar }}'
name: docker-image
path: ${{ inputs.docker_image_tar }}

###############################################
# DOWNLOAD → AUTH → SCAN → TAG → PUSH
###############################################
docker_scan_push:
if: inputs.docker_enable == 'true' && inputs.docker_push == 'true'
runs-on: ubuntu-latest
Expand All @@ -180,19 +192,18 @@ jobs:
- name: 📦 Checkout
uses: actions/checkout@v6

# - Setup smurf CLI
- name: Setup Smurf
uses: clouddrove/smurf@v1.1.3
- name: ⚙️ Setup Smurf
uses: clouddrove/smurf@v1.1.5

- name: ⬇️ Download Docker Image Artifact
- name: 📥 Download Docker Image Artifact
uses: actions/download-artifact@v8
with:
name: '${{ inputs.docker_image_name }}'
name: docker-image

- name: 📥 Load Docker Image
run: |
docker load -i ${{ inputs.docker_image_tar }}
- name: 📂 Load Docker Image
run: docker load -i ${{ inputs.docker_image_tar }}

# ── Cloud authentication ─────────────────────────────────────────
- name: 🟦 Install AWS CLI
if: ${{ inputs.provider == 'aws' }}
uses: aws-actions/configure-aws-credentials@v6
Expand All @@ -205,7 +216,7 @@ jobs:
role-duration-seconds: 900
role-skip-session-tagging: true

- name: 🔄 Assume another IAM Role
- name: 🔑 Assume another IAM Role
if: inputs.aws_assume_role == 'true'
uses: aws-actions/configure-aws-credentials@v6
with:
Expand All @@ -224,29 +235,41 @@ jobs:

- name: ☁️ Authenticate Google Cloud with Service Account JSON Key
if: inputs.gcp_auth_method == 'json'
uses: 'google-github-actions/auth@v3'
uses: google-github-actions/auth@v3
with:
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}'
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }}

- name: 🐋 Set Docker Hub environment variables
if: inputs.docker_registry == 'hub'
run: |
echo "DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}" >> $GITHUB_ENV
echo "DOCKER_PASSWORD=${{ secrets.DOCKER_PASSWORD }}" >> $GITHUB_ENV
shell: bash

# ── Scan & push ──────────────────────────────────────────────────
- name: 🛡️ Install Trivy
run: |
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
trivy --version

- name: 🛡️ Docker Image Scan
- name: 🔍 Docker Image Scan
run: |
smurf sdkr scan ${{ inputs.docker_image_name }}:${{ inputs.docker_image_tag }}

- name: 🏷️ Docker Image Tag
if: inputs.docker_push == 'true'
run: |
smurf sdkr tag ${{ inputs.docker_image_name }}:${{ inputs.docker_image_tag }} ${{
inputs.docker_registry_url }}/${{ inputs.docker_image_name }}:${{ inputs.docker_image_tag }}
smurf sdkr tag ${{ inputs.docker_image_name }}:${{ inputs.docker_image_tag }} \
${{ inputs.docker_registry_url }}/${{ inputs.docker_image_name }}:${{ inputs.docker_image_tag }}

- name: 🚀 Docker Image Push
if: inputs.docker_push == 'true' && inputs.gcp_docker_push != 'true'
if: inputs.docker_push == 'true' && inputs.gcp_docker_push != 'true'
run: |
smurf sdkr push ${{ inputs.docker_registry }} ${{ inputs.docker_registry_url }}/${{ inputs.docker_image_name }}:${{
inputs.docker_image_tag }}
smurf sdkr push ${{ inputs.docker_registry }} ${{ inputs.docker_registry_url }}/${{ inputs.docker_image_name }}:${{ inputs.docker_image_tag }}

- name: 🚀 Docker Image Push on gcp
- name: 🚀 Docker Image Push on GCP
if: inputs.docker_push == 'true' && inputs.gcp_docker_push == 'true'
run: |
smurf sdkr push ${{ inputs.docker_registry }} ${{ inputs.docker_registry_url }}/${{ inputs.docker_image_name }}:${{
inputs.docker_image_tag }} --project-id ${{ inputs.gcp_project_id }}
...
smurf sdkr push ${{ inputs.docker_registry }} \
${{ inputs.docker_registry_url }}/${{ inputs.docker_image_name }}:${{ inputs.docker_image_tag }} \
--project-id ${{ inputs.gcp_project_id }}
Loading
Loading