Update blog-deployment.yaml #72
This file contains hidden or 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: Django CI/CD Pipeline | |
| 'on': | |
| # push code and github action trigger with manually | |
| # workflow_dispatch: | |
| # push or pull request github action trigger automatically | |
| push: | |
| branches: [main] # Adjust the branch name as needed | |
| # pull_request: | |
| # branches: [main] # Adjust the branch name as needed | |
| jobs: | |
| build_and_test: | |
| name: Build and Test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.10' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r blog/requirements.txt | |
| - name: Run tests | |
| run: python blog/manage.py test | |
| deploy: | |
| name: Deploy to EC2 on main branch push | |
| # needs: build_and_test | |
| env: | |
| PRIVATE_KEY: ${{ secrets.EC2_SSH_KEY }} | |
| HOSTNAME: ${{secrets.HOST_DNS}} | |
| USER_NAME: ${{secrets.USERNAME}} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Deploy to Server 1 | |
| run: | | |
| echo "$PRIVATE_KEY" > private_key && chmod 600 private_key | |
| ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} 'bash -s'< .github/workflows/deploy_script.sh |