Skip to content

Commit 0c8b7ec

Browse files
committed
First import
0 parents  commit 0c8b7ec

File tree

344 files changed

+41361
-0
lines changed

Some content is hidden

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

344 files changed

+41361
-0
lines changed

.agignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
database/migration/versions

.coveragerc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[run]
2+
concurrency = gevent
3+
branch = True
4+
5+
[report]
6+
omit =
7+
huskar_api/contrib/*

.editorconfig

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
insert_final_newline = true
9+
10+
[*.py]
11+
indent_style = space
12+
indent_size = 4
13+
14+
[*.{yml,yaml,json}]
15+
indent_style = space
16+
indent_size = 2
17+
18+
[Makefile]
19+
indent_style = tab
20+
indent_size = 4
21+
22+
[Dockerfile,*.dockerfile]
23+
indent_style = space
24+
indent_size = 4
25+
26+
[Vagrantfile]
27+
indent_style = space
28+
indent_size = 2
29+
language = ruby
30+
31+
[Jenkinsfile]
32+
indent_style = space
33+
indent_size = 2
34+
language = groovy

.env.example

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
HUSKAR_API_DEBUG=true
2+
HUSKAR_API_TESTING=true
3+
HUSKAR_API_SECRET_KEY=foobar
4+
HUSKAR_API_ZK_SERVERS=127.0.0.1:2181,127.0.0.2:2181
5+
DATABASE_DEFAULT_URL=mysql+pymysql://root@localhost:3306/huskar?charset=utf8mb4
6+
REDIS_DEFAULT_URL=redis://localhost:6379

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tests/test_extras/test_email_snapshots/*.html linguist-generated=true
2+
docs/assets/index.rst linguist-generated=true

.github/CONTRIBUTING.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## Contributing Guide
2+
3+
1. Keep your branch up-to-date
4+
- `git fetch upstream`
5+
- `git rebase upstream/master`
6+
2. Squash or reword commits for clear history
7+
- `git rebase -i --autosquash upstream/master`
8+
3. Create a pull request
9+
- Edit the description
10+
- Invite reviewers
11+
- Assign someone who can merge pull requests
12+
- Choose labels and milestone
13+
- If there is a topic-related issue, attach it
14+
15+
**IMPORTANT** The `master` branch should **be always deployable**.
16+
Once you break the `master` via a pull request, choose a quickest way,
17+
**revert it** or **fix it** as soon as possible.
18+
19+
The regression test must be included in all hotfix pull requests.

.github/ISSUE_TEMPLATE.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Context
2+
3+
<!-- DO NOT include any token or password here. -->
4+
5+
## Description
6+
7+
<!-- Your description here. -->

.github/PULL_REQUEST_TEMPLATE.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### Description
2+
3+
<!-- Your description here. -->
4+
5+
### Reference
6+
7+
<!--
8+
Remove this section at will, if your pull request is standalone.
9+
10+
-->
11+
12+
### Todo
13+
14+
<!--
15+
Remove this section at will, if your pull request is not WIP.
16+
17+
- [ ] Step 1
18+
- [ ] Step 2
19+
-->

.gitignore

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*.swp
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
/env/
12+
env_new
13+
/build/
14+
develop-eggs/
15+
dist/
16+
downloads/
17+
eggs/
18+
.eggs/
19+
/lib/
20+
lib64/
21+
parts/
22+
sdist/
23+
var/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
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+
48+
# Translations
49+
*.mo
50+
*.pot
51+
52+
# Django stuff:
53+
*.log
54+
55+
# Sphinx documentation
56+
docs/_build/
57+
58+
# PyBuilder
59+
target/
60+
61+
# PyCharm
62+
.idea/
63+
.python-version
64+
65+
# rope
66+
.ropeproject/
67+
68+
# Jenkins
69+
junit.xml
70+
71+
# dotenv
72+
.env

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Changlog
2+
=========
3+
4+
0.242.4 (2019-10-31)
5+
---------------------
6+
7+
* First import.

Dockerfile

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM python:2.7.10-slim
2+
3+
RUN apt-get update && apt-get install -y --no-install-recommends \
4+
build-essential \
5+
git \
6+
libpq-dev \
7+
librabbitmq-dev \
8+
libncurses5-dev \
9+
mariadb-client \
10+
shellcheck \
11+
golang-go
12+
13+
ENV GOPATH "/opt/gopath"
14+
RUN go get -u github.com/client9/misspell/cmd/misspell
15+
16+
RUN pip install -U virtualenv && virtualenv /opt/huskar_api
17+
ENV VIRTUAL_ENV "/opt/huskar_api"
18+
19+
ENV PATH "$VIRTUAL_ENV/bin:$GOPATH/bin:$PATH"
20+
21+
ADD . /srv/huskar_api
22+
WORKDIR /srv/huskar_api
23+
24+
RUN pip install --no-cache-dir -r requirements-dev.txt
25+
26+
ENTRYPOINT ["./manage.sh"]

Jenkinsfile

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
pipeline {
2+
agent {
3+
dockerfile {
4+
filename 'jenkins.dockerfile'
5+
args '-v /data/jenkins-volumes/pip:/home/jenkins/.cache/pip'
6+
}
7+
}
8+
environment {
9+
PYTHONUNBUFFERED = '1'
10+
GEVENT_RESOLVER = 'block'
11+
PIP_INDEX_URL = 'https://pypi.doubanio.com/simple/'
12+
DATABASE_DEFAULT_URL = "mysql+pymysql://[email protected]:3306/huskar_api?charset=utf8mb4"
13+
HUSKAR_API_DB_URL = "mysql+pymysql://[email protected]:3306/huskar_api?charset=utf8mb4"
14+
REDIS_DEFAULT_URL = "redis://127.0.0.1:6379"
15+
HUSKAR_API_REDIS_URL = "redis://127.0.0.1:6379"
16+
17+
HUSKAR_API_DEBUG = 'true'
18+
HUSKAR_API_TESTING = 'true'
19+
HUSKAR_API_SECRET_KEY = 'test-secret-key'
20+
HUSKAR_API_ZK_SERVERS = "127.0.0.1:2181"
21+
}
22+
stages {
23+
stage('Install') {
24+
steps {
25+
sh 'mysqld_safe --user=jenkins --skip-grant-tables &'
26+
sh 'redis-server &'
27+
sh 'zookeeper-server start-foreground &'
28+
29+
sh 'make install-deps'
30+
sh './manage.sh initdb'
31+
}
32+
}
33+
stage('Test') {
34+
steps {
35+
sh './manage.sh lint'
36+
sh './manage.sh testonly tests -xv --junitxml=junit.xml --cov=huskar_api --cov-report term-missing'
37+
sh 'coverage xml'
38+
sh 'coverage html'
39+
sh 'coverage report --show-missing'
40+
sh 'test "$(coverage report | tail -n1 | awk \'{print $6}\')" = "100%"'
41+
}
42+
}
43+
stage('Build Doc') {
44+
steps {
45+
sh 'make -C docs html'
46+
archiveArtifacts artifacts: 'docs/_build/html/**', fingerprint: true
47+
}
48+
when {
49+
anyOf {
50+
branch 'master'
51+
changeset '**/*.rst'
52+
changelog 'Docs:.+'
53+
changeRequest title: 'Docs:.+', comparator: 'REGEXP'
54+
changeRequest branch: 'docs/*', comparator: 'GLOB'
55+
}
56+
}
57+
}
58+
}
59+
post {
60+
success {
61+
junit 'junit.xml'
62+
cobertura coberturaReportFile: 'coverage.xml'
63+
publishHTML(target: [
64+
allowMissing: false,
65+
alwaysLinkToLastBuild: false,
66+
keepAll: true,
67+
reportDir: 'htmlcov',
68+
reportFiles: 'index.html',
69+
reportName: 'Coverage Report'
70+
])
71+
}
72+
}
73+
}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) <2019> <Eleme Inc.>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

