Skip to content

Commit 9acd04d

Browse files
committed
Add ToDo Bot 2.0.0
1 parent 2bb1653 commit 9acd04d

File tree

181 files changed

+3836
-5550
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+3836
-5550
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/__pycache__

.github/workflows/actions.yml

-65
This file was deleted.

.gitignore

+111-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,111 @@
1-
*__pycache__*
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
48+
.pytest_cache/
49+
50+
# Translations
51+
*.mo
52+
*.pot
53+
54+
# Django stuff:
55+
*.log
56+
local_settings.py
57+
db.sqlite3
58+
59+
# Flask stuff:
60+
instance/
61+
.webassets-cache
62+
63+
# Scrapy stuff:
64+
.scrapy
65+
66+
# Sphinx documentation
67+
docs/_build/
68+
69+
# PyBuilder
70+
target/
71+
72+
# Jupyter Notebook
73+
.ipynb_checkpoints
74+
75+
# pyenv
76+
.python-version
77+
78+
# celery beat schedule file
79+
celerybeat-schedule
80+
81+
# SageMath parsed files
82+
*.sage.py
83+
84+
# Environments
85+
.env
86+
.venv
87+
env/
88+
venv/
89+
ENV/
90+
env.bak/
91+
venv.bak/
92+
93+
# Spyder project settings
94+
.spyderproject
95+
.spyproject
96+
97+
# Rope project settings
98+
.ropeproject
99+
100+
# mkdocs documentation
101+
/site
102+
103+
# mypy
104+
.mypy_cache/
105+
106+
.idea/
107+
.vscode/
108+
109+
static/
110+
111+
file_storage/

.gitlab-ci.yml

