|
| 1 | +name: Prod Deployment |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: ['main'] |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + stage: |
| 8 | + description: 'Stage to deploy (production)' |
| 9 | + required: true |
| 10 | + run_production: |
| 11 | + description: 'Staging deployment completed (yes, no)' |
| 12 | + required: true |
| 13 | + |
| 14 | +jobs: |
| 15 | + deploy_prod: |
| 16 | + name: Prod Deployment |
| 17 | + permissions: |
| 18 | + id-token: write |
| 19 | + contents: write |
| 20 | + environment: prod |
| 21 | + runs-on: ubuntu-latest |
| 22 | + if: github.event_name == 'workflow_dispatch' && github.event.inputs.stage == 'production' && github.event.inputs.run_production == 'yes' |
| 23 | + env: |
| 24 | + AWS_REGION: eu-west-1 |
| 25 | + ECR_REPOSITORY: docs-ecr |
| 26 | + ECS_SERVICE: docs-ecs-service |
| 27 | + ECS_CLUSTER: frontend-prod-ecs-cluster |
| 28 | + ECS_TASK_DEFINITION: prod-taskdef.json |
| 29 | + CONTAINER_NAME: docs |
| 30 | + steps: |
| 31 | + - name: Checkout |
| 32 | + uses: actions/checkout@v3 |
| 33 | + with: |
| 34 | + submodules: true |
| 35 | + |
| 36 | + - name: Configure AWS credentials |
| 37 | + uses: aws-actions/configure-aws-credentials@v1-node16 |
| 38 | + with: |
| 39 | + aws-region: ${{ env.AWS_REGION }} |
| 40 | + role-to-assume: arn:aws:iam::042947190491:role/docs-GithubActionsRole |
| 41 | + role-session-name: GithubActionsSession |
| 42 | + |
| 43 | + - name: Login to Amazon ECR |
| 44 | + id: login-ecr |
| 45 | + uses: aws-actions/amazon-ecr-login@v1 |
| 46 | + |
| 47 | + - name: Use Python |
| 48 | + uses: actions/setup-python@v4 |
| 49 | + with: |
| 50 | + python-version: '3.11' |
| 51 | + |
| 52 | + - name: pip Install |
| 53 | + run: pip install -r requirements.txt --no-cache-dir |
| 54 | + |
| 55 | + - name: Build mkdocs |
| 56 | + run: mkdocs build |
| 57 | + |
| 58 | + - name: Build, tag, and push image to Amazon ECR |
| 59 | + id: build-image |
| 60 | + env: |
| 61 | + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} |
| 62 | + IMAGE_TAG: ${{ github.sha }} |
| 63 | + run: | |
| 64 | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile.nginx . |
| 65 | + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |
| 66 | + echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT |
| 67 | +
|
| 68 | + - name: Fill in the new image ID in the Amazon ECS task definition |
| 69 | + id: task-def |
| 70 | + uses: aws-actions/amazon-ecs-render-task-definition@v1 |
| 71 | + with: |
| 72 | + task-definition: ${{ env.ECS_TASK_DEFINITION }} |
| 73 | + container-name: ${{ env.CONTAINER_NAME }} |
| 74 | + image: ${{ steps.build-image.outputs.image }} |
| 75 | + |
| 76 | + - name: Deploy Amazon ECS task definition |
| 77 | + uses: aws-actions/amazon-ecs-deploy-task-definition@v1 |
| 78 | + with: |
| 79 | + task-definition: ${{ steps.task-def.outputs.task-definition }} |
| 80 | + service: ${{ env.ECS_SERVICE }} |
| 81 | + cluster: ${{ env.ECS_CLUSTER }} |
| 82 | + wait-for-service-stability: true |
0 commit comments