Git Product home page Git Product logo

heroku-buildpack-monorepo's Introduction

Heroku Monorepo Buildpack

Imagine you have a single code base, which has a few different applications within it... or at least the ability to run a few different applications. Or, maybe you're Google with your mono repo?

In any case, how do you manage this on Heroku? You don't. Heroku applications assume one repo to one application.

Enter the Monorepo buildpack, which is a copy of heroku-buildpack-multi-procfile except it moves the target path in to the root, rather than just the Procfile. This helps for ruby apps etc.

Usage

  1. Write a bunch of Procfiles apps and scatter them through out your code base.
  2. Create a bunch of Heroku apps.
  3. For each app, set APP_BASE=relative/path/to/app/root, and of course: heroku buildpacks:add -a <app> https://github.com/lstoll/heroku-buildpack-monorepo
  4. For each app, git push [email protected]:<app> master

Note: If you already have other buildpacks defined, you'll need to make sure that the heroku-buildpack-monorepo buildpack is defined first. You can do this by adding -i 1 to the heroku buildpacks:add command.

Authors

Andrew Gwozdziewycz [email protected] and Cyril David [email protected] and now Lincoln Stoll [email protected]

heroku-buildpack-monorepo's People

Contributors

apg avatar cyx avatar ecbrodie avatar edmorley avatar javidjamae avatar lstoll avatar sr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

heroku-buildpack-monorepo's Issues

Cannot copy directory into place

I've added this to my heroku app, but get the following error when it runs:

-----> Monorepo app detected
rm: cannot remove '/app': Read-only file system
FAILED to copy directory into place

