Skip to content

Commit 928c04c

Browse files
committed
add updater
1 parent ff2d811 commit 928c04c

File tree

4 files changed

+144
-0
lines changed

4 files changed

+144
-0
lines changed

updater/Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM docker:dind
2+
3+
RUN apk update
4+
RUN apk add curl python3 git bash dos2unix openssh build-base python3-dev
5+
6+
RUN ln -sf $(ls /usr/bin/easy_install*) /usr/bin/easy_install
7+
RUN easy_install pip
8+
RUN pip install docker-compose
9+
10+
RUN mkdir /updater
11+
WORKDIR /updater
12+
COPY . /updater/
13+
RUN dos2unix cmd.bash
14+
15+
ENV COMMIT_NAME 'Updater Bot'
16+
ENV COMMIT_EMAIL ''
17+
ENV COMMIT_MESSAGE '[Updater Bot] Regenerate data'
18+
ENV BRANCH_NAME 'updater-bot'
19+
ENV REPO_POKEAPI '[email protected]:PokeAPI/pokeapi'
20+
ENV REPO_DATA '[email protected]:PokeAPI/api-data'
21+
22+
CMD bash cmd.bash

updater/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Updater Bot
2+
3+
## Usage
4+
5+
First, make sure you can read/write the target repository over SSH.
6+
Launch the bot with a volume containing the SSH keys to `/root/.ssh` and an environment variable for email address.
7+
Since this container runs Docker within itself, it needs to run in privileged mode.
8+
9+
```
10+
docker run --privileged -v ~/.ssh:/root/.ssh -e [email protected] sargunv/pokeapi-ditto:updater
11+
```
12+
13+
**Note:** Due to lack of support for file permissions, this does not work on Docker for Windows.
14+
15+
## Environment Variables
16+
17+
### Required
18+
19+
- `COMMIT_EMAIL`
20+
21+
### Optional
22+
23+
See [the Dockerfile](updater/Dockerfile) for the defaults.
24+
25+
- `COMMIT_NAME`
26+
- `COMMIT_MESSAGE`
27+
- `BRANCH_NAME`
28+
- `REPO_POKEAPI`
29+
- `REPO_DITTO`

updater/cmd.bash

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
3+
[ -z "${COMMIT_NAME}" ] && { echo "Need to set COMMIT_NAME"; exit 1; }
4+
[ -z "${COMMIT_EMAIL}" ] && { echo "Need to set COMMIT_EMAIL"; exit 1; }
5+
[ -z "${COMMIT_MESSAGE}" ] && { echo "Need to set COMMIT_MESSAGE"; exit 1; }
6+
[ -z "${REPO_POKEAPI}" ] && { echo "Need to set REPO_POKEAPI"; exit 1; }
7+
[ -z "${REPO_DATA}" ] && { echo "Need to set REPO_DATA"; exit 1; }
8+
[ -z "${BRANCH_NAME}" ] && { echo "Need to set BRANCH_NAME"; exit 1; }
9+
10+
set -e
11+
set -o pipefail
12+
set -x
13+
14+
export COMPOSE_INTERACTIVE_NO_CLI=1
15+
16+
dockerd --host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:2375 &> /dev/null &
17+
18+
git clone --depth=1 "$REPO_POKEAPI" pokeapi
19+
git clone --depth=1 "$REPO_DATA" api-data
20+
21+
# set up the pokeapi side
22+
cd pokeapi
23+
git apply ../disable-rate-limit.patch
24+
25+
docker volume create --name=redis_data
26+
docker volume create --name=pg_data
27+
docker-compose up -d
28+
29+
docker-compose exec -T app python manage.py migrate
30+
docker-compose exec -T app sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell'
31+
32+
# set up the data side
33+
cd ../api-data
34+
git branch -D "$BRANCH_NAME" || true
35+
git branch "$BRANCH_NAME"
36+
git checkout "$BRANCH_NAME"
37+
38+
pip install -r requirements.txt
39+
rm -r ./data
40+
ditto clone --src-url http://localhost/ --dest-dir ./data
41+
ditto analyze --api-dir ./data/api --schema-dir ./data/schema
42+
43+
# commit and push
44+
git add data
45+
git config user.name "$COMMIT_NAME"
46+
git config user.email "$COMMIT_EMAIL"
47+
git commit -m "$COMMIT_MESSAGE"
48+
git push -fu origin "$BRANCH_NAME"

updater/disable-rate-limit.patch

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
diff --git a/Resources/nginx/nginx.conf b/Resources/nginx/nginx.conf
2+
index a8841fe..8346c0a 100644
3+
--- a/Resources/nginx/nginx.conf
4+
+++ b/Resources/nginx/nginx.conf
5+
@@ -38,7 +38,7 @@ http {
6+
server app:8000 fail_timeout=0;
7+
}
8+
9+
- limit_req_zone $binary_remote_addr zone=api:10m rate=2r/s;
10+
+ # limit_req_zone $binary_remote_addr zone=api:10m rate=2r/s;
11+
12+
server {
13+
listen 80 deferred;
14+
@@ -72,7 +72,7 @@ http {
15+
add_header Cache-Control "public";
16+
add_header Pragma public;
17+
18+
- limit_req zone=api burst=10;
19+
+ # limit_req zone=api burst=10;
20+
21+
proxy_set_header X-Real-IP $remote_addr;
22+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
23+
diff --git a/config/settings.py b/config/settings.py
24+
index 1b2731b..44bab3e 100755
25+
--- a/config/settings.py
26+
+++ b/config/settings.py
27+
@@ -161,12 +161,12 @@ REST_FRAMEWORK = {
28+
'PAGE_SIZE': 20,
29+
30+
'PAGINATE_BY': 20,
31+
- 'DEFAULT_THROTTLE_CLASSES': (
32+
- 'rest_framework.throttling.AnonRateThrottle',
33+
- ),
34+
- 'DEFAULT_THROTTLE_RATES': {
35+
- 'anon': '1000/hour'
36+
- }
37+
+# 'DEFAULT_THROTTLE_CLASSES': (
38+
+# 'rest_framework.throttling.AnonRateThrottle',
39+
+# ),
40+
+# 'DEFAULT_THROTTLE_RATES': {
41+
+# 'anon': '1000/hour'
42+
+# }
43+
}
44+
45+
MARKDOWN_DEUX_STYLES = {

0 commit comments

Comments
 (0)