Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to Kobocat as Django app inside KPI #241

Merged
merged 29 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
82002a1
Remove support for kobocat, secondary back-end and external redis con…
noliveleger Apr 4, 2024
005e50c
Add celery workers inside frontend.override template
noliveleger Apr 5, 2024
92e49a1
Restore KPI_PREFIX env var
noliveleger Apr 5, 2024
a36b39e
Fix tests
noliveleger Apr 5, 2024
5a8cd10
Reformatting
noliveleger Apr 5, 2024
10926da
Remove documentation for not supported features, update README
noliveleger Apr 5, 2024
50b3658
Remove Enketo template
noliveleger Apr 5, 2024
efdbccb
Remove KC build command
noliveleger Apr 5, 2024
fab6c87
Allow service account between both domains
noliveleger Apr 5, 2024
a905b0c
bugfixes for setup
noliveleger Apr 8, 2024
8685ba5
Remove options to build KPI or KoboCAT
noliveleger May 29, 2024
c5732ba
Update README
noliveleger May 29, 2024
9401f2e
Pass database names to kobo-docker
noliveleger May 30, 2024
e9f66e3
Fix: network selection changing interface name to lowercase
nischalstha9 Jun 12, 2024
20cdabe
Use release 2.024.17b of kobo-docker
noliveleger Jun 17, 2024
2827412
Use release 2.024.17c of kobo-docker
noliveleger Jun 19, 2024
174d6f4
Match NGINX (certbot) version in template
noliveleger Jun 21, 2024
58bebd9
Merge branch 'beta' into kobocat-as-django-app
noliveleger Jun 21, 2024
c586738
Merge pull request #242 from nischalstha9/fix/nw-interface-selection-…
noliveleger Jun 27, 2024
4d1441e
Use release 2.024.19 of kobo-docker
noliveleger Jul 8, 2024
87fd03a
Use release 2.024.19a of kobo-docker
noliveleger Jul 16, 2024
4f74d78
Use release 2.024.19b of kobo-docker
noliveleger Jul 22, 2024
b11cb76
Use release 2.024.19c of kobo-docker
noliveleger Jul 30, 2024
0b003ac
fix KoboToolbox name case and wording of one message
magicznyleszek Jul 31, 2024
ac3881f
Merge pull request #243 from kobotoolbox/update-text
noliveleger Jul 31, 2024
b083783
Use release 2.024.19d of kobo-docker
noliveleger Aug 12, 2024
d69003b
Use release 2.024.19e of kobo-docker
noliveleger Aug 21, 2024
27a2944
Update version
noliveleger Sep 10, 2024
cfd65ab
Merge branch 'kobocat-as-django-app' of github.com:kobotoolbox/kobo-i…
noliveleger Sep 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 32 additions & 72 deletions helpers/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def help():
' -l, --logs',
' Display docker logs',
' -b, --build',
' Build kpi and kobocat (only on dev/staging mode)',
' -bkf, --build-kpi',
' Build kpi (only on dev/staging mode)',
' -bkc, --build-kobocat',
' Build kobocat (only on dev/staging mode)',
' Build django (kpi) container (only on dev/staging mode)',
' -s, --setup',
' Prompt questions to (re)write configuration files',
' -S, --stop',
Expand All @@ -54,52 +50,27 @@ def help():
print('\n'.join(output))

@classmethod
def build(cls, image=None):
def build(cls):
"""
Builds kpi/kobocat images with `--no-caches` option
Pulls latest `kobotoolbox/koboform_base` as well

:param image: str
Builds kpi image with `--no-caches` option
"""
config = Config()
dict_ = config.get_dict()

if config.dev_mode or config.staging_mode:

def build_image(image_):
frontend_command = run_docker_compose(dict_, [
'-f', 'docker-compose.frontend.yml',
'-f', 'docker-compose.frontend.override.yml',
'-p', config.get_prefix('frontend'),
'build', '--force-rm', '--no-cache',
image_
])

CLI.run_command(frontend_command, dict_['kobodocker_path'])

if image is None or image == 'kf':
prefix = config.get_prefix('frontend')
timestamp = int(time.time())
dict_['kpi_dev_build_id'] = f'{prefix}{timestamp}'
config.write_config()
Template.render(config)
build_image('kpi')

if image is None or image == 'kc':
pull_base_command = [
'docker',
'pull',
'kobotoolbox/koboform_base',
]

CLI.run_command(pull_base_command, dict_['kobodocker_path'])

prefix = config.get_prefix('frontend')
timestamp = int(time.time())
dict_['kc_dev_build_id'] = f'{prefix}{timestamp}'
config.write_config()
Template.render(config)
build_image('kobocat')
prefix = config.get_prefix('frontend')
timestamp = int(time.time())
dict_['kpi_dev_build_id'] = f'{prefix}{timestamp}'
config.write_config()
Template.render(config)
frontend_command = run_docker_compose(dict_, [
'-f', 'docker-compose.frontend.yml',
'-f', 'docker-compose.frontend.override.yml',
'-p', config.get_prefix('frontend'),
'build', '--force-rm', '--no-cache', 'kpi'
])
CLI.run_command(frontend_command, dict_['kobodocker_path'])

