Skip to content

Added deployment script ,correction in docker-compose file #1

Added deployment script ,correction in docker-compose file

Added deployment script ,correction in docker-compose file #1

Workflow file for this run

name: Docker Build, Push and Deploy
on:
push:
branches-ignore:
- main
jobs:
build-push-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up environment variables
run: |
echo "OPENAI_AI_KEY=${{secrets.OPENAI_AI_KEY}}" >> .env
echo "OPENAI_MODEL_ID=${{secrets.OPENAI_MODEL_ID}}" >> .env
echo "OPEN_AI_EMBEDDINGS_MODEL=${{secrets.OPEN_AI_EMBEDDINGS_MODEL}}" >> .env
echo "PORT=${{secrets.PORT}}" >> .env
echo "SERVER_PORT=${{secrets.SERVER_PORT}}" >> .env
echo "TWILIO_ACCOUNT_SID=${{secrets.TWILIO_ACCOUNT_SID}}" >> .env
echo "TWILIO_AUTH_TOKEN=${{secrets.TWILIO_AUTH_TOKEN}}" >> .env
echo "TWILIO_NUMBER=${{secrets.TWILIO_NUMBER}}" >> .env
echo "TEST_RECEPIENT_NUMBER=${{secrets.TEST_RECEPIENT_NUMBER}}" >> .env
- name: Create SSH key file
run: echo -e "${{ secrets.EC2_SSH_KEY }}" > ~/ec2_key
env:
EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }}
- name: Set permissions for SSH key file
run: chmod 600 ~/ec2_key
- name: Login to Docker Hub
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USER }}" --password-stdin
env:
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker images
run: |
docker-compose build
docker-compose push
- name: Copy environment file
run: scp -i ~/ec2_key -o StrictHostKeyChecking=no ./.env ec2-user@${{ secrets.EC2_IP }}:~/beckn-action-bot/.env
- name: Copy docker-compose.yml to the server
run: scp -i ~/ec2_key -o StrictHostKeyChecking=no ./docker-compose.yml ec2-user@${{ secrets.EC2_IP }}:~/beckn-action-bot/docker-compose.yml
- name: SSH into EC2 instance and deploy
run: |
ssh -i ~/ec2_key ec2-user@${{ secrets.EC2_IP }} '
echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USER }}" --password-stdin &&
cd ~/beckn-action-bot/ &&
docker-compose pull &&
docker-compose up -d'
env:
EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }}
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }}