Skip to content

Commit 3a1b758

Browse files
committed
add docker-compose.yml
1 parent fde35f9 commit 3a1b758

File tree

88 files changed

+380
-5
lines changed

Some content is hidden

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

88 files changed

+380
-5
lines changed

Dockerfile

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,19 @@ RUN ln -s -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
1010
mkdir ~/.pip && \
1111
echo -e "[global]\nindex-url=http://pypi.douban.com/simple/\ntrusted-host=pypi.douban.com">~/.pip/pip.conf && \
1212
yum clean all
13-
ADD . .
13+
14+
RUN yum install -y supervisor
15+
16+
RUN mkdir -p /deploy
17+
#VOLUME /deploy
18+
WORKDIR /deploy
19+
COPY requirements.txt /deploy/requirements.txt
1420
RUN pip3.6 install -r requirements.txt --timeout=120
15-
WORKDIR /opt/weeklyreport
1621

22+
# Setup supervisord
23+
RUN mkdir -p /var/log/supervisor
24+
#COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
25+
#COPY gunicorn.conf /etc/supervisor/conf.d/gunicorn.conf
1726

1827
# Start wp-server container
1928

@@ -24,4 +33,25 @@ WORKDIR /opt/weeklyreport
2433
# -v /etc/localtime:/etc/localtime:ro \
2534
# -v $PWD:/opt/weeklyreport \
2635
# weeklyreport:0.2 \
27-
# gunicorn wsgi:app --bind 0.0.0.0:80 -w 2 --log-file logs/awsgi.log --log-level=DEBUG
36+
# gunicorn wsgi:app --bind 0.0.0.0:5000 -w 2 --log-file logs/awsgi.log --log-level=DEBUG
37+
38+
# run sh. Start processes in docker-compose.yml
39+
40+
41+
#deploy
42+
COPY deploy /deploy
43+
#wait pg connected
44+
#RUN python3.6 checkdb.py
45+
# db init migrate
46+
#RUN python3.6 wsgi.py deploy
47+
48+
49+
RUN mkdir -p /scripts
50+
COPY checkdb.py /scripts/checkdb.py
51+
COPY entrypoint.sh /scripts/entrypoint.sh
52+
#RUN chown -R /scripts
53+
RUN chmod +x /scripts/entrypoint.sh
54+
55+
CMD ["/scripts/entrypoint.sh"]
56+
#CMD ["/usr/bin/supervisord"]
57+
#CMD ["/bin/bash"]

checkdb.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import sys
2+
import time
3+
import psycopg2
4+
import logging
5+
6+
7+
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
8+
logging.info("Checking if table 'django_migrations' exists.")
9+
logging.info("If you want to skip this, just set the environment var")
10+
logging.info("TAIGA_SKIP_DB_CHECK=True on docker-compose.yml on <backend> service.")
11+
CONNECTION_STRING = "dbname='{}' user='{}' host='{}' password='{}'".format(
12+
'wr_prd',
13+
'postgres',
14+
'db',
15+
'postgres'
16+
)
17+
LIMIT_RETRIES = 5
18+
SLEEP_INTERVAL = 5
19+
20+
21+
def postgres_connection(connection_string, retry_counter=1):
22+
try:
23+
connection = psycopg2.connect(connection_string)
24+
except psycopg2.OperationalError as e:
25+
if retry_counter > LIMIT_RETRIES:
26+
logging.error("CAN'T CONNECT TO POSTGRES")
27+
logging.error("Check your connection settings.")
28+
logging.error("Or increase (in docker-compose.yml):")
29+
logging.error(
30+
"TAIGA_DB_CHECK_SLEEP_INTERVAL / TAIGA_DB_CHECK_LIMIT_RETRIES."
31+
)
32+
logging.error("Exception messsage: {}".format(e))
33+
sys.exit(1)
34+
else:
35+
logging.warning("Can't connect to Postgres. Will try again...")
36+
time.sleep(SLEEP_INTERVAL)
37+
retry_counter += 1
38+
return postgres_connection(connection_string, retry_counter)
39+
return connection
40+
41+
42+
cursor = postgres_connection(CONNECTION_STRING).cursor()
43+
cursor.execute(
44+
"select exists(select * from information_schema.tables where table_name=%s)",
45+
('users',)
46+
)
47+
if not cursor.fetchone()[0]:
48+
logging.info("So, it seems like it's the first time you run the <backend>")
49+
logging.info("service for taiga. Will try to:")
50+
logging.info("1) migrate DB; 2) load initial data; 3) compilemessages")
51+
print('missing_flask_users')
1.32 KB
Binary file not shown.
File renamed without changes.

deploy/app/__init__.pyc

2.02 KB
Binary file not shown.
1.63 KB
Binary file not shown.
898 Bytes
Binary file not shown.
582 Bytes
Binary file not shown.
6.78 KB
Binary file not shown.
1.68 KB
Binary file not shown.
File renamed without changes.
218 Bytes
Binary file not shown.
4.04 KB
Binary file not shown.
4.55 KB
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
235 Bytes
Binary file not shown.
822 Bytes
Binary file not shown.
4.68 KB
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