+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# YAML objects named with dot is anchors, which are not recognized as jobs
2+
.run_bot: &run_bot
3+
- docker rm -f ${CONTAINER_NAME} || true
4+
- docker pull ${CONTAINER_RELEASE_IMAGE}
5+
# Add new envs here. Don't forget to add them in exmaple.env and docker-compose files.
6+
- docker run
7+
-d
8+
--name ${CONTAINER_NAME}
9+
--restart always
10+
--label traefik.http.routers.${BOT_PROJECT_NAME}.rule="Host(\`${BOT_URL}\`)"
11+
--label traefik.enable=true
12+
--label traefik.http.services.${BOT_PROJECT_NAME}.loadbalancer.server.port="8000"
13+
--log-opt max-size=10m
14+
--log-opt max-file=5
15+
-e POSTGRES_DSN="${POSTGRES_DSN}"
16+
-e REDIS_DSN="${REDIS_DSN}"
17+
-e BOT_CREDENTIALS="${BOT_CREDENTIALS}"
18+
-e DEBUG="${DEBUG:-false}"
19+
$CONTAINER_RELEASE_IMAGE
20+
21+
.create_db: &create_db
22+
- psql -c "create user \"${POSTGRES_USER}\"" postgres || true
23+
- psql -c "alter user \"${POSTGRES_USER}\" with password '${POSTGRES_PASSWORD}'" postgres
24+
- psql -c "create database \"${POSTGRES_DB}\" with owner \"${POSTGRES_USER}\"" postgres || true
25+
26+
.install_dependencies: &install_dependencies
27+
- echo -e "machine ${GIT_HOST}\nlogin gitlab-ci-token\npassword ${CI_JOB_TOKEN}" > ~/.netrc
28+
- pip install -q poetry
29+
- poetry config virtualenvs.in-project true
30+
- poetry install
31+
32+
.cache_dependencies: &cache_dependencies
33+
key:
34+
files:
35+
- poetry.lock
36+
prefix: "venv"
37+
paths:
38+
- .cache/pip
39+
- .venv
40+
41+
.postgres_envs: &postgres_envs
42+
- POSTGRES_USER=${CONTAINER_NAME}
43+
- POSTGRES_DB=${CONTAINER_NAME}
44+
- POSTGRES_PASSWORD=$(openssl rand -hex 16)
45+
- POSTGRES_HOST=${PROD_POSTGRES_HOST}
46+
- POSTGRES_DSN=postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST/$POSTGRES_DB
47+
48+
# Jobs
49+
variables:
50+
GIT_DEPTH: 1 # Fetch only latest commit
51+
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
52+
53+
stages:
54+
- check
55+
- build
56+
- deploy
57+
58+
default:
59+
interruptible: true
60+
61+
lint:
62+
image: python:3.10
63+
stage: check
64+
tags:
65+
- docker
66+
cache: *cache_dependencies
67+
before_script:
68+
- *install_dependencies
69+
script:
70+
- poetry run ./scripts/lint
71+
72+
test:
73+
image: python:3.10
74+
stage: check
75+
tags:
76+
- docker
77+
services:
78+
- postgres:11.4-alpine
79+
- redis:6.0.1-alpine
80+
cache: *cache_dependencies
81+
variables:
82+
BOT_CREDENTIALS: cts.example.com@secret@123e4567-e89b-12d3-a456-426655440000
83+
POSTGRES_DSN: postgres://postgres:postgres@postgres/postgres
84+
REDIS_DSN: redis://redis/0
85+
before_script:
86+
- *install_dependencies
87+
script:
88+
- poetry run pytest --cov-config=setup.cfg
89+
coverage: '/Total coverage: \d\d\d.\d\d%/'
90+
91+
build:
92+
image: docker:latest
93+
stage: build
94+
tags:
95+
- docker
96+
before_script:
97+
- docker info
98+
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
99+
- CONTAINER_RELEASE_IMAGE="$CI_REGISTRY_IMAGE:${CI_COMMIT_TAG:-$CI_COMMIT_REF_SLUG}"
100+
script:
101+
- docker pull $CONTAINER_RELEASE_IMAGE || true
102+
- docker build
103+
--cache-from $CONTAINER_RELEASE_IMAGE
104+
--build-arg GIT_HOST=$GIT_HOST
105+
--build-arg CI_JOB_TOKEN=$CI_JOB_TOKEN
106+
--build-arg CI_COMMIT_SHA=$CI_COMMIT_SHA
107+
--force-rm
108+
-t $CONTAINER_RELEASE_IMAGE .
109+
- docker push $CONTAINER_RELEASE_IMAGE
110+
- docker rmi $CONTAINER_RELEASE_IMAGE
111+
112+
deploy.botstest:
113+
image: docker:latest
114+
stage: deploy
115+
tags:
116+
- bots-test
117+
only:
118+
- branches
119+
when: manual
120+
environment:
121+
name: test
122+
on_stop: deploy.botstest.stop
123+
variables:
124+
# https://docs.gitlab.com/ee/ci/runners/configure_runners.html#git-strategy
125+
GIT_STRATEGY: none
126+
before_script:
127+
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
128+
- if [ -z ${BOT_PROJECT_NAME:-} ]; then BOT_PROJECT_NAME=${CI_PROJECT_PATH_SLUG#"$CI_PROJECT_NAMESPACE-"}; fi
129+
- CONTAINER_NAME=$BOT_PROJECT_NAME-`echo $CI_COMMIT_REF_NAME | sed 's/^.*\///'`
130+
- CONTAINER_RELEASE_IMAGE="$CI_REGISTRY_IMAGE:${CI_COMMIT_TAG:-$CI_COMMIT_REF_SLUG}"
131+
- BOT_URL="${BOT_PROJECT_NAME}.${DEV_SERVER_HOST}"
132+
- BOT_CREDENTIALS=$DEV_BOT_CREDENTIALS
133+
- *postgres_envs
134+
- REDIS_DSN=redis://${PROD_REDIS_HOST}/1
135+
script:
136+
- echo "Use URL 'https://${BOT_URL}/' in your cts admin site"
137+
- echo "Using credentials ${BOT_CREDENTIALS}"
138+
- echo "Deploing Docker container ${CONTAINER_NAME}"
139+
- *create_db
140+
- *run_bot
141+
142+
deploy.botstest.stop:
143+
when: manual
144+
environment:
145+
name: test
146+
action: stop
147+
extends: deploy.botstest
148+
script:
149+
- docker rm -f ${CONTAINER_NAME} || true
150+
- psql -c "drop database \"${POSTGRES_DB}\"" postgres || true
151+
- psql -c "drop user \"${POSTGRES_USER}\"" postgres || true
152+
153+
deploy.botsprod:
154+
stage: deploy
155+
image: docker:latest
156+
tags:
157+
- bots-prod
158+
only:
159+
# Note the bots-prod worker requires branch to be protected
160+
- master
161+
when: manual
162+
environment:
163+
name: production
164+
variables:
165+
# https://docs.gitlab.com/ee/ci/runners/configure_runners.html#git-strategy
166+
GIT_STRATEGY: none
167+
before_script:
168+
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
169+
- if [ -z ${BOT_PROJECT_NAME:-} ]; then BOT_PROJECT_NAME=${CI_PROJECT_PATH_SLUG#"$CI_PROJECT_NAMESPACE-"}; fi
170+
- CONTAINER_NAME=$BOT_PROJECT_NAME
171+
- CONTAINER_RELEASE_IMAGE="$CI_REGISTRY_IMAGE:${CI_COMMIT_TAG:-$CI_COMMIT_REF_SLUG}"
172+
- BOT_URL="${BOT_PROJECT_NAME}.${PROD_SERVER_HOST}"
173+
- *postgres_envs
174+
- REDIS_DSN=redis://${PROD_REDIS_HOST}/1
175+
script:
176+
- echo "Use URL 'https://${BOT_URL}/' in your cts admin site"
177+
- echo "Using credentials ${BOT_CREDENTIALS}"
178+
- echo "Deploing Docker container ${CONTAINER_NAME}"
179+
- *create_db
180+
- *run_bot

0 commit comments

Comments
 (0)