Skip to content

add more debug logs #32

add more debug logs

add more debug logs #32

Workflow file for this run

name: Deploy to EC2 on Push
on:
push:
branches: [dev]
env:
AWS_REGION: "us-east-1"
# Permission can be added at job level or workflow level
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
jobs:
AssumeRoleAndCallIdentity:
runs-on: ubuntu-latest
steps:
- name: Git clone the repository
uses: actions/checkout@v3
- name: configure aws credentials
uses: aws-actions/[email protected]
with:
role-to-assume: arn:aws:iam::471112976510:role/GitHubAction-AssumeRoleWithAction
role-session-name: GitHub_to_AWS_via_FederatedOIDC
aws-region: ${{ env.AWS_REGION }}
# Hello from AWS: WhoAmI
- name: Sts GetCallerIdentity
run: |
aws sts get-caller-identity
# Step 3 - check the application-name and deployment group name
- name: Create CodeDeploy Deployment
id: deploy
run: |
aws deploy create-deployment \
--application-name django-indexer \
--deployment-group-name django-indexer-dev \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--github-location repository=${{ github.repository }},commitId=${{ github.sha }}
# name: Deploy to EC2 on Push
# on:
# push:
# branches:
# - main
# - dev
# jobs:
# deploy:
# runs-on: ubuntu-latest
# environment:
# name: ${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }}
# steps:
# - name: Checkout code
# uses: actions/checkout@v2
# - name: Set up SSH key
# uses: webfactory/[email protected]
# with:
# ssh-private-key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
# - name: Push new code to EC2
# run: |
# rsync -avz --exclude '.git*' --exclude 'node_modules' ./ ${{ vars.EC2_USER }}@${{ vars.EC2_SSH_HOST }}:/home/ec2-user/django-indexer
# echo "Code has been pushed to the EC2 instance."
# - name: Check for pending migrations
# id: check_migrations
# run: |
# echo "Checking for pending migrations..."
# pending_migrations=$(ssh -o "StrictHostKeyChecking=no" ${{ vars.EC2_USER }}@${{ vars.EC2_SSH_HOST }} "cd /home/ec2-user/django-indexer && source env/bin/activate && python manage.py showmigrations --plan | grep '\[ \]'")
# echo "::set-output name=pending::${pending_migrations}"
# if [ -z "$pending_migrations" ]; then
# echo "No migrations found."
# else:
# echo "Migrations found, stopping services."
# - name: Stop services if migrations are pending
# if: steps.check_migrations.outputs.pending
# run: |
# echo "Stopping services..."
# ssh -o "StrictHostKeyChecking=no" ${{ vars.EC2_USER }}@${{ vars.EC2_SSH_HOST }} "sudo systemctl stop gunicorn.service indexer.service"
# - name: Run migrations
# if: steps.check_migrations.outputs.pending
# run: |
# echo "Running migrations..."
# ssh -o "StrictHostKeyChecking=no" ${{ vars.EC2_USER }}@${{ vars.EC2_SSH_HOST }} "cd /home/ec2-user/django-indexer && source env/bin/activate && python manage.py migrate"
# - name: Run collectstatic
# run: |
# echo "Running collectstatic..."
# ssh -o "StrictHostKeyChecking=no" ${{ vars.EC2_USER }}@${{ vars.EC2_SSH_HOST }} "cd /home/ec2-user/django-indexer && source env/bin/activate && python manage.py collectstatic --noinput"
# - name: Restart services if migrations were run
# if: steps.check_migrations.outputs.pending
# run: |
# echo "Restarting services after migrations..."
# ssh -o "StrictHostKeyChecking=no" ${{ vars.EC2_USER }}@${{ vars.EC2_SSH_HOST }} "sudo systemctl restart gunicorn.service indexer.service"
# - name: Restart services if no migrations
# if: steps.check_migrations.outputs.pending == ''
# run: |
# echo "Restarting services without migration..."
# ssh -o "StrictHostKeyChecking=no" ${{ vars.EC2_USER }}@${{ vars.EC2_SSH_HOST }} "sudo systemctl restart gunicorn.service"