12

The Problem

I have a Rails 3.1 app on Heroku which will soon require a bunch of (3rd party) submodules (some of which have submodules). Unfortunately, Heroku lacks submodule support. One suggestion on Heroku's website is to move the contents of the submodules into the main repo (here). This will work fine the first time, but there is a possibility that it won't the second. This could be caused by a major update in one of the third party submodules where a fast forward merge is unsuccessful. Obviously we can't manually merge a third party project.

The "Solution"

Our tentative solution is as follows:

  1. Create a new 'temp' branch based on the latest stable dev branch and merge the submodules into the project.
  2. Checkout to a heroku branch.
  3. Nuke the contents of this heroku branch to avoid any possible conflicts, i.e. create a commit with everything deleted.
  4. Merge the temp branch into the heroku branch.
  5. Push this heroku branch to our Heroku server.

The Advantages

This will avoid any possible conflicts in third party submodules and is scriptable.

The Disadvantages

This is extremely inelegant and is the ultimate anti-pattern for SVC.

The Question

Is there a better way to do this?

BinaryButterfly
  • 18,137
  • 13
  • 50
  • 91
Ben Sand
  • 1,130
  • 3
  • 11
  • 18

4 Answers4

11

Heroku now supports submodules.

http://devcenter.heroku.com/articles/git-submodules

However, this feature does not support submodules that are private.

Spike
  • 5,040
  • 5
  • 32
  • 47
  • @Ben, yes it does "support submodules", or yes it does "support submodules that are private"? – Hertzel Guinness Apr 08 '12 at 22:05
  • fyi, the link is dead, but i assume they just work (but not for private submodules, doh!) – B Robster Jul 23 '12 at 11:46
  • Hmm, not sure why they removed that article. There's a note about how submodules automatically work now on this page: https://devcenter.heroku.com/articles/python-pip#local_filebacked_distributions – Spike Jul 30 '12 at 04:26
  • 1
    Submodules do work, and you can get around the need to store username and password in plain text using an OAuth token: http://developer.github.com/v3/oauth/#get-or-create-an-authorization-for-a-specific-app – Richard Marr Nov 18 '13 at 12:58
  • Keep in mind that submodules only work if you push your repository to Heroku's remote directly (GitHub Sync and builds triggered via the API are not supported) – Krasimir Oct 22 '19 at 17:07
3

There is another alternative to @Daniel Eisenhardt approach: https://stackoverflow.com/a/29464430/990356

Go to Settings > Personal access tokens and generate a personal access token with repo scope enabled.

Now you can do git clone https://MY_TOKEN@github.com/user-or-org/repo and in the case of a submodule git submodule add https://MY_TOKEN@github.com/user-or-org/repo

Pros:

  • very simple approach
  • token can be easily revoked
  • your real password is safe

Cons:

  • if someone has access to the token, he can access your GitHub repos (read and write)
Community
  • 1
  • 1
tanguy_k
  • 11,307
  • 6
  • 54
  • 58
1

Since Heroku doesn't currently support submodules, one other possible way would be to use sub-tree merging.

Basically, sub-tree merging is a Git merging strategy that allows you to merge another git repository into yours, but in a subdirectory of your choosing. There's a tool called git-subtree, which tries to wrap this process in a way similar to git-submodule(1).

Other than the git-merge(1) man page, there are a few other articles that can help you with this merging strategy:

Markus
  • 526
  • 3
  • 5
  • this looks like a better way to handle simple submodules. but how could we use it for 3rd party submodules that have their own submodules? – Ben Sand Nov 21 '11 at 22:55
  • You could basically fork their repos, and do the same subtree merge with their submodules in there. This might work for you iff you can automate it, but otherwise there isn't anything else I can think of right now, sorry. – Markus Nov 23 '11 at 12:40
  • i guess they support submodules now, as long as they're public or you use Https with a username and password (e.g., github) – B Robster Jul 23 '12 at 11:46
0

You can simply add public submodules and heroku will fetch them for you when you deploy.

Heroku explains here that you can add private submodules to your repository, but you need to include the credentials which could be a security issue:

$ git submodule add https://username:password@github.com/myusername/FooBar

Unfortunately git stores your username and password in plain text when you do this.

  • See my comment above about OAuth http://developer.github.com/v3/oauth/#get-or-create-an-authorization-for-a-specific-app – Richard Marr Nov 18 '13 at 12:59