forked from graphprotocol/graph-node
-
Notifications
You must be signed in to change notification settings - Fork 2
239 lines (205 loc) · 7.78 KB
/
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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
name: "Build multi-arch Docker images"
on:
push:
tags:
- "nightly"
- "v*.*.*"
jobs:
start-runner:
name: "Start self-hosted EC2 runner"
runs-on: "ubuntu-latest"
outputs:
label: ${{ steps.start-ec2-runner.outputs.label }}
ec2-instance-id: ${{ steps.start-ec2-runner.outputs.ec2-instance-id }}
steps:
- name: "Configure AWS credentials"
uses: "aws-actions/configure-aws-credentials@v1"
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: "Start EC2 runner"
id: "start-ec2-runner"
uses: "xJonathanLEI/ec2-github-runner@main"
with:
mode: "start"
github-token: ${{ secrets.GH_PAT }}
ec2-image-id: "ami-01a786eb497a27d2a"
ec2-instance-type: "c6g.8xlarge"
subnet-id: "subnet-0f178a06b3c5e09dd"
security-group-id: "sg-0db4b2850585ebe80"
storage-size: 256
image-info:
name: "Extract image info"
runs-on: "ubuntu-latest"
outputs:
tag: ${{ steps.derive.outputs.tag }}
git_tag: ${{ steps.derive.outputs.git_tag }}
env:
DOCKER_REPOSITORY: "starknet/graph-node"
steps:
- id: "derive"
name: "Determine image version"
run: |
version_line="${{ github.ref }}"
regex="^refs\/tags\/(.*)$"
[[ $version_line =~ $regex ]];
FULL_TAG=${BASH_REMATCH[1]}
echo "git_tag=$FULL_TAG" >> $GITHUB_OUTPUT
if [ "$FULL_TAG" == "nightly" ]; then
VERSION="nightly"
else
regex="^refs\/tags\/v(.*)$"
[[ $version_line =~ $regex ]];
VERSION=${BASH_REMATCH[1]}
fi
echo "tag=$DOCKER_REPOSITORY:$VERSION" >> $GITHUB_OUTPUT
build-amd64:
name: "Build for linux/amd64"
runs-on: "ubuntu-larger"
needs:
- "image-info"
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
- name: "Set image meta"
run: |
echo "COMMIT_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
echo "TAG_NAME=${{ needs.image-info.outputs.git_tag }}" >> $GITHUB_ENV
echo "REPO_NAME=github_starknet-graph_graph-node" >> $GITHUB_ENV
echo "BRANCH_NAME=" >> $GITHUB_ENV
- name: "Build Docker image"
run: |
docker build --target graph-node-build \
--build-arg COMMIT_SHA=$COMMIT_SHA \
--build-arg REPO_NAME=$REPO_NAME \
--build-arg BRANCH_NAME=$BRANCH_NAME \
--build-arg TAG_NAME=$TAG_NAME \
-t graph-node-build \
-f docker/Dockerfile .
docker build --target graph-node \
--build-arg COMMIT_SHA=$COMMIT_SHA \
--build-arg REPO_NAME=$REPO_NAME \
--build-arg BRANCH_NAME=$BRANCH_NAME \
--build-arg TAG_NAME=$TAG_NAME \
-t ${{ needs.image-info.outputs.tag }}-amd64 \
-f docker/Dockerfile .
- name: "Export Docker image"
run: |
docker save ${{ needs.image-info.outputs.tag }}-amd64 | gzip > /tmp/amd64.tar.gz
- name: "Upload Docker image artifact"
uses: "actions/upload-artifact@v3"
with:
name: "amd64.tar.gz"
path: "/tmp/amd64.tar.gz"
build-arm64:
name: "Build for linux/arm64"
runs-on: "${{ needs.start-runner.outputs.label }}"
needs:
- "image-info"
- "start-runner"
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
- name: "Install Docker"
run: |
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
# Install the latest version
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
- name: "Set image meta"
run: |
echo "COMMIT_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
echo "TAG_NAME=${{ needs.image-info.outputs.git_tag }}" >> $GITHUB_ENV
echo "REPO_NAME=github_starknet-graph_graph-node" >> $GITHUB_ENV
echo "BRANCH_NAME=" >> $GITHUB_ENV
- name: "Build Docker image"
run: |
docker build --target graph-node-build \
--build-arg COMMIT_SHA=$COMMIT_SHA \
--build-arg REPO_NAME=$REPO_NAME \
--build-arg BRANCH_NAME=$BRANCH_NAME \
--build-arg TAG_NAME=$TAG_NAME \
-t graph-node-build \
-f docker/Dockerfile .
docker build --target graph-node \
--build-arg COMMIT_SHA=$COMMIT_SHA \
--build-arg REPO_NAME=$REPO_NAME \
--build-arg BRANCH_NAME=$BRANCH_NAME \
--build-arg TAG_NAME=$TAG_NAME \
-t ${{ needs.image-info.outputs.tag }}-arm64 \
-f docker/Dockerfile .
- name: "Export Docker image"
run: |
docker save ${{ needs.image-info.outputs.tag }}-arm64 | gzip > /tmp/arm64.tar.gz
- name: "Upload Docker image artifact"
uses: "actions/upload-artifact@v3"
with:
name: "arm64.tar.gz"
path: "/tmp/arm64.tar.gz"
push:
name: "Push Docker images"
runs-on: "ubuntu-latest"
needs:
- "image-info"
- "build-amd64"
- "build-arm64"
steps:
- name: "Download linux/amd64 image"
uses: "actions/download-artifact@v3"
with:
name: "amd64.tar.gz"
path: "/tmp/"
- name: "Download linux/arm64/v8 image"
uses: "actions/download-artifact@v3"
with:
name: "arm64.tar.gz"
path: "/tmp/"
- name: "Load Docker images"
run: |
docker load < /tmp/amd64.tar.gz
docker load < /tmp/arm64.tar.gz
- name: "Login to Docker Hub"
uses: "docker/[email protected]"
with:
username: "${{ secrets.DOCKER_HUB_USERNAME }}"
password: "${{ secrets.DOCKER_HUB_PASSWORD }}"
- name: "Push Docker images"
run: |
docker push ${{ needs.image-info.outputs.tag }}-amd64
docker push ${{ needs.image-info.outputs.tag }}-arm64
docker manifest create ${{ needs.image-info.outputs.tag }} \
${{ needs.image-info.outputs.tag }}-amd64 \
${{ needs.image-info.outputs.tag }}-arm64
docker manifest push ${{ needs.image-info.outputs.tag }}
stop-runner:
name: "Stop self-hosted EC2 runner"
runs-on: "ubuntu-latest"
needs:
- "start-runner"
- "build-arm64"
if: ${{ always() }}
steps:
- name: "Configure AWS credentials"
uses: "aws-actions/configure-aws-credentials@v1"
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: "Stop EC2 runner"
uses: "xJonathanLEI/ec2-github-runner@main"
with:
mode: "stop"
github-token: ${{ secrets.GH_PAT }}
label: "${{ needs.start-runner.outputs.label }}"
ec2-instance-id: "${{ needs.start-runner.outputs.ec2-instance-id }}"