Update template.py #13
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: Docker Build & Deploy | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
Build-and-Deploy: | |
runs-on: self-hosted | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Verify Docker Permissions | |
run: | | |
ls -l /var/run/docker.sock | |
groups | |
whoami | |
docker ps | |
- name: Build Docker Image | |
run: | | |
docker build -t streamlit-app \ | |
--build-arg OPENAI_API_KEY="${{ secrets.OPENAI_API_KEY }}" \ | |
--build-arg WEATHER_API_KEY="${{ secrets.WEATHER_API_KEY }}" \ | |
--build-arg SERPER_API_KEY="${{ secrets.SERPER_API_KEY }}" \ | |
--build-arg AMADEUS_API_KEY="${{ secrets.AMADEUS_API_KEY }}" \ | |
--build-arg AMADEUS_API_SECRET="${{ secrets.AMADEUS_API_SECRET }}" . | |
- name: Authenticate to AWS ECR | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_DEFAULT_REGION }} | |
- name: Login to Amazon ECR | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Push Docker Image to ECR | |
run: | | |
docker tag streamlit-app:latest ${{ secrets.AWS_ECR_REPO_URI }}:latest | |
docker push ${{ secrets.AWS_ECR_REPO_URI }}:latest | |
- name: Deploy to EC2 | |
run: | | |
echo "${{ secrets.SSH_KEY }}" > ssh_key | |
chmod 600 ssh_key | |
ssh -i ssh_key -o StrictHostKeyChecking=no ubuntu@44.203.254.197 \ | |
'docker pull ${{ secrets.AWS_ECR_REPO_URI }}:latest && \ | |
docker stop streamlit-app || true && \ | |
docker rm streamlit-app || true && \ | |
docker run -d --name streamlit-app \ | |
-e OPENAI_API_KEY="${{ secrets.OPENAI_API_KEY }}" \ | |
-e WEATHER_API_KEY="${{ secrets.WEATHER_API_KEY }}" \ | |
-e SERPER_API_KEY="${{ secrets.SERPER_API_KEY }}" \ | |
-e AMADEUS_API_KEY="${{ secrets.AMADEUS_API_KEY }}" \ | |
-e AMADEUS_API_SECRET="${{ secrets.AMADEUS_API_SECRET }}" \ | |
-p 8501:8501 ${{ secrets.AWS_ECR_REPO_URI }}:latest' | |
rm ssh_key |