Update variables #31
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Push Docker Image to AWS ECR | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- '.github/workflows/cf-ai-agent.yml' | |
- 'dodao-ai-agents/crowd-fund-analysis/**' | |
jobs: | |
build-and-push: | |
name: Build and Push Docker Image | |
runs-on: ubuntu-latest | |
env: | |
NODE_OPTIONS: --max-old-space-size=8182 | |
AWS_REGION: us-east-1 # Change this to the AWS region where your ECR repository is located | |
ECR_REPOSITORY: crowd-fund-analysis # Replace this with your ECR repository name | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AI_AGENT_AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AI_AGENT_AWS_SECRET_ACCESS_KEY }} | |
aws-region: us-east-1 | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Get Git Commit Info | |
working-directory: dodao-ai-agents/crowd-fund-analysis | |
run: | | |
echo "Writing Git commit info to file..." | |
GIT_COMMIT_HASH=$(git rev-parse HEAD) | |
GIT_COMMIT_MESSAGE=$(git log -1 --pretty=%B) | |
echo "COMMIT_HASH=${GIT_COMMIT_HASH}" > cf_analysis_agent/commit_info.txt | |
echo "COMMIT_MESSAGE=${GIT_COMMIT_MESSAGE}" >> cf_analysis_agent/commit_info.txt | |
- name: Build Docker Image | |
working-directory: dodao-ai-agents/crowd-fund-analysis | |
run: | | |
IMAGE_TAG=${{ github.sha }} | |
docker build -t ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:$IMAGE_TAG . | |
- name: Tag Docker Image | |
working-directory: dodao-ai-agents/crowd-fund-analysis | |
run: | | |
IMAGE_TAG=${{ github.sha }} | |
docker tag ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:$IMAGE_TAG ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:latest | |
- name: Push Docker Image | |
working-directory: dodao-ai-agents/crowd-fund-analysis | |
run: | | |
IMAGE_TAG=${{ github.sha }} | |
docker push ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:$IMAGE_TAG | |
docker push ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:latest | |
- name: Deploy to Lightsail Container Service | |
run: | | |
aws lightsail create-container-service-deployment \ | |
--service-name cf-analysis-service \ | |
--containers '{ | |
"cf-analysis-container": { | |
"image": "729763663166.dkr.ecr.us-east-1.amazonaws.com/crowd-fund-analysis:latest", | |
"ports": { | |
"5000": "HTTP" | |
}, | |
"environment": { | |
"OPENAI_API_KEY": "${{ secrets.AI_AGENT_OPENAI_API_KEY }}", | |
"SCRAPINGANT_API_KEY": "${{ secrets.AI_AGENT_SCRAPINGANT_API_KEY }}", | |
"SERPER_API_KEY": "${{ secrets.AI_AGENT_SERPER_API_KEY }}", | |
"SCRAPIN_API_KEY": "${{ secrets.AI_AGENT_SCRAPIN_API_KEY }}", | |
"GOOGLE_CSE_ID": "${{ secrets.AI_AGENT_GOOGLE_CSE_ID }}", | |
"GOOGLE_API_KEY": "${{ secrets.AI_AGENT_GOOGLE_API_KEY }}", | |
"AWS_ACCESS_KEY_ID": "${{ secrets.AI_AGENT_AWS_ACCESS_KEY_ID }}", | |
"AWS_SECRET_ACCESS_KEY": "${{ secrets.AI_AGENT_AWS_SECRET_ACCESS_KEY }}", | |
"S3_BUCKET_NAME": "dodao-ai-insights-agent", | |
"AWS_DEFAULT_REGION": "us-east-1" | |
} | |
} | |
}' \ | |
--public-endpoint '{"containerName":"cf-analysis-container","containerPort":5000}' | |
- name: Check Deployment Status | |
id: check-status | |
run: | | |
until [[ $(aws lightsail get-container-services --service-name cf-analysis-service --query "containerServices[0].state" --output text) == "RUNNING" ]]; do | |
echo "Waiting for deployment to complete..." | |
sleep 15 | |
done | |
echo "Deployment completed successfully." |