config.py renamed to deploy/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@
3636
"<p>&nbsp;<strong>下周计划:</strong></p><ol><li></li></ol>"
3737

3838

39-
# SQLALCHEMY_DATABASE_URI = 'postgresql://postgres:postgres@localhost/wr_prd'
40-
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(base_dir, 'wr_prd.sqlite')
39+
SQLALCHEMY_DATABASE_URI = 'postgresql://postgres:postgres@db/wr_prd'
40+
# SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(base_dir, 'wr_prd.sqlite')
File renamed without changes.

deploy/migrations/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Generic single-database configuration.
2.15 KB
Binary file not shown.

deploy/migrations/alembic.ini

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# A generic, single database configuration.
2+
3+
[alembic]
4+
# template used to generate migration files
5+
# file_template = %%(rev)s_%%(slug)s
6+
7+
# set to 'true' to run the environment during
8+
# the 'revision' command, regardless of autogenerate
9+
# revision_environment = false
10+
11+
12+
# Logging configuration
13+
[loggers]
14+
keys = root,sqlalchemy,alembic
15+
16+
[handlers]
17+
keys = console
18+
19+
[formatters]
20+
keys = generic
21+
22+
[logger_root]
23+
level = WARN
24+
handlers = console
25+
qualname =
26+
27+
[logger_sqlalchemy]
28+
level = WARN
29+
handlers =
30+
qualname = sqlalchemy.engine
31+
32+
[logger_alembic]
33+
level = INFO
34+
handlers =
35+
qualname = alembic
36+
37+
[handler_console]
38+
class = StreamHandler
39+
args = (sys.stderr,)
40+
level = NOTSET
41+
formatter = generic
42+
43+
[formatter_generic]
44+
format = %(levelname)-5.5s [%(name)s] %(message)s
45+
datefmt = %H:%M:%S

deploy/migrations/env.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
from __future__ import with_statement
2+
from alembic import context
3+
from sqlalchemy import engine_from_config, pool
4+
from logging.config import fileConfig
5+
import logging
6+
7+
# this is the Alembic Config object, which provides
8+
# access to the values within the .ini file in use.
9+
config = context.config
10+
11+
# Interpret the config file for Python logging.
12+
# This line sets up loggers basically.
13+
fileConfig(config.config_file_name)
14+
logger = logging.getLogger('alembic.env')
15+
16+
# add your model's MetaData object here
17+
# for 'autogenerate' support
18+
# from myapp import mymodel
19+
# target_metadata = mymodel.Base.metadata
20+
from flask import current_app
21+
config.set_main_option('sqlalchemy.url',
22+
current_app.config.get('SQLALCHEMY_DATABASE_URI'))
23+
target_metadata = current_app.extensions['migrate'].db.metadata
24+
25+
# other values from the config, defined by the needs of env.py,
26+
# can be acquired:
27+
# my_important_option = config.get_main_option("my_important_option")
28+
# ... etc.
29+
30+
31+
def run_migrations_offline():
32+
"""Run migrations in 'offline' mode.
33+
34+
This configures the context with just a URL
35+
and not an Engine, though an Engine is acceptable
36+
here as well. By skipping the Engine creation
37+
we don't even need a DBAPI to be available.
38+
39+
Calls to context.execute() here emit the given string to the
40+
script output.
41+
42+
"""
43+
url = config.get_main_option("sqlalchemy.url")
44+
context.configure(url=url)
45+
46+
with context.begin_transaction():
47+
context.run_migrations()
48+
49+
50+
def run_migrations_online():
51+
"""Run migrations in 'online' mode.
52+
53+
In this scenario we need to create an Engine
54+
and associate a connection with the context.
55+
56+
"""
57+
58+
# this callback is used to prevent an auto-migration from being generated
59+
# when there are no changes to the schema
60+
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
61+
def process_revision_directives(context, revision, directives):
62+
if getattr(config.cmd_opts, 'autogenerate', False):
63+
script = directives[0]
64+
if script.upgrade_ops.is_empty():
65+
directives[:] = []
66+
logger.info('No changes in schema detected.')
67+
68+
engine = engine_from_config(config.get_section(config.config_ini_section),
69+
prefix='sqlalchemy.',
70+
poolclass=pool.NullPool)
71+
72+
connection = engine.connect()
73+
context.configure(connection=connection,
74+
target_metadata=target_metadata,
75+
process_revision_directives=process_revision_directives,
76+
**current_app.extensions['migrate'].configure_args)
77+
78+
try:
79+
with context.begin_transaction():
80+
context.run_migrations()
81+
finally:
82+
connection.close()
83+
84+
if context.is_offline_mode():
85+
run_migrations_offline()
86+
else:
87+
run_migrations_online()

