-
Notifications
You must be signed in to change notification settings - Fork 3
93 lines (84 loc) · 3.33 KB
/
deploy-docker.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
name: Push to Docker image to AWS ECR and deploy to AWS EC2
on:
workflow_dispatch:
inputs:
development-environment:
description: Development environment to deploy to.
required: true
default: staging
type: choice
options:
- staging
- production
pull_request:
branches:
- main
types:
- closed
paths-ignore:
- 'web/deploy/terraform/**'
workflow_call:
inputs:
development-environment:
description: Development environment to deploy to. Usually `staging` or `production`
required: true
default: staging
type: string
permissions:
id-token: write
contents: read
jobs:
set-development-environment:
runs-on: ubuntu-latest
name: Set development environment
outputs:
development-environment: ${{ steps.set-development-environment.outputs.development-environment }}
steps:
- name: Set development environment
id: set-development-environment
run: |
if [[ "${{ github.event_name }}" == 'pull_request' || "${{ inputs.development-environment }}" == 'staging' ]]; then
echo "development-environment=staging" >> $GITHUB_OUTPUT
else
echo "development-environment=production" >> $GITHUB_OUTPUT
fi
cat "$GITHUB_OUTPUT"
cat "$GITHUB_OUTPUT" | grep 'development-environment'
infrastructure-modified:
runs-on: ubuntu-latest
name: Check for modified infrastructure
outputs:
modified-files: ${{ steps.set-output.outputs.modified-files }}
steps:
- uses: actions/checkout@v4
name: Checkout repository
- name: Get modified infrastructure configuration
id: infrastructure-modified
uses: tj-actions/changed-files@v45
with:
files: |
web/deploy/terraform/**
- name: Set modified output
id: set-output
env:
MODIFIED_FILES: ${{ steps.infrastructure-modified.outputs.any_modified }}
run: |
echo "modified-files=${MODIFIED_FILES}" >> $GITHUB_OUTPUT
build-and-push:
needs: [infrastructure-modified, set-development-environment]
strategy:
matrix:
deployment: ["api", "dashboard"]
uses: ./.github/workflows/build-docker.yml
if: ( (github.event_name == 'pull_request' && github.event.pull_request.merged == true && needs.infrastructure-modified.outputs.modified-files != 'true' && needs.set-development-environment.result == 'success') || (github.event_name == 'workflow_dispatch') || (github.event_name == 'workflow_call') )
secrets: inherit
with:
deployment: ${{ matrix.deployment }}
docker-up:
needs: [build-and-push, set-development-environment, infrastructure-modified]
if: ${{ always() && !cancelled() && needs.build-and-push.result == 'success' && ( (github.event_name == 'pull_request' && github.event.pull_request.merged == 'true' && needs.infrastructure-modified.outputs.modified-files != 'true') || (github.event_name == 'workflow_dispatch') || (github.event_name == 'push') || (github.event_name == 'workflow_call') )}}
name: Deploy and run Docker images on EC2
uses: ./.github/workflows/docker-up.yml
secrets: inherit
with:
development-environment: ${{ needs.set-development-environment.outputs.development-environment }}