-
Notifications
You must be signed in to change notification settings - Fork 0
232 lines (200 loc) · 6.81 KB
/
images.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
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.
name: Create and publish a Docker images
on:
push: {}
env:
REGISTRY: ghcr.io
IMAGE_BASE_NAME: ${{ github.repository_owner }}
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
app:
- name: web_proxy
- name: static_datastore_builder
- name: public_node
env:
OUTPUTS_DIR: /tmp/outputs
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
"${{ env.REGISTRY }}/${{ env.IMAGE_BASE_NAME }}/${{ matrix.app.name }}"
tags: |
type=ref,event=branch,prefix=branch-
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push
id: build_and_push
uses: docker/build-push-action@v4
with:
context: .
file: build/docker/Dockerfile.${{ matrix.app.name }}
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/riscv64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Prepare artifacts
run: |
mkdir -p "$OUTPUTS_DIR"
jq -c '{
"${{ matrix.app.name }}": (
"${{ env.REGISTRY }}/${{ env.IMAGE_BASE_NAME }}/${{ matrix.app.name }}@" + .["containerimage.digest"]
)
}' <<EOF >> "$OUTPUTS_DIR/image"
${{ steps.build_and_push.outputs.metadata }}
EOF
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: image_${{ matrix.app.name }}
path: ${{ env.OUTPUTS_DIR }}/image
images:
runs-on: ubuntu-latest
needs: build-and-push-image
env:
OUTPUTS_DIR: /tmp/outputs
outputs:
images: ${{ steps.images.outputs.images }}
steps:
- uses: actions/download-artifact@v3
with:
path: /tmp/outputs
- run: ls /tmp/outputs || true
- run: cat /tmp/outputs/*/image || true
- id: images
run: echo "images=$( cat /tmp/outputs/*/image | jq -sc add )" >> "$GITHUB_OUTPUT"
test-docker-images:
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
needs: images
strategy:
matrix:
arch:
- linux/amd64
- linux/arm/v6
- linux/arm/v7
- linux/arm64
- linux/riscv64
env:
IMG_STATIC_DATASTORE_BUILDER: ${{ fromJSON(needs.images.outputs.images).static_datastore_builder }}
IMG_PUBLIC_NODE: ${{ fromJSON(needs.images.outputs.images).public_node }}
IMG_WEB_PROXY: ${{ fromJSON(needs.images.outputs.images).web_proxy }}
NETWORK_NAME: "cinode/${{ matrix.arch }}"
steps:
- name: Dump docker images info
run: |
jq . <<EOF
${{ needs.images.outputs.images }}
EOF
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Compile simple dataset
run: |
mkdir /tmp/cinode
docker run \
--platform "${{ matrix.arch }}" \
--rm \
--interactive \
--read-only \
--volume "/tmp/cinode:/tmp" \
--volume "$(pwd)/testvectors:/data:ro" \
--user $(id -u ${USER}):$(id -g ${USER}) \
"$IMG_STATIC_DATASTORE_BUILDER" \
compile \
--source /data \
--destination /tmp/encrypted \
> /tmp/cinode/compile_result.json
- name: Create docker network
run: |
docker network create "$NETWORK_NAME"
- name: Run public datastore node
run: |
docker run \
--platform "${{ matrix.arch }}" \
--detach \
--read-only \
--network "$NETWORK_NAME" \
--volume "/tmp/cinode/encrypted:/data:ro" \
--env CINODE_MAIN_DATASTORE=/data \
--name datastore \
"$IMG_PUBLIC_NODE"
- name: Run web proxy
run: |
docker run \
--platform "${{ matrix.arch }}" \
--detach \
--read-only \
--network "$NETWORK_NAME" \
--env CINODE_ENTRYPOINT="$( cat /tmp/cinode/compile_result.json | jq -r .entrypoint )" \
--env CINODE_ADDITIONAL_DATASTORE_1="http://datastore:8080/" \
--name web_proxy \
"$IMG_WEB_PROXY"
- name: Inspect docker environment
run: docker ps
- name: Check if can fetch files from cinode proxy
run: |
docker run \
--rm \
--interactive \
--network "$NETWORK_NAME" \
--read-only \
--mount type=tmpfs,destination=/tmp \
--volume "$(pwd)/testvectors:/data:ro" \
--user $(id -u ${USER}):$(id -g ${USER}) \
curlimages/curl \
sh \
-c '
set -euo pipefail
cd /data
while read f; do
FILE_HASH="$( cat "$f" | sha256sum )"
WEB_HASH="$( curl -s "http://web_proxy:8080/${f}" | sha256sum )"
echo "${FILE_HASH} ${f}"
diff <( echo "$FILE_HASH" ) <( echo "$WEB_HASH" )
done < <( find . -type f -print )
'
- name: Dump datastore logs
if: always()
run: docker logs datastore
- name: Dump web_proxy logs
if: always()
run: docker logs web_proxy
- name: Inspect docker environment
if: always()
run: docker ps