John-Jiang's picture
init commit
b27e586
name: Build and Push Docker Image
# Trigger the pipeline
on:
workflow_dispatch: # manual trigger
push:
branches:
- test
- dev
- main
# Define pipeline jobs
jobs:
build-image:
runs-on: ubuntu-latest
steps:
# Checkout only the latest first commit
- uses: actions/checkout@v3
with:
fetch-depth: 1
# Set up QEMU for multi-platform Docker builds
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
# Set up Docker Buildx for multi-platform support
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Log in to DockerHub
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Cache Docker layers to speed up builds
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('**/Dockerfile', '**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-buildx-
# Build and push Docker image to DockerHub and GHCR
- name: Build and push Docker images
uses: docker/build-push-action@v2
with:
platforms: linux/amd64
context: .
push: true
# Define dynamic tags based on branch name
tags: |
synthetic-data-${{ github.ref_name }}:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
# deploy:
# needs: build-image
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v3
# - name: Configure AWS credentials
# uses: aws-actions/configure-aws-credentials@v1
# with:
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# aws-region: us-west-1
# # Update kubeconfig to the correct EKS cluster based on the branch
# - name: Update kubeconfig
# run: |
# if [[ "${{ github.ref_name }}" == "main" ]]; then
# aws eks update-kubeconfig --name Prod --region us-west-1
# elif [[ "${{ github.ref_name }}" == "dev" ]]; then
# aws eks update-kubeconfig --name Dev --region us-west-1
# elif [[ "${{ github.ref_name }}" == "test" ]]; then
# aws eks update-kubeconfig --name test --region us-west-1
# fi
# # Deploy to EKS
# - name: Deploy to EKS
# run: |
# kubectl rollout restart deployment ai-agent-service --namespace intersoul