-
Notifications
You must be signed in to change notification settings - Fork 30
178 lines (147 loc) · 5.47 KB
/
prod-build-and-deploy.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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: (prod) Manual build & deploy
on:
workflow_dispatch:
inputs:
version:
description: 'Version tag'
required: true
type: string
permissions:
id-token: write
contents: read
env:
REGISTRY: "599564732950.dkr.ecr.us-east-2.amazonaws.com"
REPOSITORY: "starknet-remix-plugin"
CLUSTER: "starknet-remix-plugin-ecs-cluster"
SERVICE_NAME: "rocket-development-svc"
PROD_BUCKET_NAME: 'starknet-remix-plugin-prod-web'
PROD_CLUSTER: "starknet-remix-plugin-production-ecs-cluster"
PROD_SERVICE_NAME: "rocket-production-svc"
jobs:
BuildAPI:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Apply release tag
uses: rickstaa/action-create-tag@v1
with:
tag: ${{ inputs.version }}
tag_exists_error: false
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: us-east-2
role-to-assume: arn:aws:iam::599564732950:role/Aws-GH-Action-Assume-Role-Starknet
role-session-name: GHStarknet
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
mask-password: 'true'
# - name: Update local Rust toolchain
# run: |
# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain stable -y
# rustup update
# rustup component add clippy
# rustup install nightly
# - name: Toolchain info
# run: |
# cargo --version --verbose
# rustc --version
# cargo clippy --version
# - name: Build
# run: |
# cd api
# cargo build
# ls ./target/debug/ -al
- name: Build, tag, and push docker image to Amazon ECR
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ env.REPOSITORY }}
IMAGE_TAG: ${{ inputs.version }}
run: |
docker build -t $REGISTRY/$REPOSITORY:apiserver-$IMAGE_TAG -f ./DockerfileRocket .
docker push $REGISTRY/$REPOSITORY:apiserver-$IMAGE_TAG
outputs:
image-version: ${{ inputs.version }}
BuildReact:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Inject version
env:
SED_COMMAND: 's/\"version\"\:[ ]\"0.1.0\"/\"version\": \"0.3.0\"/g'
run: |
sed -i 's/\"version\"\:[ ]\"0.1.0\"/\"version\": \"${{ inputs.version }}\"/g' ./plugin/package.json
- name: Setup Node ${{ env.NODE_VERSION }} Environment
uses: actions/setup-node@v1
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
run: npm install -g pnpm
- name: pnpm install
working-directory: ./plugin
run: pnpm install
- name: pnpm build
working-directory: ./plugin
run: pnpm run build
- name: 'Upload Artifact'
uses: actions/upload-artifact@v3
with:
name: react-github-actions-build
path: ./plugin/build/**/*
DeployAPI_Prod:
runs-on: ubuntu-latest
needs: BuildAPI
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: us-east-2
role-to-assume: arn:aws:iam::228016254426:role/Aws-GH-Action-Assume-Role-Starknet-Production
role-session-name: GHStarknet
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition starknet-remix-production-rocket --query taskDefinition > task-definition.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: "rocket"
image: ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:apiserver-${{ needs.BuildAPI.outputs.image-version }} #${{ github.run_number }}
# inject the expected React package URL for CORS logic
environment-variables: |
RUST_LOG=INFO
VITE_URL=https://cairo-remix.nethermind.io
PROMTAIL_USERNAME=${{secrets.PROMTAIL_USERNAME}}
PROMTAIL_PASSWORD=${{secrets.PROMTAIL_PASSWORD}}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.PROD_SERVICE_NAME }}
cluster: ${{ env.PROD_CLUSTER }}
wait-for-service-stability: true
DeployReact_Prod:
runs-on: ubuntu-latest
needs: BuildReact
steps:
- name: Get artifact
uses: actions/download-artifact@v3
with:
name: react-github-actions-build
path: artifact
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: us-east-2
role-to-assume: arn:aws:iam::228016254426:role/Aws-GH-Action-Assume-Role-Starknet-Production
role-session-name: GHStarknet
- name: Deploy to S3
run: aws s3 sync . s3://${{ env.PROD_BUCKET_NAME }} --acl public-read
working-directory: artifact