A few days ago, I was trying to deploy a NodeJS application on Heroku. When I was trying to push the same to Heroku using the Heroku CLI, I got an error stating that the deployment failed, since the CLI could not access the private submodule.
The Heroku documentation provides a workaround for this to allow it to resolve Private Submodules in non-local environments —
For instance, to add the FooBar submodule using an HTTP basic authentication URL scheme (note the presence of the username:password tokens):
git submodule add https://username:email@example.com/myusername/FooBar
The problem with the method is that git submodule references are stored in plaintext in the
.git/submodules directory, and thus, it can be a security issue.
Heroku allows us to deploy an application using a container as well.
Thus, I created a simple Dockerfile to build my project and then push it to Heroku's Container Registry.
This example uses a NodeJS project to show the same.
Dockerfile needs to be added to the root folder of your NodeJS folder.
You also need to add a
.dockerignore file as follows:
Heroku will always ignore the PORT you have set for your project, and thus your NodeJS app must use the value
const PORT = process.env.PORT || 5000 to ensure that the project runs both locally and on the Heroku deployment.
After this follow the given steps using Heroku CLI
$ heroku login $ heroku container:login $ heroku create <optional app name> $ heroku container:push web $ heroku container:release web
Here we first login to our Heroku Account and then the Heroku Container Registry, followed by creating a new Heroku app and then building the Docker image using
push and then using the
release command to "release" the image to your app.
You can then use
heroku open to access your application!
Congratulations 🎉, you have now deployed your project on Heroku using Containers and even avoided having to copy the submodules to a new Repository or compromising your security by saving the password in plaintext.
You can repeat the given steps every time you have a new build!
I hope this helps someone 😄