-
Notifications
You must be signed in to change notification settings - Fork 49
make docker image multimodal and don't apply migration by default. #1037
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,84 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| if [ "$1" = 've/bin/gunicorn' ] || [ "$1" = 've/bin/python' ]; then | ||
| echo "Updating static files in /volumes/static-files/." | ||
| rsync -a --delete specifyweb/frontend/static/ /volumes/static-files/frontend-static | ||
| cd /opt/specify7 | ||
| echo "Applying Django migrations." | ||
| set +e | ||
| # The following commands are prone to failing | ||
| # See https://github.com/specify/specify7/issues/789 and https://github.com/specify/docker-compositions/issues/7 | ||
| ve/bin/python manage.py migrate notifications | ||
| ve/bin/python manage.py migrate workbench | ||
| set -e | ||
| fi | ||
| exec "$@" | ||
|
|
||
| # This entry point script implements a multi-mode image as described in | ||
| # https://aws.amazon.com/blogs/opensource/demystifying-entrypoint-cmd-docker/ | ||
| # | ||
| # It supports the following commands: | ||
| # | ||
| # sp7start -- This is the default CMD. When the container is invoked | ||
| # this way it checks if any Django migrations need to be | ||
| # performed. If so it refuses to start and issues instructions to | ||
| # do the migrations. Otherwise it performs a normal Specify 7 start | ||
| # up. | ||
| # | ||
| # sp7migrate -- When the container is invoked with this command it | ||
| # executes any outstanding migrations. | ||
| # | ||
| # sp7migrate-and-start -- This command executes any migrations and | ||
| # then starts Specify 7. It is less safe than doing the migrations | ||
| # independently but is convenient in testing scenarios. | ||
| # | ||
| # sp7worker -- This command starts the container in worker mode and | ||
| # is intended to simplify docker-compose.yml files. | ||
| # | ||
| # Any other command is executed as is. | ||
| # | ||
| # For the sp7start and sp7worker commands, any arguments are passed through to | ||
| # the underlying gunicorn or celery command, respectively. | ||
|
|
||
|
|
||
| set -euf -o pipefail | ||
|
|
||
| sp7start () { | ||
| echo "Updating static files in /volumes/static-files/." | ||
| rsync -a --delete specifyweb/frontend/static/ /volumes/static-files/frontend-static | ||
|
|
||
| echo "Starting Specify 7." | ||
| exec ve/bin/gunicorn -w 3 -b 0.0.0.0:8000 -t 300 specifyweb_wsgi "$@" | ||
| } | ||
|
|
||
| sp7migrate () { | ||
| echo "Applying Django migrations." | ||
| ve/bin/python manage.py migrate notifications | ||
| ve/bin/python manage.py migrate workbench | ||
| } | ||
|
|
||
| case "$1" in | ||
| "sp7start" ) | ||
| shift | ||
|
|
||
| if (ve/bin/python manage.py showmigrations notifications workbench | grep -q '\[ \]'); then | ||
| printf "\n\nSpecify 7 cannot start because Django migrations need to be applied.\n\n" | ||
| printf "Apply the migrations by:\n" | ||
| printf "1. Stopping any process that could be accessing your database \"$DATABASE_NAME\".\n" | ||
| printf "2. Backing up the database \"$DATABASE_NAME\".\n" | ||
| printf "3. Applying the migrations by running \"docker-compose run --rm THIS-CONTAINER sp7migrate\".\n" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like docker-compose run requires SERVICE name, instead of CONTAINER name.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for reference, I received the following exception when trying to run a migration on a Applying Django migrations.
[24/Nov/2021 18:47:27] [WARNING] [specifyweb.specify.load_datamodel:248] missing table or relationship setting dependent field: Deaccession.deaccessionpreparations
Operations to perform:
Apply all migrations: notifications
Running migrations:
Applying notifications.0001_initial...Traceback (most recent call last):
File "/opt/specify7/ve/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/opt/specify7/ve/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 71, in execute
return self.cursor.execute(query, args)
File "/opt/specify7/ve/lib/python3.6/site-packages/MySQLdb/cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "/opt/specify7/ve/lib/python3.6/site-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "/opt/specify7/ve/lib/python3.6/site-packages/MySQLdb/cursors.py", line 247, in execute
res = self._query(query)
File "/opt/specify7/ve/lib/python3.6/site-packages/MySQLdb/cursors.py", line 412, in _query
rowcount = self._do_query(q)
File "/opt/specify7/ve/lib/python3.6/site-packages/MySQLdb/cursors.py", line 375, in _do_query
db.query(q)
File "/opt/specify7/ve/lib/python3.6/site-packages/MySQLdb/connections.py", line 276, in query
_mysql.connection.query(self, query)
_mysql_exceptions.OperationalError: (1005, 'Can\'t create table `specify`.`notifications_message` (errno: 150 "Foreign key constraint is incorrectly formed")') |
||
| else | ||
| sp7start "$@" | ||
| fi | ||
| ;; | ||
|
|
||
| "sp7migrate" ) | ||
| shift | ||
|
|
||
| sp7migrate | ||
| ;; | ||
|
|
||
| "sp7migrate-and-start" ) | ||
| shift | ||
|
|
||
| sp7migrate | ||
| sp7start "$@" | ||
| ;; | ||
|
|
||
| "sp7worker" ) | ||
| shift | ||
|
|
||
| echo "Starting Specify 7 Worker." | ||
| exec ve/bin/celery -A specifyweb worker -l INFO --concurrency=1 "$@" | ||
| ;; | ||
|
|
||
| *) | ||
| exec "$@" | ||
| ;; | ||
| esac | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to clarify that the database container should not be stopped?
Alternatively, this command would start the container if it wasn't running