@classmethod
def compose_frontend(cls, args):
Expand All @@ -119,10 +90,9 @@ def compose_frontend(cls, args):
def compose_backend(cls, args):
config = Config()
dict_ = config.get_dict()
backend_role = dict_['backend_server_role']
command = run_docker_compose(dict_, [
'-f', f'docker-compose.backend.{backend_role}.yml',
'-f', f'docker-compose.backend.{backend_role}.override.yml',
'-f', f'docker-compose.backend.yml',
'-f', f'docker-compose.backend.override.yml',
'-p', config.get_prefix('backend')
])
cls.__validate_custom_yml(config, command)
Expand Down Expand Up @@ -163,8 +133,8 @@ def info(cls, timeout=600):
elif int(time.time()) - start >= timeout:
if timeout > 0:
CLI.colored_print(
'\n`KoBoToolbox` has not started yet. '
'This is can be normal with low CPU/RAM computers.\n',
'\n`KoboToolbox` has not started yet. '
'This can happen with low CPU/RAM computers.\n',
CLI.COLOR_INFO)
question = f'Wait for another {timeout} seconds?'
response = CLI.yes_no_question(question)
Expand Down Expand Up @@ -209,7 +179,7 @@ def info(cls, timeout=600):

else:
message = (
'KoBoToolbox could not start!\n'
'KoboToolbox could not start!\n'
'Please try `python3 run.py --logs` to see the logs.'
)
CLI.framed_print(message, color=CLI.COLOR_ERROR)
Expand All @@ -221,11 +191,10 @@ def logs(cls):
config = Config()
dict_ = config.get_dict()

if config.primary_backend or config.secondary_backend:
backend_role = dict_['backend_server_role']
if config.backend:
backend_command = run_docker_compose(dict_, [
'-f', f'docker-compose.backend.{backend_role}.yml',
'-f', f'docker-compose.backend.{backend_role}.override.yml',
'-f', f'docker-compose.backend.yml',
'-f', f'docker-compose.backend.override.yml',
'-p', config.get_prefix('backend'),
'logs', '-f'
])
Expand Down Expand Up @@ -310,13 +279,10 @@ def start(cls, frontend_only=False, force_setup=False):
else:
nginx_port = int(dict_['exposed_nginx_docker_port'])

if frontend_only or config.frontend or \
not config.multi_servers:
if frontend_only or config.frontend or not config.multi_servers:
ports.append(nginx_port)

if (not frontend_only or config.primary_backend or
config.secondary_backend) and \
config.expose_backend_ports:
if not frontend_only and config.expose_backend_ports and config.backend:
ports.append(dict_['postgresql_port'])
ports.append(dict_['mongo_port'])
ports.append(dict_['redis_main_port'])
Expand All @@ -332,11 +298,9 @@ def start(cls, frontend_only=False, force_setup=False):
# Start the back-end containers
if not frontend_only and config.backend:

backend_role = dict_['backend_server_role']

backend_command = run_docker_compose(dict_, [
'-f', f'docker-compose.backend.{backend_role}.yml',
'-f', f'docker-compose.backend.{backend_role}.override.yml',
'-f', f'docker-compose.backend.yml',
'-f', f'docker-compose.backend.override.yml',
'-p', config.get_prefix('backend'),
'up', '-d'
])
Expand Down Expand Up @@ -392,9 +356,8 @@ def start(cls, frontend_only=False, force_setup=False):
'It can take a few minutes.', CLI.COLOR_INFO)
cls.info()
else:
backend_server_role = dict_['backend_server_role']
CLI.colored_print(
(f'{backend_server_role} backend server is starting up '
(f'Back-end server is starting up '
'and should be up & running soon!\nPlease look at docker '
'logs for further information: '
'`python3 run.py -cb logs -f`'),
Expand Down Expand Up @@ -443,7 +406,6 @@ def stop_containers(cls, group: str, down: bool = False):

config = Config()
dict_ = config.get_dict()
backend_role = dict_['backend_server_role']

if group not in ['frontend', 'backend', 'certbot', 'maintenance']:
raise Exception('Unknown group')
Expand All @@ -459,8 +421,8 @@ def stop_containers(cls, group: str, down: bool = False):
},
'backend': {
'options': [
'-f', f'docker-compose.backend.{backend_role}.yml',
'-f', f'docker-compose.backend.{backend_role}.override.yml',
'-f', f'docker-compose.backend.yml',
'-f', f'docker-compose.backend.override.yml',
'-p', config.get_prefix('backend'),
],
'custom_yml': True,
Expand Down Expand Up @@ -570,10 +532,8 @@ def __validate_custom_yml(config, command):
command.insert(start_index + 1, 'docker-compose.frontend.custom.yml')

if not frontend_command and dict_['use_backend_custom_yml']:
backend_server_role = dict_['backend_server_role']
custom_file = '{}/docker-compose.backend.{}.custom.yml'.format(
custom_file = '{}/docker-compose.backend.custom.yml'.format(
dict_['kobodocker_path'],
backend_server_role
)

does_custom_file_exist = os.path.exists(custom_file)
Expand All @@ -590,5 +550,5 @@ def __validate_custom_yml(config, command):
command.insert(start_index, '-f')
command.insert(
start_index + 1,
'docker-compose.backend.{}.custom.yml'.format(backend_server_role),
'docker-compose.backend.custom.yml',
)
Loading
Loading