forked from NethermindEth/juno
-
Notifications
You must be signed in to change notification settings - Fork 0
195 lines (164 loc) · 6.05 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
name: "Build multi-arch images"
on:
push:
tags:
- "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 crate info"
runs-on: "ubuntu-latest"
outputs:
repo: ${{ steps.derive.outputs.repo }}
tag: ${{ steps.derive.outputs.tag }}
env:
DOCKER_REPOSITORY: "starknet/juno-firehose"
steps:
- id: "derive"
name: "Derive image info from Git tag"
run: |
echo "repo=${DOCKER_REPOSITORY}" >> $GITHUB_OUTPUT
FULL_REF="${{ github.ref }}"
REGEX="^refs\/tags\/v(.*)$"
[[ $FULL_REF =~ $REGEX ]];
echo "tag=${DOCKER_REPOSITORY}:${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
build-amd64:
name: "Build for linux/amd64"
runs-on: "ubuntu-larger"
needs:
- "image-info"
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
- name: "Build Docker image"
run: |
docker build \
-t ${{ needs.image-info.outputs.tag }}-amd64 -f ./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: "Build Docker image"
run: |
docker build \
-t ${{ needs.image-info.outputs.tag }}-arm64 -f ./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 multi-arch manifest"
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 image"
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 create ${{ needs.image-info.outputs.repo }}:latest \
${{ needs.image-info.outputs.tag }}-amd64 \
${{ needs.image-info.outputs.tag }}-arm64
docker manifest push ${{ needs.image-info.outputs.tag }}
docker manifest push ${{ needs.image-info.outputs.repo }}:latest
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 }}"