-
Notifications
You must be signed in to change notification settings - Fork 1
100 lines (94 loc) · 3.61 KB
/
deploy-staging-ecs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: Deploy-staging
on:
workflow_dispatch:
inputs:
custom_tag:
description: 'Set custom tag for image'
required: true
type: string
environment:
type: choice
description: 'The environment to deploy to'
options:
- staging
- production
required: true
default: 'staging'
push:
branches:
- main
paths-ignore:
- '.github/**'
- '**.md'
jobs:
context:
name: Setup context
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
outputs:
aws_region: ${{ steps.get.outputs.aws_region }}
aws_ecr_uri: ${{ steps.get.outputs.aws_ecr_uri }}
aws_ecr_region: ${{ steps.get.outputs.aws_ecr_region }}
aws_ecr_account_id: ${{ steps.get.outputs.aws_ecr_account_id }}
aws_ecs_cluster: ${{ steps.get.outputs.aws_ecs_cluster }}
steps:
- id: get
run: |
echo "aws_region=${{ vars.AWS_REGION }}" >> "$GITHUB_OUTPUT"
echo "aws_ecr_uri=${{ vars.AWS_ECR_URI }}" >> "$GITHUB_OUTPUT"
echo "aws_ecr_region=${{ vars.AWS_ECR_REGION }}" >> "$GITHUB_OUTPUT"
echo "aws_ecr_account_id=${{ vars.AWS_ECR_ACCOUNT_ID }}" >> "$GITHUB_OUTPUT"
echo "aws_ecs_cluster=${{ vars.AWS_ECS_CLUSTER }}" >> "$GITHUB_OUTPUT"
build-push-image:
if: ${{ github.event_name == 'push' }}
name: Build deploy image and push to registry
uses: infinum/devops-pipelines/.github/workflows/[email protected]
needs: context
with:
environment: ${{ inputs.environment }}
cloud: AWS
tags: ${{ needs.context.outputs.aws_ecr_uri }}:${{ github.sha }}
aws_ecr_region: ${{ needs.context.outputs.aws_ecr_region }}
aws_ecr_account_id: ${{ needs.context.outputs.aws_ecr_account_id }}
target: deploy
secrets: inherit
build-push-image-manual:
if: ${{ github.event_name == 'workflow_dispatch' }}
name: Run on workflow dispatch
uses: infinum/devops-pipelines/.github/workflows/[email protected]
needs: context
with:
environment: ${{ inputs.environment }}
cloud: AWS
tags: ${{ needs.context.outputs.aws_ecr_uri }}:${{ inputs.custom_tag }}
aws_ecr_region: ${{ needs.context.outputs.aws_ecr_region }}
aws_ecr_account_id: ${{ needs.context.outputs.aws_ecr_account_id }}
secrets: inherit
deploy-image:
if: ${{ github.event_name == 'push' }}
name: Deploy backend
uses: infinum/devops-pipelines/.github/workflows/[email protected]
needs: [context, build-push-image]
with:
image_uri: ${{ needs.context.outputs.aws_ecr_uri }}:${{ github.sha }}
environment: ${{ inputs.environment }}
aws_region: ${{ needs.context.outputs.aws_region }}
ecs_cluster: ${{ needs.context.outputs.aws_ecs_cluster }}
ecs_service: js-react-example
task_def_path: .aws/ecs/task-definition-app-staging.json
container_name: js-react-example
secrets: inherit
deploy-image-manual:
if: ${{ github.event_name == 'workflow_dispatch' }}
name: Deploy backend
uses: infinum/devops-pipelines/.github/workflows/[email protected]
needs: [context, build-push-image-manual]
with:
image_uri: ${{ needs.context.outputs.aws_ecr_uri }}:${{ inputs.custom_tag }}
environment: ${{ inputs.environment }}
aws_region: ${{ needs.context.outputs.aws_region }}
ecs_cluster: ${{ needs.context.outputs.aws_ecs_cluster }}
ecs_service: js-react-example
task_def_path: .aws/ecs/task-definition-app-staging.json
container_name: js-react-example
secrets: inherit