deploy/migrations/script.py.mako

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""${message}
2+
3+
Revision ID: ${up_revision}
4+
Revises: ${down_revision | comma,n}
5+
Create Date: ${create_date}
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
${imports if imports else ""}
11+
12+
# revision identifiers, used by Alembic.
13+
revision = ${repr(up_revision)}
14+
down_revision = ${repr(down_revision)}
15+
branch_labels = ${repr(branch_labels)}
16+
depends_on = ${repr(depends_on)}
17+
18+
19+
def upgrade():
20+
${upgrades if upgrades else "pass"}
21+
22+
23+
def downgrade():
24+
${downgrades if downgrades else "pass"}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""empty message
2+
3+
Revision ID: 4e32e2d01c28
4+
Revises:
5+
Create Date: 2017-12-22 12:06:04.886300
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '4e32e2d01c28'
14+
down_revision = None
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.create_table('departments',
22+
sa.Column('id', sa.Integer(), nullable=False),
23+
sa.Column('name', sa.String(length=64), nullable=True),
24+
sa.PrimaryKeyConstraint('id'),
25+
sa.UniqueConstraint('name')
26+
)
27+
op.create_table('roles',
28+
sa.Column('id', sa.Integer(), nullable=False),
29+
sa.Column('name', sa.String(length=64), nullable=True),
30+
sa.Column('permissions', sa.Integer(), nullable=True),
31+
sa.PrimaryKeyConstraint('id'),
32+
sa.UniqueConstraint('name')
33+
)
34+
op.create_table('users',
35+
sa.Column('id', sa.Integer(), nullable=False),
36+
sa.Column('email', sa.String(length=64), nullable=True),
37+
sa.Column('username', sa.String(length=64), nullable=True),
38+
sa.Column('password_hash', sa.String(length=128), nullable=True),
39+
sa.Column('is_ignored', sa.Boolean(), nullable=True),
40+
sa.Column('role_id', sa.Integer(), nullable=True),
41+
sa.Column('department_id', sa.Integer(), nullable=True),
42+
sa.Column('is_super_admin', sa.Boolean(), nullable=True),
43+
sa.ForeignKeyConstraint(['department_id'], ['departments.id'], ),
44+
sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ),
45+
sa.PrimaryKeyConstraint('id')
46+
)
47+
op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
48+
op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
49+
op.create_table('reports',
50+
sa.Column('id', sa.Integer(), nullable=False),
51+
sa.Column('created_at', sa.DateTime(), nullable=True),
52+
sa.Column('author_id', sa.Integer(), nullable=True),
53+
sa.Column('content', sa.Text(), nullable=True),
54+
sa.Column('week_count', sa.Integer(), nullable=True),
55+
sa.Column('year', sa.Integer(), nullable=True),
56+
sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
57+
sa.PrimaryKeyConstraint('id')
58+
)
59+
op.create_index(op.f('ix_reports_created_at'), 'reports', ['created_at'], unique=False)
60+
# ### end Alembic commands ###
61+
62+
63+
def downgrade():
64+
# ### commands auto generated by Alembic - please adjust! ###
65+
op.drop_index(op.f('ix_reports_created_at'), table_name='reports')
66+
op.drop_table('reports')
67+
op.drop_index(op.f('ix_users_username'), table_name='users')
68+
op.drop_index(op.f('ix_users_email'), table_name='users')
69+
op.drop_table('users')
70+
op.drop_table('roles')
71+
op.drop_table('departments')
72+
# ### end Alembic commands ###
Binary file not shown.

wsgi.py renamed to deploy/wsgi.py

File renamed without changes.

docker-compose.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
version: '3.3'
2+
services:
3+
4+
db:
5+
image: postgres
6+
environment:
7+
- POSTGRES_DB=wr_prd
8+
- POSTGRES_USER=postgres
9+
- POSTGRES_PASSWORD=postgres
10+
volumes:
11+
- ./pg_data:/var/lib/postgresql/data
12+
13+
adminer:
14+
image: adminer
15+
restart: always
16+
ports:
17+
- 8080:8080
18+
19+
api:
20+
build: .
21+
#restart: always
22+
stdin_open: true
23+
tty: true
24+
volumes:
25+
- ./deploy:/deploy
26+
- /etc/localtime:/etc/localtime:ro
27+
# - ./gunicorn.conf:/etc/supervisor/conf.d/gunicorn.conf
28+
# - ./supervisord.conf:/etc/supervisor/conf.d/supervisord.conf
29+
depends_on:
30+
- db
31+
ports:
32+
- 8000:5000
33+
34+
#command: '/bin/bash'
35+
#command: ['python3.6', ' wsgi.py', 'deploy']
36+
#command: '/usr/bin/supervisord'
37+
#command: ['gunicorn','--workers=3', 'wsgi:app', '-b 0.0.0.0:5000']

0 commit comments

Comments
 (0)