-
Notifications
You must be signed in to change notification settings - Fork 1
145 lines (129 loc) · 5.59 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
name: Docker
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build_docker:
strategy:
matrix:
rust-features: [["default"], ["integration-testing", "admin"]]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: resolve_variables
run: |
echo "GIT_REVISION=$(git describe --always --dirty=-modified)" >> $GITHUB_OUTPUT
# Join features with , for RUST_FEATURES, but - for cache keys, where commas are illegal
echo "CACHE_KEY=${{ join(matrix.rust-features, '-') }}" >> $GITHUB_OUTPUT
echo "RUST_FEATURES=${{ join(matrix.rust-features, ',') }}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver: docker-container
use: true
- name: Build
uses: docker/build-push-action@v6
with:
context: .
push: false
load: true
cache-from: |
type=gha,scope=main-${{ steps.resolve_variables.outputs.CACHE_KEY }}
type=gha,scope=${{ github.ref_name }}-${{ steps.resolve_variables.outputs.CACHE_KEY }}
cache-to: type=gha,scope=${{ github.ref_name }}-${{ steps.resolve_variables.outputs.CACHE_KEY }},mode=max
build-args: |
GIT_REVISION=${{ steps.resolve_variables.outputs.GIT_REVISION }}
RUST_FEATURES=${{ steps.resolve_variables.outputs.RUST_FEATURES }}
# Test the dev compose, which should use the images built earlier. Technically this is only
# interesting when feature integration-testing is on, but we may as well exercise both.
#
# Bring the environment up, down and up again to ensure all services can restart
- name: Compose (dev)
id: compose-dev
run: |
docker compose -f compose.dev.yaml up --wait --wait-timeout 120
docker compose down
docker compose -f compose.dev.yaml up --wait --wait-timeout 120
- name: Inspect dev containers
if: ${{ failure() && steps.compose-dev.outcome != 'success' }}
run: |
docker compose ps --all
for NAME in `docker compose ps --all --format json | jq -r '.Name'`; do
echo $NAME
docker inspect $NAME
docker logs $NAME
done
# Test the non-dev compose, which we use for demo purposes. This pulls images from remote repos,
# so no need to build anything.
# Ideally we'd test on macOS and Windows, too, but those runners don't have Docker:
# https://github.com/actions/runner-images/issues/2150
# https://github.com/actions/runner/issues/904
compose:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
path: checkout
- uses: dtolnay/rust-toolchain@stable
- run: cargo build --package divviup-cli --profile release
working-directory: checkout
- run: |
mkdir compose
cp checkout/target/release/divviup compose/
cp checkout/compose.yaml compose/
- name: Compose
id: compose
run: docker compose up --wait --wait-timeout 120
working-directory: compose
- name: Demo script
id: demo-script
working-directory: compose
run: |
export DIVVIUP_API_URL=http://localhost:8080
export DIVVIUP_TOKEN=""
export DIVVIUP_ACCOUNT_ID=`./divviup account list | jq -r '.[0].id'`
printf 'account ID %s\n' $DIVVIUP_ACCOUNT_ID
AGGREGATOR_LIST=`./divviup aggregator list`
echo "aggregator list:"
echo $AGGREGATOR_LIST
LEADER_ID=`echo $AGGREGATOR_LIST | jq -r '.[] |= select(.name == "leader") |.[0].id'`
printf 'leader ID %s\n' $LEADER_ID
HELPER_ID=`echo $AGGREGATOR_LIST | jq -r '.[] |= select(.name == "helper") |.[0].id'`
printf 'helper ID %s\n' $HELPER_ID
CRED_OUTPUT=`./divviup collector-credential generate --save`
echo "collector credential:"
echo $CRED_OUTPUT
COLLECTOR_CREDENTIAL_PATH=${PWD}/`echo $CRED_OUTPUT | jq -r '.name' 2>/dev/null || echo ''`.json
printf 'collector credential path %s\n' $COLLECTOR_CREDENTIAL_PATH
COLLECTOR_CREDENTIAL_ID=`echo $CRED_OUTPUT | jq -r '.id' 2>/dev/null || echo ''`
printf 'collector credential ID %s\n' $COLLECTOR_CREDENTIAL_ID
TASK=`./divviup task create --name net-promoter-score \
--leader-aggregator-id $LEADER_ID --helper-aggregator-id $HELPER_ID \
--collector-credential-id $COLLECTOR_CREDENTIAL_ID \
--vdaf histogram --categorical-buckets 0,1,2,3,4,5,6,7,8,9,10 \
--min-batch-size 100 --max-batch-size 200 --time-precision 60sec`
echo "task:"
echo $TASK
TASK_ID=`echo $TASK | jq -r '.id'`
for i in {1..150}; do
measurement=$(( $RANDOM % 10 ))
./divviup dap-client upload --task-id $TASK_ID --measurement $measurement;
done
echo "finished uploading measurements"
sleep 120
./divviup dap-client collect \
--task-id $TASK_ID \
--collector-credential-file $COLLECTOR_CREDENTIAL_PATH \
--current-batch
- name: Inspect containers
if: ${{ failure() && (steps.compose.outcome != 'success' || steps.demo-script.outcome != 'success') }}
working-directory: compose
run: |
docker compose ps --all
for NAME in `docker compose ps --all --format json | jq -r '.Name'`; do
echo $NAME
docker inspect $NAME
docker logs $NAME
done