-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile
93 lines (68 loc) · 4.66 KB
/
Makefile
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
MAKEFLAGS += --silent
include .env
help:
sed -rn 's/^([a-zA-Z0-9_-]+):.*?##(.*).*?## (.*)/'$$(tput setaf 99)'make '$$(tput setaf 99)$$(tput bold)'\1|'$$(tput setaf 96)'\2'$$(tput sgr0)'|\3/p' < $(or ${makefile}, Makefile) | sort | column -t -s "|"
update: ## ## Updates codebase & rebuild. Used in production deploy pipeline
cd astro && npm i
rm -rf astro/src/pages/{it,es,fr}/* && \
docker-compose run -it --rm web npx astro-i18next generate && \
docker-compose run -it --rm web npm run build && \
docker-compose up -d web && \
docker-compose restart web
docker-compose build worker
docker-compose up -d worker
dump: dump-db zip-images
echo done
sync-s3: ## target=path/to/folder ## Downloads all remote images, creates a tgz archive, with a symlink to `latest`
$$(cat .env | grep AWS_ |xargs -L 1 echo export) && \
aws s3 sync s3://${AWS_S3_BUCKET} $(or ${target}, .data/web/images/)
zip-images:
cd $(or ${target}, .data/web/images/) && tar cfz ../gone.bike.images.`date +"%Y-%m-%d"`.tgz . && \
cd .. && rm -f gone.bike.images.latest.tgz && \
ln -s gone.bike.images.`date +"%Y-%m-%d"`.tgz gone.bike.images.latest.tgz
dump-db: ## target=path/to/folder ## Dumps db, nullifying local references to users and personal info about submission (email, ip)
docker-compose up -d postgresql
docker-compose exec postgresql pg_dump -U postgres \
-t language -t bike_brand -t bike_brand_model -t report -t report_files -t i18n -t i18n_translation \
-t directus_users -t directus_roles -t directus_files -t directus_folders | gzip -c > gone.bike.db-pre-dump.`date +"%Y%m%d"`.sql.gz
docker-compose exec postgresql psql -U postgres -c "DROP DATABASE dump;" || true
docker-compose exec postgresql psql -U postgres -c "CREATE DATABASE dump;"
docker-compose exec postgresql psql -U postgres -d dump -c "CREATE EXTENSION postgis;"
gunzip -c gone.bike.db-pre-dump.`date +"%Y%m%d"`.sql.gz | docker-compose exec -T postgresql psql -U postgres -d dump
rm -f gone.bike.db-pre-dump.`date +"%Y%m%d"`.sql.gz;
docker-compose exec postgresql psql -U postgres -d dump -c "UPDATE directus_files SET storage = 'local', modified_by = NULL, uploaded_by = NULL;"
docker-compose exec postgresql psql -U postgres -d dump -c "UPDATE report SET submit_by = null, user_created = NULL, user_updated = NULL, email = NULL;"
docker-compose exec postgresql psql -U postgres -d dump -c "UPDATE i18n_translation SET user_updated = NULL;"
docker-compose exec postgresql psql -U postgres -d dump -c "DELETE FROM directus_users;"
docker-compose exec postgresql psql -U postgres -d dump -c "DELETE FROM directus_roles;"
docker-compose exec postgresql pg_dump -U postgres -d dump --data-only \
-t language -t bike_brand -t bike_brand_model -t report -t report_files -t i18n -t i18n_translation \
-t directus_files -t directus_folders | gzip -c > gone.bike.db-dump.`date +"%Y%m%d"`.sql.gz
mv -v gone.bike.db-dump.`date +"%Y%m%d"`.sql.gz $(or ${target}, .data/web/) && \
cd $(or ${target}, .data/web/) && rm -f gone.bike.db-dump.latest.sql.gz && \
ln -s gone.bike.db-dump.`date +"%Y%m%d"`.sql.gz gone.bike.db-dump.latest.sql.gz
docker-compose exec postgresql psql -U postgres -c "DROP DATABASE dump;" || true
delete-old-tmp: ## ## Shortcut to remove files in temporary upload folder
find astro/public/tmp/ -mmin +459 -type f -print | grep -v 'tmp/\.gitignore$$' | xargs -r -L 1 rm -fv
weaviate-list-report-files: ## id=x ## Lists all weaviate entries associated to a specific report id
curl -s \
-X POST \
-H "Content-Type: application/json" \
-d '{ "query": "{ Get { Bike(where: { path: [\"report_id\"], operator: Equal, valueInt: '${id}' }) { _additional { id distance } } } }" }' \
${WEAVIATE_URI}/v1/graphql | jq -r .data.Get.Bike[]._additional.id
delete-weaviate-report-files: ## id=x ## Deletes all indexed entries from Weaviate related to a report id
${MAKE} weaviate-list-report-files id=${id} | while read wid; do \
echo "Deleting $$wid ..." && \
curl -X DELETE ${WEAVIATE_URI}/v1/objects/Bike/$$wid; \
done
count-weaviate-objects:
echo '{ "query": "{ Aggregate { Bike { meta { count } } } }" }' |\
tr -d "\n" | curl -s -X POST -H 'Content-Type: application/json' -d @- http://localhost:8080/v1/graphql |\
jq .data.Aggregate.Bike[0].meta.count
directus-schema-dump: ## ## Generates a Directus schema in YML format
docker-compose exec directus rm -f gb-schema.yml && \
docker-compose exec directus npx directus schema snapshot gb-schema.yml && \
docker-compose exec directus cat gb-schema.yml
directus-schema-apply: ## ## Applies local schema to directus (inverse operation of dump)
docker-compose cp database/directus-schema.yml directus:/directus/ && \
docker-compose exec directus npx directus schema apply directus-schema.yml