/docker/jupyterhub/provision.sh

https://github.com/sql-machine-learning/sqlflow · Shell · 58 lines · 29 code · 7 blank · 22 comment · 3 complexity · 7bc25e4c6882e3e4ddfe4054c1f189a6 MD5 · raw file

  1. #!/bin/sh
  2. # Copyright 2020 The SQLFlow Authors. All rights reserved.
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # This script is to do some Playground initialization, like change logo,
  15. # Add homepage content, etc.
  16. # Change logo to SQLFLow
  17. sed -i -e \
  18. 's@{{base_url}}logo@https://avatars0.githubusercontent.com/u/48231449?s=200\&v=4@g' \
  19. /usr/local/share/jupyterhub/templates/page.html
  20. # Add welcome words in homepage
  21. # shellcheck disable=SC1004
  22. sed -i -e 's@{% block main %}@& \n\
  23. <div style="width:100%; text-align:center; margin:15vh 0 -15vh 0;"> \n\
  24. <span style="font-size: 2em; color: #1BA2FF">SQLFlow</span> \n\
  25. <div style="font-size: 1.2em; color: #454545">Extends SQL to support AI. Extract knowledge from Data.</div> \n\
  26. <br/> \n\
  27. <div> \n\
  28. <a href="https://sql-machine-learning.github.io/sqlflow/">GitHub</a> \n\
  29. <span>\&emsp;|\&emsp;</span> \n\
  30. <a href="https://github.com/sql-machine-learning/sqlflow/wiki/Contact-us">Contact Us</a> \n\
  31. </div> \n\
  32. </div>@g' /usr/local/share/jupyterhub/templates/login.html
  33. # Add GitHub OAuth retry, we encounter connection failures sometimes, so add retry.
  34. cat >/tmp/retry_code<<EOM
  35. # retry for 3 times
  36. retry = 3
  37. for i in range(retry):
  38. try:
  39. resp = await http_client.fetch(req)
  40. break
  41. except BaseException as e:
  42. if i == retry - 1:
  43. # (TODO:lhw) we may use local cookie if all retries failed
  44. raise e
  45. self.log.info('Connection fail, sleep 2sec and retry %s', str(e))
  46. import time
  47. time.sleep(2)
  48. EOM
  49. # Patch GitHub OAuth, add retry
  50. sed -i -e'160r /tmp/retry_code' -e'160d' \
  51. /usr/local/lib/python3.8/dist-packages/oauthenticator/github.py