Makefile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.PHONY: help install-deps compile-deps prepare-deps git-hooks pow
2+
3+
help:
4+
@echo "Available commands: help install-deps compile-deps"
5+
6+
install-deps: prepare-deps
7+
pip-sync requirements.txt requirements-dev.txt
8+
9+
compile-deps: prepare-deps
10+
pip-compile --no-index --no-emit-trusted-host requirements.in
11+
pip-compile --no-index --no-emit-trusted-host requirements-dev.in
12+
13+
prepare-deps:
14+
@[ -n "$${VIRTUAL_ENV}" ] || (echo >&2 "Please activate virtualenv."; false)
15+
pip install -U pip==19.2.3 setuptools==41.4.0 wheel==0.33.6 pip-tools==4.2.0
16+
17+
git-hooks:
18+
ln -sf `pwd`/tools/git-hooks/* .git/hooks/
19+
20+
pow:
21+
echo "http://$$(docker-compose port wsgi 5000)" > ~/.pow/huskar.test

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: gunicorn -c config/gunicorn_config.py huskar_api.wsgi:app

README.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Huskar API
2+
==========
3+
4+
HTTP API of Huskar: http://example.com/huskar_api/
5+
6+
How to start
7+
------------
8+
9+
$ cp .env.example .env && vim .env
10+
11+
Starting the API server in local environment:
12+
13+
$ . path/to/venv/activate
14+
$ make install-deps
15+
$ honcho start
16+
17+
Starting the API server in [Docker](https://www.docker.com/products/docker):
18+
19+
$ docker-compose run --rm wsgi initdb # initialize database
20+
$ docker-compose run --rm wsgi initadmin # initialize administrator
21+
$ docker-compose up wsgi # start web server
22+
23+
24+
Development FAQ
25+
---------------
26+
27+
Using the ZooKeeper CLI:
28+
29+
$ zkCli -server $(docker-compose port zookeeper 2181)
30+
31+
Using the MySQL CLI:
32+
33+
$ mycli mysql://root@$(docker-compose port mysql 3306)/huskar_api
34+
35+
Updating dependencies:
36+
37+
$ docker-compose run --rm wsgi make compile-deps
38+
$ git add -p requirements*
39+
40+
Running tests:
41+
42+
$ docker-compose run --rm wsgi testall -xv
43+
$ docker-compose run --rm wsgi test test_foo.py -xv
44+
45+
Maintaining database schema:
46+
47+
$ docker-compose run --rm wsgi alembic upgrade head
48+
$ vim huskar_api/models/foobar.py
49+
$ docker-compose run --rm wsgi alembic revision --autogenerate -m 'add an index of foo'
50+
$ vim database/migration/versions/xxxxxxx.py
51+
$ docker-compose run --rm wsgi alembic upgrade head
52+
$ docker-compose run --rm wsgi dumpdb
53+
$ git add database
54+
55+
Updating snapshot of email template in tests:
56+
57+
$ docker-compose run --rm wsgi python run.py tests.test_extras.test_email:gen

config/gunicorn_config.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bind = "0.0.0.0:5000"
2+
worker_class = "gevent"

database/migration/README

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Generic single-database configuration.

0 commit comments

Comments
 (0)