forked from amplication/amplication
-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (139 loc) · 4.92 KB
/
release.template.yml
File metadata and controls
151 lines (139 loc) · 4.92 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: Release
on:
workflow_call:
inputs:
branch:
type: string
description: Name of the git branch
required: true
affected-apps:
type: string
description: Nx applications affected by the changes
required: true
affected-lib:
type: string
description: Nx libraries affected by the changes
required: true
affected-dockerable:
type: string
description: Nx projects configured with docker:build affected by the changes
required: true
affected-deployable:
type: string
description: Nx projects configured with deploy affected by the changes
required: true
secrets:
nx-cloud-access-token:
required: true
ECR_AWS_ACCESS_KEY_ID:
required: true
ECR_AWS_SECRET_ACCESS_KEY:
required: true
AWS_ACCESS_KEY_ID:
required: true
AWS_SECRET_ACCESS_KEY:
required: true
env:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.nx-cloud-access-token }}
BRANCH: ${{ inputs.branch }}
jobs:
package:
if: ${{ inputs.affected-dockerable != '[]' && inputs.affected-dockerable != ''}}
name: Package
runs-on: ubuntu-20.04
strategy:
matrix:
project: ${{ fromJson(inputs.affected-dockerable) }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.workflow_run.head_branch }}
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version-file: "package.json"
cache: "npm"
cache-dependency-path: "**/package-lock.json"
- name: Cache global node modules
id: cache-node-modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
- name: Cache other node modules
id: cache-other-node-modules
uses: actions/cache@v3
env:
cache-name: cache-other-node-modules
with:
path: |
libs/data-service-generator/node_modules
libs/util/code-gen-utils/node_modules
packages/amplication-cli/node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('./**/package-lock.json') }}
- name: Install Dependencies
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' || steps.cache-other-node-modules.outputs.cache-hit != 'true' }}
run: npm ci
- name: Configure AWS Credentials (operations account)
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Login to Amazon ECR (operations account)
uses: aws-actions/amazon-ecr-login@v1
with:
registries: "439403303254"
# https://github.com/docker/metadata-action
- name: Docker Metadata
uses: docker/metadata-action@v4
id: meta
with:
images: "439403303254.dkr.ecr.us-east-1.amazonaws.com/${{ matrix.project }}"
tags: |
type=sha,prefix=sha-
type=ref,event=pr,prefix=pr-
type=ref,event=tag,prefix=tag-
type=raw,value=${{ github.run_id }},prefix=gh-
type=raw,value=${{ env.BRANCH }}
type=raw,value=latest,enable=${{ env.BRANCH == 'master' }}
# https://www.npmjs.com/package/@nx-tools/nx-docker
- name: Dockerize
run: npx nx docker:build ${{ matrix.project }} --prod
env:
INPUT_TAGS: ${{ steps.meta.outputs.tags }}
INPUT_PUSH: true
# env variables substituted in the project.json docker target build-args
GIT_REF_NAME: ${{ github.ref_name }}
GIT_SHA: ${{ github.sha }}
configure:
name: Configure deployment target environment
runs-on: ubuntu-20.04
outputs:
environment: ${{ steps.environment-identifier.outputs.environment }}
steps:
- id: environment-identifier
run: |
if [[ "${{ env.BRANCH }}" == "next" ]];
then
echo environment="sandbox" >> $GITHUB_OUTPUT
elif [[ "${{ env.BRANCH }}" == "master" ]];
then
echo environment="staging" >> $GITHUB_OUTPUT
fi;
deploy:
name: Deployment
needs: [package, configure]
if: ${{ inputs.affected-deployable != '[]' && inputs.affected-deployable != ''}}
strategy:
matrix:
project: ${{ fromJson(inputs.affected-deployable) }}
uses: ./.github/workflows/deployment.template.yml
with:
environment-name: ${{ needs.configure.outputs.environment }}
project-name: ${{ matrix.project }}
secrets:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}