Heroku Tips & Tricks

TODO

TODO: merge in instructions from: aiconductor_execution-engine_workflow

TODO: add keywords from web history

packaging for heroku

    <dependency>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>appassembler-maven-plugin</artifactId>
        <version>${appassembler-maven-plugin.version}</version>
    </dependency>

...

    <build>
            <plugins>
                <!--
                Creates jar which could be easily launched from Heroku:
                http://mojo.codehaus.org/appassembler/appassembler-maven-plugin/usage-program.html
                mvn package appassembler:assemble

                procfile:
                http://stackoverflow.com/questions/8060158/heroku-can-i-call-maven-from-procfile  (uses older version of appassembler)
                -->
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>appassembler-maven-plugin</artifactId>
                    <version>${appassembler-maven-plugin.version}</version>
                    <!-- http://maven.apache.org/guides/mini/guide-configuring-plugins.html#Using_the_executions_Tag -->
                    <configuration>
                        <assembleDirectory>${project.basedir}/appassembler</assembleDirectory>
                        <programs>
                            <program>
                                <!-- predictionWorker:
                                <mainClass>org.activeintel.aiconductor.execution.engine.workflow.run.ExecutionEnginePredictionWorker</mainClass>
                                -->
                                <!-- workflowWorker:
                                -->
                                <mainClass>org.activeintel.aiconductor.execution.engine.workflow.run.ExecutionEnginePredictionWorkflowWorker</mainClass>
                                <id>execengine</id>
                            </program>
                        </programs>
                    </configuration>
                    <executions>
                        <execution>
                            <id>appassembler</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>assemble</goal>
                                <goal>create-repository</goal>
                            </goals>
                        </execution>
                        <!-- this alone might be necessary; the one above does not always works -->
                        <execution>
                            <id>assemble</id>
                            <goals>
                                <goal>assemble</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

            </plugins>
    </build>

 

pointing to local dependencies

Point to local dependencies packaged with appassembler Note: some repos don’t get properly packaged; in that case may need to copy them manually.

<!-- https://devcenter.heroku.com/articles/local-maven-dependencies -->
<repositories>
    <repository>
        <id>project.local</id>
        <name>project</name>
        <url>file:${project.basedir}/appassembler/repo</url>
    </repository>
</repositories>

Dependencies

Fixing Transitive Dependencies

Heroku doesn’t seem to handle well maven’s transitive dependencies; so they may need to be explicitly included in your pom; e.g:

    <!-- AWS Dependencies -->
    <!-- doesn't need to be included; but is for heroku -->
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk</artifactId>
        <version>${aws-java-sdk.version}</version>
    </dependency>

    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-flow-build-tools</artifactId>
        <version>${aws-java-sdk.version}</version>
    </dependency>

maven-dependency-plugin

<build>
        <plugins>
            <!-- for heorku: https://devcenter.heroku.com/articles/getting-started-with-java
                 not sure if it is needed (since using appsembler; but kept it for now-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals><goal>copy-dependencies</goal></goals>
                    </execution>
                </executions>
            </plugin>

Deployment

WARNING: heroku deploys from git repository; so make sure all the changes are committed; also make sure that you are deploying from the right branch.

example of deploying current feature to heroku:

git push -f  heroku feature/engine_init:master

git push -f  heroku develop:master

 

Changing Deployment

To add or change a different deployment point can do the following (ref):

git remote add prod-heroku GIT_URL
git push prod-heroku production:master

Setting up Development / Production Environments

https://devcenter.heroku.com/articles/fork-app

(also referred to as staging)

I prefer to have dev (heroku) as my default

 

Maven

Don’t forget to make sure that artificats packaging is jar:

<packaging>jar</packaging> <!-- needed for heroku -->

Clear Repo Cache (ref)

mvn clean install -U

To enable checking for a changed dependency although the version number didn’t change go to the “Maven Projects” tab, select “Maven settings” and there activate “Always update snapshots”. (ref)

To ensure that all packages are included run:

mvn package

Stack: Play (Scala), MongoDB, AngularJS

Great Tutorial:
ReactiveMongo, Play & AngularJS (mongodb)
https://github.com/lashford/modern-web-template/
http://www.cakesolutions.net/teamblogs/2014/03/13/reactivemongo-play-angularjs/

https://github.com/ReactiveMongo/Play-ReactiveMongo

!! Heroku

@see https://bitbucket.org/neil_rubens/sector-predictor_db

Need to add `Procfile` https://devcenter.heroku.com/articles/play-support

Make sure that the `appname` matches in `Procfile` and `Build.scala`.

Logs

heroku logs –tail

Ssh

heroku run bash

keywords

maven pom.xml heroku scala java

Problem:

[ERROR] Failed to execute goal on project …: Could not resolve dependencies for project …:jar:1.1-SNAPSHOT: Could not find artifact …:jar:1.1-SNAPSHOT in project.local (file:/tmp/build_24b6a25f-cfbc-4492-bbdb-186ab27489ac/appassembler/repo) -> [Help 1]

Solution: mvn package

Problem:

app[worker.1]: Error: Could not find or load main class

Solution:

<packaging>jar</packaging> <!– needed for heroku –>

may also need to manually call: mvn package appassembler:assemble

also make sure that appassembler has:

<execution>
<id>assemble</id>
<goals>
<goal>assemble</goal>
</goals>
</execution>

 

 

 

 

 

About Neil Rubens

see http://ActiveIntelligence.org
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*