diff --git a/.env.sample b/.env.sample index 2b246e7..29ec50d 100644 --- a/.env.sample +++ b/.env.sample @@ -1,7 +1,7 @@ OPENAI_AI_KEY= OPENAI_MODEL_ID=gpt-3.5-turbo-1106 OPEN_AI_EMBEDDINGS_MODEL=text-embedding-ada-002 -PORT=8080 +PORT=8081 SERVER_PORT=3001 TWILIO_ACCOUNT_SID= TWILIO_AUTH_TOKEN= diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..c7db779 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,63 @@ +name: Docker Build, Push and Deploy + +on: + push: + branches: + - 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 }} diff --git a/docker-compose.yml b/docker-compose.yml index 7559cf3..16aac02 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -26,8 +26,8 @@ services: - redis-new networks: - beckn_action_bot_network - volumes: - - ./:/app + # volumes: + # - ./:/app volumes: index_data: