Skip to content

Commit ddddf63

Browse files
gdixonGerald Iakobinyi-Pich
andauthored
fix: adds bash script to install docker for celery servers (#10661)
* fix: adds bash script to install docker * fix: adds docker-compose to docker install script * Adding docker-compose to run celery workers * fix: moves deps to test.txt and imports inside fns * fix: only run calculate_trust_bonus on gitcoin_passport queue Co-authored-by: Gerald Iakobinyi-Pich <gerald@gitcoin.co>
1 parent 3cb262d commit ddddf63

File tree

7 files changed

+63
-6
lines changed

7 files changed

+63
-6
lines changed

app/app/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ def callback(request):
537537
CELERY_RESULT_BACKEND = env('CELERY_RESULT_BACKEND', default=CACHEOPS_REDIS)
538538
# https://docs.celeryproject.org/en/latest/userguide/configuration.html#std-setting-task_routes
539539
CELERY_ROUTES = [
540-
('dashboard.tasks.calculate_trust_bonus', {'queue': 'high_priority'}),
540+
('dashboard.tasks.calculate_trust_bonus', {'queue': 'gitcoin_passport'}),
541541
('grants.tasks.process_grant_contribution', {'queue': 'high_priority'}),
542542
('grants.tasks.batch_process_grant_contributions', {'queue': 'high_priority'}),
543543
('kudos.tasks.mint_token_request', {'queue': 'high_priority'}),

app/dashboard/passport_reader.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import hashlib
33
import json
44

5-
import dag_cbor
6-
75
# Making GET requests against the CERAMIC_URL to read streams
86
import requests
97

@@ -47,6 +45,9 @@ def get_did(address, network="1"):
4745
return f"did:pkh:eip155:{network}:{address}"
4846

4947
def get_stream_ids(did, ids=[CERAMIC_GITCOIN_PASSPORT_STREAM_ID]):
48+
# delay import as this is only available in celery envs
49+
import dag_cbor
50+
5051
# encode the input genesis with cborg (Concise Binary Object Representation)
5152
input_bytes = dag_cbor.encode({"header":{"controllers":[did],"family":"IDX"}})
5253
# hash the input_bytes and pad with STREAMID_CODEC and type (as bytes)

app/dashboard/tasks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from django.http import HttpRequest
1515
from django.utils import timezone
1616

17-
import didkit
1817
from app.services import RedisService
1918
from app.utils import get_location_from_ip
2019
from celery import app, group
@@ -496,6 +495,9 @@ def calculate_trust_bonus(user_id, did, address):
496495
:return: None
497496
"""
498497

498+
# delay import as this is only available in celery envs
499+
import didkit
500+
499501
try:
500502
# Verify that this DID is not associated to any other profile.
501503
# We want to avoid the same user creating multiple accounts and re-using the same did

bin/docker-install.bash

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/local/bin/dumb-init /bin/bash
2+
3+
# ==================================================
4+
# Install docker
5+
# ==================================================
6+
7+
# add repo
8+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
9+
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
10+
sudo apt-get update
11+
12+
# use docker-ce over default
13+
apt-cache policy docker-ce
14+
15+
# install from docker-ce
16+
sudo apt-get install -y docker-ce
17+
18+
# add current user to dockers usergroup
19+
sudo usermod -aG docker ${USER}
20+
21+
# download and expose docker-compose
22+
sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
23+
sudo chmod +x /usr/local/bin/docker-compose

docker-compose-celery.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version: '3'
2+
3+
services:
4+
worker_1: &worker
5+
restart: unless-stopped
6+
logging:
7+
options:
8+
max-size: '100m'
9+
max-file: '10'
10+
driver: json-file
11+
12+
# image: gitcoin/web:034f6cde3c
13+
image: gitcoin/web:817ff194e7
14+
15+
volumes:
16+
- .:/code
17+
18+
working_dir: /code/app
19+
command: ["celery", "-A", "taskapp", "worker", "-Q", "gitcoin_passport,high_priority,celery"]
20+
21+
worker_2:
22+
<<: *worker
23+
command: ["celery", "-A", "taskapp", "worker", "-Q", "gitcoin_passport,high_priority,celery"]
24+
25+
worker_3:
26+
<<: *worker
27+
command: ["celery", "-A", "taskapp", "worker", "-Q", "gitcoin_passport,celery"]
28+
29+
worker_4:
30+
<<: *worker
31+
command: ["celery", "-A", "taskapp", "worker", "-Q", "gitcoin_passport,celery"]

requirements/base.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,3 @@ unidecode==1.2.0
121121
drf-flex-fields==0.9.1
122122
pandas
123123
django-svg-image-form-field==1.0.1
124-
git+https://github.com/gdixon/dag-cbor.git#egg=dag-cbor
125-
didkit==0.2.1

requirements/test.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ django-debug-toolbar==3.2.4
1717
ipfshttpclient==0.6.0
1818
dj_static==0.0.6
1919
livereload==2.6.3
20+
git+https://github.com/gdixon/dag-cbor.git#egg=dag-cbor
21+
didkit==0.2.1

0 commit comments

Comments
 (0)