It looks like previously the app would run rm -rf ${BUILD}/*, but now is trying to run rm -rf ${BUILD}.

Should it be reverted back to the way it was, or am I doing something wrong in my app?

monorepo breaks in-dyno postgres addon, within CI pipeline

If you add a postgres addon via your app.json, to be used during your CI testing, and you are using this buildpack, the test setup fails when it tries to find the DB the first time, with an error like "could not open file global/pg_filenode.map". This was observed with a Rails project, but I think the issue is generic, and I suspect in-dyno Redis addons also get messed up.

The problem is when using these in-dyno addons, Heroku adds a couple buildpacks that run before any of the app buildpacks, and they install directories like /app/.indyno, /app/.profile.d and /app/.sprettur (at least those are what I found when debugging). When monorepo comes along to do its thing, it wipes out /app/*, and the addons are broken.

I have a simple fix that is working for me at master...mindtrip-ai:heroku-buildpack-monorepo:master . I was undecided about preserving specific Heroku files, but wound up preserving all dotfiles in case the Heroku set expands.

Work with pipelines / review apps

Hi, thanks for this great buildpack.

Is there any way to set up review apps, so that PRs created on github could build and deploy the project to two different review apps (if I've got 2 sub-projects)?

Or is this simply not possible on heroku? Shame if so.. :(

I've managed to deploy and run my code just fine from the monorepo, the pain comes when trying to set up the review apps as there seems to be no way to create two review apps per branch, as I guess you'd need to.

This is my app.json which does deploy one half of my application correctly:


{
    "name": "Heroku Mono Repo",
    "env": {
      "APP_BASE": {
          "required": true,
          "value": "web"
      }
    },       
    "addons": [     
      {
        "plan": "heroku-postgresql"        
      }
    ],
    "buildpacks": [
      {
          "url": "https://github.com/lstoll/heroku-buildpack-monorepo.git"
      },
      { 
          "url": "https://github.com/heroku/heroku-buildpack-clojure.git"          
      }     
    ]
  }

Any help would be much appreciated!

Readme title is not up to date

Leftover of the copy paste from Heroku Multi Procfile buildpack, the readme title should be:
«Heroku Monorepo buildpack»

Not installing dependencies for Python project

I'm trying to set up Heroku monorepo to this repository.

The buildpack apparently is able to detect the Procfile and the APP_ROOT.

But it's not installing the dependencies for the project, in fact, is not running any command at all.

Build log:

-----> Building on the Heroku-20 stack
-----> Using buildpack: https://github.com/lstoll/heroku-buildpack-monorepo
-----> Monorepo app detected
      Copied modules/kubrick to root of app successfully
-----> Discovering process types
       Procfile declares types -> release, web
-----> Compressing...
       Done: 3.5M
-----> Launching...
 !     Release command declared: this new release will not be available until the command succeeds.
       Released v11
       https://aposcar.herokuapp.com/ deployed to Heroku

My release command fails because of that:

Traceback (most recent call last):
  File "manage.py", line 11, in main
    from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 13, in main
    raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?

My Procfile is in the APP_ROOT, not the repo root itself.

release: python manage.py migrate && python manage.py loaddata initial_data/*
web: gunicorn kubrick.wsgi

Buildpack incompatible with building in /app ("rm: cannot remove '/app': Read-only file system")

Hi

I'm on the team that maintains Heroku's build system and official buildpacks, and wanted to let you know about a future incompatibility with this buildpack.

The directory in which the Heroku build system performs builds is currently a path like/tmp/build_<hash>.

In the near future this path will be changing to /app so that the build-time and run-time app locations are the same path - in order to resolve a number of long standing bugs and reduce the number of hacks buildpacks have to use to work around non-relocatable languages/toolchains.

One side-effect of this build directory change is that it will no longer be possible to rm -rf $BUILD_DIR since that will now be equivalent to rm -rf /app, and due to the way slugs are mounted inside a dyno, the /app directory is read-only (not the contents of the directory, only the directory listing itself).

As such once this change comes into effect this buildpack will error like so:

remote: -----> Monorepo app detected
remote: rm: cannot remove '/app': Read-only file system
remote:       FAILED to copy directory into place
remote:  !     Push rejected, failed to compile Monorepo app.

Due to this line:

rm -rf "${BUILD_DIR}" &&

In order to resolve this, the buildpack needs to instead delete only the contents of the directory, not the directory root.

For example by doing:

shopt -s dotglob
rm -rf "${BUILD_DIR}"/*

The dotglob is required in order that the wildcard matches dotfiles, since by default it doesn't:
https://wiki.bash-hackers.org/internals/shell_options#dotglob

In addition, this line will need adjusting to take into account the fact that the build directory will already exist (otherwise the mv will nest the moved directory inside the build directory, rather than place the contents in its root):

mv "${STAGE}/$(basename "$APP_BASE")" "${BUILD_DIR}"

I'll open a PR :-)

App not compatible with buildpack

I followed all the steps in the README, but this doesn't seem to work. Am I missing something?

$ ls -la
total 32
drwxr-xr-x@  9 javidjamae  staff   306 Sep 13 22:24 .
drwxr-xr-x@  9 javidjamae  staff   306 Sep 13 09:40 ..
drwxr-xr-x  15 javidjamae  staff   510 Sep 23 10:09 .git
-rw-r--r--   1 javidjamae  staff    18 Jul  3 15:39 .gitignore
-rw-r--r--   1 javidjamae  staff  3829 Sep  1 20:12 README.md
drwxr-xr-x   4 javidjamae  staff   136 Sep 10 12:35 eslint-files
drwxr-xr-x  26 javidjamae  staff   884 Sep 20 08:59 node-server
drwxr-xr-x  27 javidjamae  staff   918 Sep 23 10:20 react-native
$ git remote -v
origin	[email protected]:myapp.git (fetch)
origin	[email protected]:myapp.git (push)
production	https://git.heroku.com/myapp.git (fetch)
production	https://git.heroku.com/myapp.git (push)
staging	https://git.heroku.com/myapp-staging.git (fetch)
staging	https://git.heroku.com/myapp-staging.git (push)
$ heroku config:add APP_BASE=node-server --remote staging
 ▸    heroku-cli: update available from 6.13.5 to 6.14.25-4fab11b
Setting APP_BASE and restarting ⬢ myapp-staging... done, v24
APP_BASE: node-server
$ heroku buildpacks:add -a myapp-staging https://github.com/lstoll/heroku-buildpack-monorepo
 ▸    heroku-cli: update available from 6.13.5 to 6.14.25-4fab11b
Buildpack added. Next release on myapp-staging will use:
  1. heroku/nodejs
  2. https://github.com/lstoll/heroku-buildpack-monorepo
$ git push staging master -f
Counting objects: 2830, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2747/2747), done.
Writing objects: 100% (2830/2830), 7.15 MiB | 437.00 KiB/s, done.
Total 2830 (delta 1882), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> App not compatible with buildpack: https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/nodejs.tgz
remote:        More info: https://devcenter.heroku.com/articles/buildpacks#detection-failure
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !	Push rejected to myapp-staging.
remote:
To https://git.heroku.com/myapp-staging.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/myapp-staging.git'

Packages depencies with each other ?

What if the different packages have dependency on each other ?

Moving app to root will kill those dependencies before installing and resolving dependencies

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.