Closed Bug 1612977 Opened 6 years ago Closed 6 years ago

./initialize_data.sh is not working

Categories

(Tree Management :: Treeherder: Infrastructure, defect, P3)

defect

Tracking

(Not tracked)

RESOLVED WORKSFORME

People

(Reporter: ekyle, Unassigned)

References

Details

Adding this command to docker/entrypoint.sh prevents startup of backend

# Initialize migrations and SETA
./initialize_data.sh
backend     | -----> Waiting for MySQL server to be ready
backend     | -----> Running Django migrations and loading reference data
frontend    | [2/4] Fetching packages...
backend     | Operations to perform:
backend     |   Apply all migrations: auth, contenttypes, model, perf, seta
backend     | Running migrations:
backend     |   Applying contenttypes.0001_initial...Traceback (most recent call last):
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
backend     |     return self.cursor.execute(sql)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 74, in execute
backend     |     return self.cursor.execute(query, args)
backend     |   File "/usr/local/lib/python3.7/site-packages/MySQLdb/cursors.py", line 209, in execute
backend     |     res = self._query(query)
backend     |   File "/usr/local/lib/python3.7/site-packages/MySQLdb/cursors.py", line 315, in _query
backend     |     db.query(q)
backend     |   File "/usr/local/lib/python3.7/site-packages/MySQLdb/connections.py", line 239, in query
backend     |     _mysql.connection.query(self, query)
backend     | MySQLdb._exceptions.OperationalError: (1050, "Table 'django_content_type' already exists")
backend     |
backend     | The above exception was the direct cause of the following exception:
backend     |
backend     | Traceback (most recent call last):
backend     |   File "./manage.py", line 34, in <module>
backend     |     execute_from_command_line(sys.argv)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
backend     |     utility.execute()
backend     |   File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
backend     |     self.fetch_command(subcommand).run_from_argv(self.argv)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 328, in run_from_argv
backend     |     self.execute(*args, **cmd_options)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 369, in execute
backend     |     output = self.handle(*args, **options)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
backend     |     res = handle_func(*args, **kwargs)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 233, in handle
backend     |     fake_initial=fake_initial,
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/migrations/executor.py", line 117, in migrate
backend     |     state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
backend     |     state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
backend     |     state = migration.apply(state, schema_editor)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/migrations/migration.py", line 124, in apply
backend     |     operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/migrations/operations/models.py", line 92, in database_forwards
backend     |     schema_editor.create_model(model)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 324, in create_model
backend     |     self.execute(sql, params or None)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 142, in execute
backend     |     cursor.execute(sql, params)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 100, in execute
backend     |     return super().execute(sql, params)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 68, in execute
backend     |     return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
backend     |     return executor(sql, params, many, context)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 86, in _execute
backend     |     return self.cursor.execute(sql, params)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/utils.py", line 90, in __exit__
backend     |     raise dj_exc_value.with_traceback(traceback) from exc_value
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
backend     |     return self.cursor.execute(sql)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 74, in execute
backend     |     return self.cursor.execute(query, args)
backend     |   File "/usr/local/lib/python3.7/site-packages/MySQLdb/cursors.py", line 209, in execute
backend     |     res = self._query(query)
backend     |   File "/usr/local/lib/python3.7/site-packages/MySQLdb/cursors.py", line 315, in _query
backend     |     db.query(q)
backend     |   File "/usr/local/lib/python3.7/site-packages/MySQLdb/connections.py", line 239, in query
backend     |     _mysql.connection.query(self, query)
backend     | django.db.utils.OperationalError: (1050, "Table 'django_content_type' already exists")
backend exited with code 1

What happens if you just run ./manage.py migrate --noinput twice?

Is this when you run docker-compose run backend bash or docker-compose up?

This happens during docker-compose up --build

C:\Users\kyle\code\treeherder>git checkout upstream/master
Note: switching to 'upstream/master'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at d962fb693 Bug 1612892 - Fix endpoint URL + other cleanups

C:\Users\kyle\code\treeherder>docker-compose up --build
Building backend
Step 1/15 : FROM python:3.7.2
 ---> 2053ca75899e
