/feat update cd.yml #8
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: 🚀 Deploy to production | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| types: | |
| - closed | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: read | |
| env: # 전역 변수 선언 | |
| PROJECT_NAME: input-server | |
| jobs: | |
| build: | |
| environment: production | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: ✅ Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| id: setup_python | |
| with: | |
| python-version: '3.10' | |
| architecture: x64 | |
| - name: Restore Virtual env | |
| uses: actions/cache/restore@v4 | |
| id: cache-venv | |
| with: | |
| path: venv | |
| key: venv-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('requirements.txt') }} | |
| restore-keys: | | |
| venv-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}- | |
| - name: Install dependencies | |
| if: steps.cache-venv.outputs.cache-hit != 'true' | |
| run: | | |
| python -m venv venv | |
| source venv/bin/activate | |
| python -m pip install --upgrade pip | |
| python -m pip install -r requirements.txt | |
| - name: Update environment paths | |
| run: | | |
| echo "${{ github.workspace }}/venv/bin" >> $GITHUB_PATH | |
| echo "VIRTUAL_ENV=${{ github.workspace }}/venv" >> $GITHUB_ENV | |
| - name: Save virtual environment cache | |
| if: steps.cache-venv.outputs.cache-hit != 'true' | |
| uses: actions/cache@v3 | |
| with: | |
| path: venv | |
| key: venv-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('requirements.txt') }} | |
| - name: Create Zipfile archive of Dependencies | |
| run: | | |
| cd ./venv/lib/python3.10/site-packages | |
| zip -r9 ../../../../${PROJECT_NAME}.zip . | |
| - name: Add App to Zipfile | |
| run: cd ./src && zip -g ../${PROJECT_NAME}.zip -r . | |
| - name: 🌎 Access to AWS | |
| 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: ap-northeast-2 | |
| - name: 🚛 Upload to S3 | |
| run: | | |
| aws s3 cp \ | |
| --region ap-northeast-2 \ | |
| --acl private \ | |
| ./${PROJECT_NAME}.zip \ | |
| s3://${{ secrets.S3_BUCKET_NAME }}/${{ secrets.S3_BUCKET_DIR_NAME }}/$GITHUB_SHA.zip | |
| deploy: | |
| env: | |
| ENV_PATH: .env | |
| environment: production | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 🌎 Access to AWS | |
| 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: ap-northeast-2 | |
| - name: 🚀 Deploy to EC2 | |
| run: | | |
| aws deploy create-deployment \ | |
| --application-name ${PROJECT_NAME} \ | |
| --deployment-group-name production \ | |
| --s3-location bucket=${{ secrets.S3_BUCKET_NAME }},bundleType=zip,key=${{ secrets.S3_BUCKET_DIR_NAME }}/$GITHUB_SHA.zip \ | |
| --deployment-config-name CodeDeployDefault.AllAtOnce \ | |
| --region ap-northeast-2 |