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

New monorepo deploys #366

Merged
merged 17 commits into from
Dec 16, 2019
Merged

New monorepo deploys #366

merged 17 commits into from
Dec 16, 2019

Conversation

josegonzalez
Copy link
Contributor

@josegonzalez josegonzalez commented Dec 13, 2019

Issue: plotly/streambed#13854

App pull request

  • I am improving the deploy process

About

This pull request re-implements the deployment process in order to treat each app within the apps directory as a standalone application. In the future, developers will develop dash apps as if they were in their own, standalone repositories, and the deployment process would take care of injecting anything custom into place.

This allows us to remove a ton of path hacks within each dash app, which simplifies copy paste. As a byproduct, we are no longer shipping the entire repository for each app, which minimizes the overall image size as well as allows us to take advantage of the deploy build cache.

One thing this removes is the ability to push from local in a straightforward manner. You'll need to use the ./deploy script with the proper environment variables - it will complain when they aren't set! - in order to continue deploying as normal. Hopefully this pushes folks to use CI in the future instead of deploying from local though :)

This has already been tested on dash-playground, where the overall disk utilization went down to 120GB (its a bit higher now due to my attempts at installing the dashr apps) from ~900GB (I also did some manual cleanup of old images/containers but thats besides the point).

Workflow

N/A

The pre-review review