Step 2/15 : ENV NEW_RELIC_CONFIG_FILE newrelic.ini
 ---> Using cache
 ---> aa16c195b5b0
Step 3/15 : RUN apt-get update && apt-get install -y --no-install-recommends     default-libmysqlclient-dev     gcc     netcat     && rm -rf /var/lib/apt/lists/*
 ---> Using cache
 ---> 104d64da1ca9
Step 4/15 : ENV GECKODRIVER_VERSION='0.24.0'
 ---> Using cache
 ---> 3643d63382d3
Step 5/15 : RUN curl -sSfL "https://github.com/mozilla/geckodriver/releases/download/v${GECKODRIVER_VERSION}/geckodriver-v${GECKODRIVER_VERSION}-linux64.tar.gz"     | tar -zxC "/usr/local/bin"     && curl -sSfL 'https://download.mozilla.org/?product=firefox-beta-latest&lang=en-US&os=linux64'     | tar -jxC "/usr/local/bin"
 ---> Using cache
 ---> 6f783ba859ed
Step 6/15 : RUN apt-get update && apt-get install -y --no-install-recommends     libgtk-3-0     libdbus-glib-1-2     && rm -rf /var/lib/apt/lists/*
 ---> Using cache
 ---> 9f5576f55b13
Step 7/15 : ENV MOZ_HEADLESS=1
 ---> Using cache
 ---> f9f1e338a108
Step 8/15 : ENV PATH="/usr/local/bin/firefox:${PATH}"
 ---> Using cache
 ---> ca554a53d7ce
Step 9/15 : ENV SHELLCHECK_VERSION="0.4.6"
 ---> Using cache
 ---> c37f0def7371
Step 10/15 : RUN curl -sSfL "https://storage.googleapis.com/shellcheck/shellcheck-v${SHELLCHECK_VERSION}.linux.x86_64.tar.xz"     | tar -Jx --strip-components=1 -C /usr/local/bin
 ---> Using cache
 ---> 74bfde5b811b
Step 11/15 : ADD . /app
 ---> Using cache
 ---> 0d162228e3ee
Step 12/15 : WORKDIR /app
 ---> Using cache
 ---> 0f1e07f9eb19
Step 13/15 : RUN pip install --no-cache-dir --disable-pip-version-check --require-hashes -r requirements/common.txt
 ---> Using cache
 ---> 40e03eed23f8
Step 14/15 : RUN pip install --no-cache-dir --disable-pip-version-check --require-hashes -r requirements/dev.txt
 ---> Using cache
 ---> fe2af2e17b14
Step 15/15 : RUN pip install --no-cache-dir --disable-pip-version-check -r requirements/docs.txt
 ---> Using cache
 ---> bae29f654f91
Successfully built bae29f654f91
Successfully tagged treeherder-backend:latest
Starting frontend   ... done
Starting mysql      ... done
Recreating redis    ... done
Recreating rabbitmq ... done
Recreating backend  ... done
Attaching to mysql, frontend, rabbitmq, redis, backend
mysql       | 2020-02-04 21:34:47+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.29-1debian9 started.
mysql       | 2020-02-04 21:34:47+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql       | 2020-02-04 21:34:47+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.29-1debian9 started.
frontend    | yarn install v1.19.1
frontend    | [1/4] Resolving packages...
redis       | 1:C 04 Feb 2020 21:34:48.232 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis       | 1:C 04 Feb 2020 21:34:48.232 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=1, just started
redis       | 1:C 04 Feb 2020 21:34:48.232 # Configuration loaded
redis       | 1:M 04 Feb 2020 21:34:48.236 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis       | 1:M 04 Feb 2020 21:34:48.236 # Server initialized
backend     | -----> Running Django migrations and loading reference data
redis       | 1:M 04 Feb 2020 21:34:48.236 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
frontend    | [2/4] Fetching packages...
frontend    | info fsevents@1.2.11: The platform "linux" is incompatible with this module.
frontend    | info "fsevents@1.2.11" is an optional dependency and failed compatibility check. Excluding it from installation.
frontend    | [3/4] Linking dependencies...
frontend    | warning " > bootstrap@4.3.1" has unmet peer dependency "popper.js@^1.14.7".
frontend    | warning " > react-dates@21.5.1" has unmet peer dependency "@babel/runtime@^7.0.0".
frontend    | warning " > react-dates@21.5.1" has unmet peer dependency "react-with-direction@^1.3.1".
frontend    | warning "react-dates > react-with-styles@4.1.0" has unmet peer dependency "@babel/runtime@^7.0.0".
frontend    | warning "react-dates > react-with-styles-interface-css@6.0.0" has unmet peer dependency "@babel/runtime@^7.0.0".
frontend    | warning "@neutrinojs/jest > eslint-plugin-jest > @typescript-eslint/experimental-utils > @typescript-eslint/typescript-estree > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
frontend    | warning " > eslint-config-airbnb@18.0.1" has unmet peer dependency "eslint-plugin-react-hooks@^1.7.0".
backend     | Operations to perform:
backend     |   Apply all migrations: auth, contenttypes, model, perf, seta
backend     | Running migrations:
backend     |   Applying contenttypes.0001_initial...Traceback (most recent call last):
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
backend     |     return self.cursor.execute(sql)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 74, in execute
backend     |     return self.cursor.execute(query, args)
backend     |   File "/usr/local/lib/python3.7/site-packages/MySQLdb/cursors.py", line 209, in execute
backend     |     res = self._query(query)
backend     |   File "/usr/local/lib/python3.7/site-packages/MySQLdb/cursors.py", line 315, in _query
backend     |     db.query(q)
backend     |   File "/usr/local/lib/python3.7/site-packages/MySQLdb/connections.py", line 239, in query
backend     |     _mysql.connection.query(self, query)
backend     | MySQLdb._exceptions.OperationalError: (1050, "Table 'django_content_type' already exists")
backend     |
backend     | The above exception was the direct cause of the following exception:
backend     |
backend     | Traceback (most recent call last):
backend     |   File "./manage.py", line 34, in <module>
backend     |     execute_from_command_line(sys.argv)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
backend     |     utility.execute()
backend     |   File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
backend     |     self.fetch_command(subcommand).run_from_argv(self.argv)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 328, in run_from_argv
backend     |     self.execute(*args, **cmd_options)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 369, in execute
backend     |     output = self.handle(*args, **options)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
backend     |     res = handle_func(*args, **kwargs)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 233, in handle
backend     |     fake_initial=fake_initial,
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/migrations/executor.py", line 117, in migrate
backend     |     state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
backend     |     state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
backend     |     state = migration.apply(state, schema_editor)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/migrations/migration.py", line 124, in apply
backend     |     operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/migrations/operations/models.py", line 92, in database_forwards
backend     |     schema_editor.create_model(model)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 324, in create_model
backend     |     self.execute(sql, params or None)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 142, in execute
backend     |     cursor.execute(sql, params)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 100, in execute
backend     |     return super().execute(sql, params)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 68, in execute
backend     |     return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
backend     |     return executor(sql, params, many, context)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 86, in _execute
backend     |     return self.cursor.execute(sql, params)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/utils.py", line 90, in __exit__
backend     |     raise dj_exc_value.with_traceback(traceback) from exc_value
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
backend     |     return self.cursor.execute(sql)
backend     |   File "/usr/local/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 74, in execute
backend     |     return self.cursor.execute(query, args)
backend     |   File "/usr/local/lib/python3.7/site-packages/MySQLdb/cursors.py", line 209, in execute
backend     |     res = self._query(query)
backend     |   File "/usr/local/lib/python3.7/site-packages/MySQLdb/cursors.py", line 315, in _query
backend     |     db.query(q)
backend     |   File "/usr/local/lib/python3.7/site-packages/MySQLdb/connections.py", line 239, in query
backend     |     _mysql.connection.query(self, query)
backend     | django.db.utils.OperationalError: (1050, "Table 'django_content_type' already exists")
backend exited with code 1

Could you try docker volume rm treeherder_mysql_data?
docker volume ls should list it.

It seems that the tables had been modified outside of the normal workflows.
Resetting it got it fixed.

Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.