-
Sign up/log in on Heroku by visiting https://www.heroku.com/.
-
Install the command line client for Heroku: Heroku CLI
NoteThe Travis client might also be useful at later stages of the course, you can install it from here: Travis CLI -
Log in to Heroku CLI by opening a terminal an typing:
heroku login
.
We are creating a Heroku application and deploying the Hello world! Spring example. Additionally, the steps below will make it possible to store multiple different applications in the same git repository and deploy them individually to Heroku. Steps will be shown through the example EventRegistration application, and should be adapted in the course project.
Note
|
All actions described here for configuring Heroku applications using the Heroku CLI could also be done via the web UI. |
-
Once you are logged in with the Heroku-CLI, create a new Heroku application: in the root of the git repository of your repository (assumed to be ~/git/eventregistration), issue the below command to create an application named "eventregistration-backend-<UNIQUE_ID>".
heroku create eventregistration-backend-<UNIQUE_ID> -n
Note
|
In Heroku, the application name should be unique Heroku-wise, that is, each application in Heroku’s system should have a unique name. If you don’t provide a name parameter for the command, Heroku will randomly generate one. |
-
Add the multi procfile and Gradle buildpacks to the app.
heroku buildpacks:add -a eventregistration-backend-<UNIQUE_ID> https://github.com/heroku/heroku-buildpack-multi-procfile heroku buildpacks:add -a eventregistration-backend-<UNIQUE_ID> heroku/gradle
CautionOrder is important.
-
Open the Heroku applications web page and go to Resources, then add the Heroku Postgres add-on.
-
Click the entry for Postgres within the list of add-ons, then go to Settings. You can see the database credentials there.
NoteThe credentials are periodically updated and changed by Heroku, so make sure that you are using the actual credentials when manually connecting to the database. (E.g., during manual testing.)
-
Before deploying, a top level build.gradle and settings.gradle need to be created in the root of the repository (i.e., in ~/git/eventregistration)
build.gradle:task stage () { dependsOn ':EventRegistration-Backend:assemble' }
settings.gradle:
include ':EventRegistration-Backend'
-
Generate the Gradle wrapper with the newest Gradle version
gradle wrapper --gradle-version 5.6.2
-
Create a .gitignore file for the .gradle folder:
.gitignore:.gradle/
-
Add all new files to git
git add . git status #make sure that files in .gradle/ are not added
Expected output for
git status
:On branch master Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to publish your local commits) Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: .gitignore new file: build.gradle new file: gradle/wrapper/gradle-wrapper.jar new file: gradle/wrapper/gradle-wrapper.properties new file: gradlew new file: gradlew.bat new file: settings.gradle
Commit changes:
git commit -m "Adding Gradle wrapper"
-
Within the EventRegistration-Backend folder, create a file called Procfile (not Procfile.txt, name it exactly Procfile) with the content:
web: java -jar EventRegistration-Backend/build/libs/EventRegistration-Backend-0.0.1-SNAPSHOT.jar
-
Add the Procfile to a new commit
-
Configure the multi-procfile buildpack to find the Procfile:
heroku config:add PROCFILE=EventRegistration-Backend/Procfile --app eventregistration-backend-<UNIQUE_ID>
-
Obtain and copy the Heroku Git URL
heroku git:remote --app eventregistration-backend-<UNIQUE_ID> --remote backend-heroku
Output:
set git remote backend-heroku to https://git.heroku.com/eventregistration-backend-<UNIQUE_ID>.git
-
Verify that the
backend-heroku
remote is successfully added besidesorigin
withgit remote -v
. Output:backend-heroku https://git.heroku.com/eventregistration-backend-123.git (fetch) backend-heroku https://git.heroku.com/eventregistration-backend-123.git (push) origin git@github.com:imbur/eventregistration.git (fetch) origin git@github.com:imbur/eventregistration.git (push)
-
Deploy your application with
git push backend-heroku master
NoteIf it fails to build, make sure you try understanding the output. Typical issue: buildpacks are not added/are not in the right order. -
Visit the link provided in the build output. It may take some time (even 30-60 seconds) for the server to answer the first HTTP request, so be patient!
-
Save your work to the GitHub repository, too:
git push origin master
Final layout of the files (only two directory levels are shown and hidden items are suppressed):
~/git/eventregistration ├── build.gradle ├── EventRegistration-Backend │ ├── build │ │ ├── classes │ │ ├── libs │ │ ├── resources │ │ └── tmp │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ ├── gradlew │ ├── gradlew.bat │ ├── Procfile │ ├── settings.gradle │ └── src │ ├── main │ └── test ├── gradle │ └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── README.md └── settings.gradle