-
Notifications
You must be signed in to change notification settings - Fork 3
155 lines (126 loc) · 4.37 KB
/
deploy.yml
File metadata and controls
155 lines (126 loc) · 4.37 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
152
153
154
155
name: Deploy to Production
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Install Hardhat
run: npm install -g hardhat
- name: Run smart contract tests
run: npx hardhat test
env:
ETHEREUM_RPC_URL: ${{ secrets.ETHEREUM_RPC_URL }}
- name: Run backend tests
run: npm run test:backend
- name: Run frontend tests
run: npm run test:frontend
- name: Build application
run: npm run build
deploy-contracts:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Deploy to Sepolia
run: npx hardhat run scripts/deploy.ts --network sepolia
env:
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
ETHEREUM_RPC_URL: ${{ secrets.ETHEREUM_RPC_URL }}
- name: Verify contracts
run: npx hardhat run scripts/verify.ts --network sepolia
env:
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}
- name: Deploy to Mumbai (Polygon testnet)
run: npx hardhat run scripts/deploy.ts --network mumbai
env:
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
POLYGON_RPC_URL: ${{ secrets.POLYGON_RPC_URL }}
deploy-backend:
needs: deploy-contracts
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build and push Docker image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: oui-backend
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile.backend .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
- name: Deploy to ECS
run: |
aws ecs update-service --cluster oui-cluster --service oui-backend --force-new-deployment --region us-east-1
- name: Wait for deployment to complete
run: |
aws ecs wait services-stable --cluster oui-cluster --services oui-backend --region us-east-1
deploy-frontend:
needs: deploy-backend
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Build frontend
run: npm run build:frontend
env:
REACT_APP_OUI_API_URL: ${{ secrets.REACT_APP_OUI_API_URL }}
REACT_APP_INFURA_PROJECT_ID: ${{ secrets.REACT_APP_INFURA_PROJECT_ID }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Deploy to S3
run: aws s3 sync src/frontend/build/ s3://oui-frontend-prod --delete
- name: Invalidate CloudFront cache
run: aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} --paths "/*"
notify:
needs: [deploy-contracts, deploy-backend, deploy-frontend]
runs-on: ubuntu-latest
if: always()
steps:
- name: Notify deployment status
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
channel: '#deployments'
webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()