I have addressed all of the following questions:

  • Does everything in my code serve some purpose? (I have removed
    any dead and/or irrelevant code.)
  • Does everything in my code have a clear purpose? (My code is
    readable and, where it isn't, it has been commented appropriately.)]
  • Am I reinventing the wheel? (I have used appropriate packages to
    lessen the volume of code that needs to be maintained.)

Synthetic Deploy Demo

An app deploy now takes ~2 minutes, an entire CI run should be ~5min (about 10-15 seconds to check if a given app needs to be updated).

CI runs can be done in parallel and as long as they don't hit a specific app, we can more or less safely merge a ton of PRs at the same time :)

jose@plotaku:~/src/plotly/dash-sample-apps git:new-deploys $ export APP=dash-brain-viewer; export CIRCLE_SHA1="$(git log --pretty=

====> Deploying dash-brain-viewer
      dashr: false
      dash python version: dash==1.0.2
      exists: true
      remote-sha: 55af4c5
====> Ensuring code is up to date
      Copying updated app source
      Python app detected, injecting common python-specific files
====> Deploying
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 340 bytes | 340.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
-----> DDS disk space information
Filesystem      Size  Used Avail Use% Mounted on
overlay         993G  123G  870G  13% /
/dev/sda1       993G  123G  870G  13% /data
-----> DASH_APP_NAME => dash-brain-viewer
-----> DASH_DOMAIN_BASE => dash-playground.plotly.host
-----> DASH_PATH_ROUTING => 1
-----> DASH_STREAMBED_DIRECT_IP => 172.17.0.1
-----> DASH_LOGOUT_URL => /Manager/api/logout
-----> SCRIPT_NAME => /dash-brain-viewer
-----> Cleaning up...
-----> Building dash-brain-viewer from herokuish...
-----> Adding BUILD_ENV to build environment...
-----> Python app detected
       !     Python has released a security update! Please consider upgrading to python-3.6.8
       Learn More: https://dash.plot.ly/dash-deployment-server/application-structure
-----> Installing requirements with pip

-----> Discovering process types
       Procfile declares types -> web
-----> Releasing dash-brain-viewer (dokku/dash-brain-viewer:latest)...
-----> Deploying dash-brain-viewer (dokku/dash-brain-viewer:latest)...
 !     Predeploy command declared: 'python predeploy.py'
-----> App Procfile file found (/home/dokku/dash-brain-viewer/DOKKU_PROCFILE)
       DOKKU_SCALE declares scale -> web=1
-----> Attempting pre-flight checks
       For more efficient zero downtime deployments, create a file CHECKS.
       See http://dokku.viewdocs.io/dokku/deployment/zero-downtime-deploys/ for examples
       CHECKS file not found in container: Running simple container check...
-----> Waiting for 10 seconds ...
-----> Default container check successful!
-----> Running post-deploy
-----> VHOST support disabled. Skipping domains setup
-----> Overriding default nginx.conf with detected nginx.conf.sigil
-----> Creating http nginx.conf
-----> Running nginx-pre-reload
       Reloading nginx
-----> Renaming containers
       Found previous container(s) (e876dbd1e050) named dash-brain-viewer.web.1
       Renaming container (e876dbd1e050) dash-brain-viewer.web.1 to dash-brain-viewer.web.1.1576255999
       Renaming container (098c90e596d2) elegant_montalcini to dash-brain-viewer.web.1
-----> Extracting app dependencies
-----> Updating deploy timestamp
-----> Shutting down old containers in 60 seconds
       e876dbd1e050acf0c68b364fd3c70a2d1d4ed2ed3263a5351dd8abf2defb8af6
=====> Application deployed:
       https://dash-playground.plotly.host/dash-brain-viewer/

To https://dash-playground.plotly.host/GIT/dash-brain-viewer
   55af4c5..1a8ed49  master -> master
jose@plotaku:~/src/plotly/dash-sample-apps git:new-deploys $ export APP=dash-brain-viewer; export CIRCLE_SHA1="$(git log --pretty=format:"%H" "apps/$APP/" | head -n1)"; CREATE_APP=true  time ./deploy $APP
====> Deploying dash-brain-viewer
      dashr: false
      dash python version: dash==1.0.2
      exists: true
      remote-sha: 1a8ed49
====> Ensuring code is up to date
      Copying updated app source
      Python app detected, injecting common python-specific files
====> 🤜 App not updated, skipping deploy
      Check app out at https://dash-playground.plotly.host/dash-brain-viewer/
       13.19 real         2.02 user         0.60 sys
jose@plotaku:~/src/plotly/dash-sample-apps git:new-deploys $

Todo

  • OSS dds-client (the repo is private atm)
  • Modify circleci to download the compiled dds-client
  • Chat with @rpkyle to figure out what is breaking dashr apps and maybe re-enable once they are fixed.
    • Its a dependency issue, we'll fix it post-merge
  • Re-enable gallery deploys (atm we only auto-deploy to playground) by changing the environment variables in the circleci config back
  • Figure out how this should land into each app-specific branch...
    • Can we just delete these app branches? Deploys would be super quick now, no need for the extra process around this anymore...

@josegonzalez josegonzalez changed the title New deploys New monorepo deploys Dec 13, 2019
This new script handles deployment of both Python and R Dash apps within a monorepo. At the moment, it will skip any apps that require redis, and also detects when the old-style monorepo was deployed in order to override the repository with the newer, slimmer methodology.

This script is meant to be run from CI, and should be avoided if possible locally, though will still work, assuming the dds-client is available.
This made it more complex for others to reference the code - they'd need to remove the paths themselves - and also complicated our deployment process.

With the new deploy process, we treat each app directory as if it was a single entity, using a temporary git repository if necessary to initialize the app, and update the app with history as appropriate.
These are useful for dashr apps where the default buildpack is not bundled with DDS at this time.
None of these work on playground at the moment, so they are just deploy noise.
@bpostlethwaite
Copy link
Member

cc @lundstrj

Copy link
Contributor

@shammamah-zz shammamah-zz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good -- just a couple of questions from me!

- dashr is completely disabled already, no need to re-enable here
- the others seem to be fine on playground
@josegonzalez
Copy link
Contributor Author

Discussed with @shammamah, we're getting rid of the branch deploy mechanism. It's pretty clunky and not necessary now that deploys are much quicker than before.

@josegonzalez
Copy link
Contributor Author

I'll delete all the branches post-merge.

ycaokris
ycaokris previously approved these changes Dec 13, 2019
Copy link
Contributor

@ycaokris ycaokris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃

The custom branch work is no longer necessary, as all branches other than master will now deploy to playground. Once an app lands in master, it will be deployed to gallery.
This was missing some environment variables in playground, but that has been fixed, so deploys work again.
@josegonzalez
Copy link
Contributor Author

I'll re-enable dash-gallery post-merge.

@lundstrj
Copy link
Contributor

I'm so happy you are doing this @josegonzalez

Copy link
Contributor

@ycaokris ycaokris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃 LGTM

Copy link
Contributor

@shammamah-zz shammamah-zz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Just one small comment.

log-info "exists: false"
if [[ "$CREATE_APP" == "true" ]]; then
log-warn "$APP not found, creating"
dds-client apps:create --name "$APP"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! So much faster than going to the web interface to create an app :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah and hopefully at some point I add support for creating redis/postgres for the apps too!

log-header "Deploying $APP"
log-info "dashr: ${is_dashr}"
if [[ "$is_dashr" == "false" ]]; then
local celery_version="$(cat "$app_dir/requirements.txt" | grep -E "^celery=")"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can also take the form celery>={version}!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually don't use celery in any of these apps, but once I add this to other monorepos, I'll keep that in mind - and come back to update this one.

@shammamah-zz shammamah-zz self-requested a review December 16, 2019 16:13
Copy link
Contributor

@shammamah-zz shammamah-zz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants