• Stars
    star
    111
  • Rank 303,538 (Top 7 %)
  • Language
    Scala
  • License
    MIT License
  • Created over 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An sbt plugin for deploying Heroku Scala applications

Heroku sbt Plugin

CI

This plugin is used to deploy Scala and Play applications directly to Heroku without pushing to a Git repository. This is can be useful when deploying from a CI server.

Using the Plugin

Add the following to your project/plugins.sbt file:

addSbtPlugin("com.heroku" % "sbt-heroku" % "2.1.4")

If you're not using Play, then you'll also need to add the sbt-native-packager plugin, which creates a stage task. Alternatively, you can deploy a fat JAR using sbt-assembly.

Next, add something like this to your build.sbt if you do not have a Heroku Git repo in your git remotes.

herokuAppName in Compile := "your-heroku-app-name"

Now, if you have the Heroku CLI installed, run:

$ sbt stage deployHeroku

If you do not have the CLI installed, then run:

$ HEROKU_API_KEY="xxx-xxx-xxxx" sbt stage deployHeroku

And replace "xxx-xxx-xxxx" with the value of your Heroku API token.

Requirements

  • It is required that you use sbt 0.13.5 or greater.

  • You must use Java 1.7 or higher locally.

  • This plugin has not been tested with Play 2.0 or 2.1.

Configuring the Plugin

You may set the desired JDK version like so:

herokuJdkVersion in Compile := "11"

For a list of supported JDK versions, refer to the Heroku Java Support DevCenter article.

You can (but probably should not) set configuration variables like so:

herokuConfigVars in Compile := Map(
  "MY_VAR" -> "some value",
  "JAVA_OPTS" -> "-XX:+UseCompressedOops"
)

If you adhere to the principles of the 12 Factor app, Configuration should be strictly seperated from code. Thus, you do not want to tie your configuration to your codebase. There are a few exceptions to this, such as conf/routes, and some JAVA_OPTS may be universal. But please use herokuConfigVars sparingly.

Any variable defined in herokuConfigVars will override defaults. However, if you remove a variable from this list, it will not automatically be removed from your Heroku app (even on the next deploy).

You may set process types (similar to a Procfile) with herokuProcessTypes:

herokuProcessTypes in Compile := Map(
  "web" -> "target/universal/stage/bin/my-app -Dhttp.port=$PORT",
  "worker" -> "java -jar target/universal/stage/lib/my-worker.jar"
)

You can include additional directories in the slug (they must be relative to the project root):

herokuIncludePaths in Compile := Seq(
  "app", "conf/routes", "public/javascripts"
)

You can run the plugin against all sub-projects (in addition to the root project) by setting the following option:

herokuSkipSubProjects in Compile := false

This defaults to true (and currently it only runs against all sub-projects or none).

You can disable the upload progress in the console by setting the heroku.log.format system property to false, like this:

$ sbt -Dheroku.log.format=false deployHeroku

See the src/sbt-test directory for examples.

Deploying a Fat JAR

If you are packaging your application with sbt-assembly or any other plugin that produces a "fat JAR", you can deploy that file by adding the following configuration to your build.sbt:

herokuFatJar in Compile := Some((assemblyOutputPath in assembly).value)

If not using sbt-assembly, you may replace (assemblyOutputPath in assembly).value with the relative path to your JAR file. Then you can deploy by running:

$ sbt assembly deployHeroku

The sbt-heroku plugin will skip the sbt-native-packager bits and deploy your JAR directly to Heroku.

Running a Remote Console

When using sbt-native-packager version 0.7.6 or greater, sbt-heroku will create a console process type for you. This command can be run like so:

$ heroku run console -a <appname>
Running `console` attached to terminal... up, run.5154
Picked up JAVA_TOOL_OPTIONS: -Xmx384m  -Djava.rmi.server.useCodebaseOnly=true
Failed to created JLineReader: java.lang.NoClassDefFoundError: scala/tools/jline/console/completer/Completer
Falling back to SimpleReader.
Welcome to Scala version 2.10.4 (OpenJDK 64-Bit Server VM, Java 1.8.0_20).
Type in expressions to have them evaluated.
Type :help for more information.

scala>

For older versions of Play 2.x it might be necessary to upgrade sbt-native-packager manually. You can do this by adding the following line of code to your project/plugins.sbt:

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.7.6")

Additionally, the is a bug in Scala 2.11.6 that causes this console task to fail. Upgrading to Scala 2.11.7 fixes the issue.

Deploying to Multiple Environments

To deploy to multiple Heroku app environments, you can use either system properties, environment variables, or any other native sbt/Java configuration method. For example, you might define your appName as a Map and choose a value with the system property as a key.

herokuAppName in Compile := Map(
  "test" -> "your-heroku-app-test",
  "stg"  -> "your-heroku-app-stage",
  "prod" -> "your-heroku-app-prod"
).getOrElse(sys.props("appEnv"), "your-heroku-app-dev")

Then run the sbt command like so:

$ sbt -DappEnv=test stage deployHeroku

Deploying from Git Branches

Another option when using multiple environments is to deploy from a Git branch that corresponds to the environment. This is particularly useful if you are using git-flow or a similar process.

First, add the sbt-git plugin ot your project/plugins.sbt like this:

resolvers += "jgit-repo" at "http://download.eclipse.org/jgit/maven"

addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.6.4")

Then in your build.sbt you can configure the sbt-heroku plugin to deploy to the environment that corresponds to the current Git branch like this:

import com.typesafe.sbt.SbtGit._

// ...
herokuAppName in Compile := Map(
  "testing"    -> "myapp-testing",
  "staging"    -> "myapp-staging",
  "production" -> "myapp"
).getOrElse(git.gitCurrentBranch.value, "myapp-dev")

showCurrentGitBranch

Hacking

In order to run the test suite, you must have the Heroku CLI installed. Then run:

$ sbt scripted

To run an individual test, use a command like this:

$ sbt "scripted settings/config_vars"

The heavy lifting for this plugin is done by the heroku-deploy library. The source code for that project can be found in the heroku-maven-plugin repository. If you need to update that library, do this:

$ git clone https://github.com/heroku/heroku-maven-plugin
$ cd heroku-maven-plugin/heroku-deploy
# make your changes
$ mvn clean install

Then update the heroku-deploy dependency version in the sbt-heroku build.sbt to whatever version is specified in the heroku-deploy pom.xml. The next time you run the scripted tests it will pick up the snapshot version from your local Maven repository.

More Repositories

1

react-refetch

A simple, declarative, and composable way to fetch data for React components
JavaScript
3,439
star
2

legacy-cli

Heroku CLI
Ruby
1,370
star
3

heroku-pg-extras

A heroku plugin for awesome pg:* commands that are also great and fun and super.
JavaScript
1,306
star
4

heroku-buildpack-nodejs

The official Heroku buildpack for Node.js apps.
Shell
1,265
star
5

node-js-getting-started

Getting Started with Node on Heroku
EJS
1,054
star
6

logplex

[DEPRECATED] Heroku log router
Erlang
984
star
7

heroku-buildpack-python

The official Heroku buildpack for Python apps
Ruby
953
star
8

heroku-django-template

A Django 2.0 base template featuring all recommended best practices for deployment on Heroku and local development.
Python
901
star
9

node-js-sample

This repository is deprecated. Head over to https://github.com/heroku/node-js-getting-started
JavaScript
847
star
10

cli

Heroku CLI
JavaScript
847
star
11

rails_12factor

Ruby
845
star
12

python-getting-started

Getting Started with Python on Heroku.
Python
818
star
13

heroku-buildpack-php

The official PHP buildpack for Heroku.
Shell
799
star
14

heroku-buildpack-go

Heroku Go Buildpack
Shell
790
star
15

heroku-buildpack-ruby

Heroku's Ruby Buildpack
Ruby
778
star
16

hk

DEPRECATED: see
Go
709
star
17

heroku-buildpack-static

[DEPRECATED] Heroku buildpack for handling static sites and single page web apps
Ruby
681
star
18

heroku-repo

Plugin for heroku CLI that can manipulate the repo
JavaScript
680
star
19

vegur

Vegur: HTTP Proxy Library
Erlang
620
star
20

heroku-accounts

Helps use multiple accounts on Heroku.
JavaScript
548
star
21

django-heroku

[DEPRECATED] Do not use! See https://github.com/heroku/django-heroku/issues/56
Python
465
star
22

heroku-buildpack-pgbouncer

Run pgbouncer in a dyno along with your application
Shell
335
star
23

devcenter-embedded-tomcat

Java
330
star
24

webapp-runner

Lightweight Application Launcher. Launch your webapp in the most popular open source web container available with a single command.
Java
319
star
25

docker-registry-client

A Go API client for the v2 Docker Registry API
Go
287
star
26

heroku-buildpack-google-chrome

Run (headless) Google Chrome on Heroku
Shell
283
star
27

stack-images

Recipies for building Heroku's stack images
Shell
264
star
28

java-getting-started

Getting Started with Java on Heroku
HTML
248
star
29

identity

[DEPRECATED] Login and OAuth management service for Heroku
CSS
247
star
30

go-getting-started

Getting Started with Go on Heroku https://devcenter.heroku.com/articles/getting-started-with-go
Dockerfile
246
star
31

heroku-buildpack-nginx

Run NGINX in a Heroku app
Shell
242
star
32

heroku-buildpack-apt

Buildpack that installs APT based dependencies
Shell
239
star
33

log-shuttle

HTTP log transport.
Go
236
star
34

terrier

Terrier is a Image and Container analysis tool that can be used to scan Images and Containers to identify and verify the presence of specific files according to their hashes.
Go
226
star
35

umpire

HTTP metrics monitoring endpoint
Ruby
221
star
36

platform-api

Ruby HTTP client for the Heroku API
Ruby
211
star
37

starboard

onboarding, offboarding, or crossboarding made easy
SCSS
204
star
38

salesforce-bulk

Python interface to the Salesforce.com Bulk API
Python
203
star
39

php-getting-started

Getting Started with PHP on Heroku
Twig
200
star
40

heroku-container-tools

DEPRECATED Heroku Toolbelt plugin to help configure, test and release apps to Heroku using local containers.
JavaScript
195
star
41

heroku-buildpack-scala

Heroku buildpack: Scala
Shell
190
star
42

node-heroku-client

A wrapper around the Heroku API for Node.js
JavaScript
188
star
43

roadmap

This is the public roadmap for Salesforce Heroku services.
187
star
44

vulcan

A build server in the cloud.
Ruby
172
star
45

pg_lock

Use Postgres advisory lock to isolate code execution across machines
Ruby
168
star
46

awsdetailedbilling

A toolkit for importing AWS detailed billing reports into Redshift
JavaScript
167
star
47

heroku-buildpack-java

A Heroku buildpack for Java apps.
Shell
167
star
48

pulse

DEPRECATED: Real-time Heroku operations dashboard
Clojure
161
star
49

heroku.rb

DEPRECATED! Official Heroku Ruby Legacy API wrapper
Ruby
161
star
50

heroku-buildpack-multi

[DEPRECATED] Please use https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app instead
Shell
157
star
51

erlang-in-anger

A little guide about how to be the Erlang medic in a time of war. It is first and foremost a collection of tips and tricks to help understand where failures come from, and a dictionary of different code snippets and practices that helped developers debug production systems that were built in Erlang.
TeX
157
star
52

plexy

A toolkit for building excellent APIs with Elixir
Elixir
154
star
53

heroku-buildpack-multi-procfile

Everyone gets a Procfile!
Shell
150
star
54

log2viz

DEFUNCT: Realtime analysis of your Heroku app logs.
Ruby
145
star
55

heroku.py

DEPRECATED! Heroku API wrapper for Python.
Python
142
star
56

facebook-template-nodejs

JavaScript
136
star
57

ruby-getting-started

Getting Started with Ruby on Heroku
Ruby
120
star
58

heroku-buildpack-chromedriver

Installs chromedriver in a Heroku slug
Shell
117
star
59

heroku-buildpack-clojure

Heroku's buildpack for Clojure applications.
Shell
115
star
60

mobile-template1

JavaScript
115
star
61

instruments

Collecting metrics over discrete time intervals
Go
112
star
62

heroku-buildpack-erlang

Erlang buildpack
Shell
107
star
63

cli-engine

TypeScript
97
star
64

semver.io

*DEPRECATED* The semver.io instance has now been sunset: https://github.com/heroku/semver.io/issues/74
CoffeeScript
96
star
65

facebook-template-php

example facebook app for heroku
PHP
96
star
66

terraform-provider-heroku

Terraform Heroku provider
Go
95
star
67

dotnet-buildpack

ASP.NET 5 Buildpack
Shell
92
star
68

kensa

A tool to help Heroku add-on providers integrate their services with Heroku
Ruby
92
star
69

netrc

Reads and writes netrc files.
Ruby
89
star
70

hstore_example

Ruby
89
star
71

alpinehelloworld

An Alpine-based Docker example
Python
85
star
72

heroku-kong

🐒 Kong API gateway as a Heroku app
Lua
84
star
73

heroku-buildpack-hello

Shell
82
star
74

heroku-releases-retry

CLI plugin to allow retrying the latest release-phase command
JavaScript
79
star
75

faceplate

A Node.js wrapper for Facebook authentication and API
JavaScript
76
star
76

rails_stdout_logging

Logs to stdout so you don't have to
Ruby
76
star
77

shaas

Shell as a Service: API to inspect and execute scripts in a server's environment via HTTP and WebSockets
Go
75
star
78

devcenter-spring-mvc-hibernate

AspectJ
75
star
79

heroku-buildpack-core-data

A Heroku Buildpack that generates a REST webservice from a Core Data model
Shell
74
star
80

heroku-buildpack-emberjs

**This buildpack is deprecated!** Please use the official Node.js buildpack combined with the static or nginx buildpack instead.
Ruby
72
star
81

facebook-template-python

Python
69
star
82

devcenter-java

Java
62
star
83

heroku-buildpack-c

C Language Pack
Shell
62
star
84

nibs

JavaScript
61
star
85

heroku-buildpack-gradle

This is a Heroku buildpack for Gradle apps. It uses Gradle to build your application and OpenJDK to run it.
Shell
61
star
86

heroku-buildpack-ember-cli

A Heroku buildpack for ember-cli apps; powers dashboard.heroku.com
Shell
60
star
87

heroku-guardian

Easy to use CLI security checks for the Heroku platform. Validate baseline security configurations for your own Heroku deployments.
Python
59
star
88

list-of-ingredients

An example of using Create React App with Rails 5 API and ActiveAdmin on Heroku
Ruby
56
star
89

heroku-fork

Heroku CLI plugin to fork an existing app into a new app
JavaScript
55
star
90

salesforce-buildpack

Heroku Buildpack for Salesforce
Shell
53
star
91

ruby-rails-sample

Ruby
52
star
92

facebook-template-ruby

CSS
52
star
93

heroku-jupyterlab

An example of running JupyterLab on Heroku, with Amazon S3.
Python
52
star
94

heroku-maven-plugin

This plugin is used to deploy Java applications directly to Heroku without pushing to a Git repository.
Java
51
star
95

cnb-builder-images

Recipes for building Heroku's Cloud Native Buildpacks builder images
Shell
51
star
96

stillir

Cache environment variables as Erlang app variables
Erlang
51
star
97

heroku-gradle-plugin

A Gradle plugin for deploying JAR and WAR files to Heroku.
Java
49
star
98

rails_serve_static_assets

Ruby
49
star
99

x

A set of packages for reuse within Heroku Go applications
Go
49
star
100

template-java-spring-hibernate

Java
48
star