-
Notifications
You must be signed in to change notification settings - Fork 0
220 lines (193 loc) · 7.4 KB
/
ingest.yaml
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
name: ingest
on:
# push: {}
schedule:
- cron: "45 */3 * * *"
workflow_dispatch: {}
concurrency: ingest
env:
AWS_ROUTE53_HOSTED_ZONE_ID: Z25CPWZR4S9IHS
AWS_ROUTE53_TTL: 60
AWS_S3_BASE_URL: s3://datasets.kamu.dev/odf/v2/contrib
jobs:
update:
name: Update Dataset
permissions:
id-token: write
strategy:
fail-fast: false
# TODO: We use DNSLink instead of IPNS due to IPNS's current usability issues like:
# - frequent loss of writes
# - lack of read-after-write consistency
# - abysmal resolution times and frequent timeouts
matrix:
include:
- dataset_name: com.cryptocompare.ohlcv.eth-usd
dnslink_subdomain: _dnslink.com.cryptocompare.ohlcv.eth-usd.ipns.kamu.dev
- dataset_name: co.alphavantage.tickers.daily.spy
dnslink_subdomain: _dnslink.co.alphavantage.tickers.daily.spy.ipns.kamu.dev
- dataset_name: net.rocketpool.reth.tokens-minted
dnslink_subdomain: _dnslink.net.rocketpool.reth.tokens-minted.ipns.kamu.dev
- dataset_name: net.rocketpool.reth.tokens-burned
dnslink_subdomain: _dnslink.net.rocketpool.reth.tokens-burned.ipns.kamu.dev
- dataset_name: com.github.kamu-data.clones
- dataset_name: com.github.kamu-data.stargazers
- dataset_name: com.github.kamu-data.views
- dataset_name: com.youtube.channel.kamu-data.stats
- dataset_name: com.youtube.channel.kamu-data.videos.stats
- dataset_name: com.youtube.playlist.featuring-kamu-data.videos.stats
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
path: kamu-contrib
- uses: oduwsdl/setup-ipfs@main
with:
ipfs_version: ^0.29
run_daemon: true
- name: Install kamu
shell: bash
run: |
curl -s "https://get.kamu.dev" | sh
- name: Print info
shell: bash
run: |
echo "Work dir: $PWD"
echo "IPFS version:"
ipfs version
ipfs id
echo "Podman version:"
podman version
echo "AWS CLI version:"
aws --version
echo "Kamu version:"
kamu --version
- uses: actions/cache@v4
with:
key: ingest-${{ matrix.dataset_name }}
save-always: true
path: |
.kamu
- uses: aws-actions/configure-aws-credentials@v4
with:
audience: sts.amazonaws.com
aws-region: us-west-2
role-to-assume: ${{ secrets.AWS_IAM_ROLE }}
- name: Configure
shell: bash
run: |
# Setup kamu config
echo "
kind: CLIConfig
version: 1
content:
source:
ethereum:
rpcEndpoints:
- chainId: 1
chainName: Ethereum Mainnet
nodeUrl: ${{ secrets.INFURA_ETH_MAINNET_WS }}
" > .kamuconfig
# Add pinning service
ipfs pin remote service add pinata https://api.pinata.cloud/psa "${{ secrets.PINATA_ACCESS_TOKEN }}"
# Create workspace
kamu init --exists-ok
kamu list --output-format table -w
- name: Sync dataset from S3
shell: bash
run: |
kamu -v pull "$AWS_S3_BASE_URL/${{ matrix.dataset_name }}" --as ${{ matrix.dataset_name }} --no-alias
kamu list --output-format table -w
- name: Ingest new data
shell: bash
env:
ALPHA_VANTAGE_API_KEY: ${{ secrets.ALPHA_VANTAGE_API_KEY }}
YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }}
GH_TOKEN: ${{ secrets.GITHUBSTATS_TOKEN }}
run: |
kamu -v pull --fetch-uncacheable ${{ matrix.dataset_name }}
kamu list --output-format table -w
- name: Publish dataset to S3
shell: bash
run: |
kamu push ${{ matrix.dataset_name }} --to "$AWS_S3_BASE_URL/${{ matrix.dataset_name }}" --no-alias
- name: Resolve current dataset CID
id: resolve-dataset
if: ${{ matrix.dnslink_subdomain }}
shell: bash
run: |
ipfs_cid=$( \
aws route53 list-resource-record-sets \
--hosted-zone-id $AWS_ROUTE53_HOSTED_ZONE_ID \
| jq -r ".ResourceRecordSets[] | select(.Name == \"${{ matrix.dnslink_subdomain }}.\") | .ResourceRecords[0].Value" \
| grep -oE '[^/]+"$' \
| grep -oE '^[^"]+'
)
echo "Current IPFS CID (from DNSLink): $ipfs_cid"
echo "CID=$ipfs_cid" >> $GITHUB_OUTPUT
- name: Pin dataset in Pinata
if: ${{ matrix.dnslink_subdomain }}
shell: bash
env:
OLD_CID: ${{ steps.resolve-dataset.outputs.CID }}
PIN_TRIES: "10"
run: |
# Add dataset to IPFS
ipfs_cid=$(kamu -v system ipfs add ${{ matrix.dataset_name }})
echo "New IPFS CID: $ipfs_cid"
if [ "$OLD_CID" == "$ipfs_cid" ]; then
echo "CID didn't change - skipping publishing"
else
for i in $(seq 1 $PIN_TRIES); do
echo "Pinning CID (attempt $i)"
if ipfs pin remote add --service=pinata --name=${{ matrix.dataset_name }} $ipfs_cid; then
echo "Successfully pinned"
break
else
echo "Pinning service returned an error"
# TODO: Remove this debug stuff when pinning is reliable
peers_num=$(ipfs swarm peers | wc -l)
echo "IPFS is connected to $peers_num peers"
echo "IPFS addresses:"
ipfs id
if curl -s --fail "https://dweb.link/ipfs/$ipfs_cid" > /dev/null; then
echo "CID is RESOLVABLE via public gateway"
else
echo "CID is NOT resolvable via public gateway"
fi
if [ $i == $PIN_TRIES ]; then
echo "Failed to pin CID after $PIN_TRIES attempts"
# TODO: Pinning fails so often that we have to ignore this for now
# not to obscure ingest errors.
exit 0
fi
fi
done
# Update DNSLink entry
echo "{
\"Comment\": \"GHAction update of DNSLink record\",
\"Changes\": [
{
\"Action\": \"UPSERT\",
\"ResourceRecordSet\": {
\"Name\": \"${{ matrix.dnslink_subdomain }}.\",
\"Type\": \"TXT\",
\"TTL\": $AWS_ROUTE53_TTL,
\"ResourceRecords\": [{
\"Value\": \"\\\"dnslink=/ipfs/$ipfs_cid\\\"\"
}]
}
}
]
}" > dns-upsert.json
echo "Updating DNSLink entry with: $(cat dns-upsert.json)"
aws route53 change-resource-record-sets --hosted-zone-id $AWS_ROUTE53_HOSTED_ZONE_ID --change-batch file://dns-upsert.json
fi
- name: Cleanup old pins
if: ${{ matrix.dnslink_subdomain }}
shell: bash
env:
PINATA_ACCESS_TOKEN: ${{ secrets.PINATA_ACCESS_TOKEN }}
run: |
kamu-contrib/.ci/pinata.py unpin-old --name ${{ matrix.dataset_name }} --keep-latest 1