Skip to content

Commit

Permalink
initial support for heroku deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
atomfrede committed Jun 28, 2020
1 parent 68abec7 commit e516c77
Show file tree
Hide file tree
Showing 8 changed files with 472 additions and 0 deletions.
69 changes: 69 additions & 0 deletions generators/heroku/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* eslint-disable consistent-return */
const chalk = require('chalk');
const HerokuGenerator = require('generator-jhipster/generators/heroku');
const constants = require('generator-jhipster/generators/generator-constants');

module.exports = class extends HerokuGenerator {
constructor(args, opts) {
super(args, { fromBlueprint: true, ...opts }); // fromBlueprint variable is important

const jhContext = (this.jhipsterContext = this.options.jhipsterContext);

if (!jhContext) {
this.error(`This is a JHipster blueprint and should be used only like ${chalk.yellow('jhipster --blueprint micronaut')}`);
}

this.configOptions = jhContext.configOptions || {};
}

get initializing() {
return super._initializing();
}

get prompting() {
return super._prompting();
}

get configuring() {
return super._configuring();
}

get default() {
// Here we are not overriding this phase and hence its being handled by JHipster
const phaseFromJHipster = super._default();
const jhipsterMicronautDefaultPhaseSteps = {
copyHerokuFiles() {
if (this.abort) return;

const done = this.async();
this.log(chalk.bold('\nCreating Heroku deployment files'));

// this.template('bootstrap-heroku.yml.ejs', `${constants.SERVER_MAIN_RES_DIR}/config/bootstrap-heroku.yml`);
this.template('application-heroku.yml.ejs', `${constants.SERVER_MAIN_RES_DIR}/application-heroku.yml`);
this.template('Procfile.ejs', 'Procfile');
this.template('system.properties.ejs', 'system.properties');
if (this.buildTool === 'gradle') {
this.template('heroku.gradle.ejs', 'gradle/heroku.gradle');
}
if (this.useOkta) {
this.template('provision-okta-addon.sh.ejs', 'provision-okta-addon.sh');
fs.appendFile('.gitignore', 'provision-okta-addon.sh', 'utf8', (err, data) => {
this.log(`${chalk.yellow.bold('WARNING!')}Failed to add 'provision-okta-addon.sh' to .gitignore.'`);
});
}

this.conflicter.resolve(err => {
done();
});
},
addHerokuDependencies() {
// Nothing to do here right now
},
}
return Object.assign(phaseFromJHipster, jhipsterMicronautDefaultPhaseSteps);
}

get end() {
return super._end();
}
};
22 changes: 22 additions & 0 deletions generators/heroku/templates/Procfile.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%#
Copyright 2013-2020 the original author or authors from the JHipster project.
This file is part of the JHipster project, see https://www.jhipster.tech/
for more information.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-%>
web: java $JAVA_OPTS <% if (applicationType === 'gateway' || dynoSize === 'Free') { %>-Xmx256m<% } %> -jar <% if (buildTool === 'maven') { %>target<% } %><% if (buildTool === 'gradle') { %>build/libs<% } %>/*.jar --spring.profiles.active=prod,heroku<% if (buildTool == 'maven' && herokuDeployType == 'git') { %>,no-liquibase<% } %> --micronaut.server.port=$PORT
<%_ if (buildTool == 'maven' && herokuDeployType == 'git' && (prodDatabaseType === 'postgresql' || prodDatabaseType === 'mysql' || prodDatabaseType === 'mariadb')) { _%>
release: cp -R src/main/resources/config config && ./mvnw -ntp liquibase:update -Pprod,heroku
<%_ } _%>
43 changes: 43 additions & 0 deletions generators/heroku/templates/application-heroku.yml.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<%#
Copyright 2013-2020 the original author or authors from the JHipster project.
This file is part of the JHipster project, see https://www.jhipster.tech/
for more information.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-%>
# ===================================================================
# Micronaut configuration for the "heroku" profile.
#
# This configuration overrides the application.yml file.
# ===================================================================

# ===================================================================
# Standard Micronaut configuration properties.
# Full reference is available at:
# https://docs.micronaut.io/latest/guide/configurationreference.html
# ===================================================================



datasources:
default:
<%_ if (prodDatabaseType === 'postgresql' || prodDatabaseType === 'mysql' || prodDatabaseType === 'mariadb') { _%>
type: com.zaxxer.hikari.HikariDataSource
url: ${JDBC_DATABASE_URL}
username: ${JDBC_DATABASE_USERNAME}
password: ${JDBC_DATABASE_PASSWORD}
hikari:
maximum-pool-size: 8
<%_ } _%>

29 changes: 29 additions & 0 deletions generators/heroku/templates/bootstrap-heroku.yml.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<%#
Copyright 2013-2020 the original author or authors from the JHipster project.
This file is part of the JHipster project, see https://www.jhipster.tech/
for more information.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-%>
# ===================================================================
# Spring Cloud Config bootstrap configuration for the "heroku" profile
# ===================================================================

<%_ if (serviceDiscoveryType === 'eureka') { _%>
spring:
cloud:
config:
fail-fast: true
uri: ${JHIPSTER_REGISTRY_URL}/config
<%_ } _%>
41 changes: 41 additions & 0 deletions generators/heroku/templates/heroku.gradle.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<%#
Copyright 2013-2020 the original author or authors from the JHipster project.
This file is part of the JHipster project, see https://www.jhipster.tech/
for more information.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-%>
apply plugin: "com.heroku.sdk.heroku-gradle"

heroku {
appName = "<%= herokuAppName %>"
buildpacks = ["heroku/jvm"]
}
<%_ if (herokuDeployType === 'git') { _%>
// Task stage is used by Heroku, see also
// https://devcenter.heroku.com/articles/deploying-gradle-apps-on-heroku
// and GRADLE_TASK configuration variable.
task stage(dependsOn: "jar") {
}
gradle.taskGraph.whenReady {taskGraph ->
taskGraph.afterTask() {task ->
if (task.getName().equals("stage") && System.getenv("DYNO") != null) {
delete "node_modules"
delete fileTree(dir: "build/libs", exclude: "*.jar")
}
}
}
<%_ } _%>
50 changes: 50 additions & 0 deletions generators/heroku/templates/pom-profile.xml.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<build>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<configuration combine.self="override">
<changeLogFile>src/main/resources/config/liquibase/master.xml</changeLogFile>
<diffChangeLogFile>src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml</diffChangeLogFile>
<driver></driver>
<url>${env.JDBC_DATABASE_URL}</url>
<defaultSchemaName></defaultSchemaName>
<username>${env.JDBC_DATABASE_USERNAME}</username>
<password>${env.JDBC_DATABASE_PASSWORD}</password>
<referenceUrl>hibernate:spring:<%= packageName %>.domain?dialect=<% if (prodDatabaseType === 'mysql') { %>org.hibernate.dialect.MySQL8Dialect<% } else if (prodDatabaseType === 'mariadb') { %>org.hibernate.dialect.MariaDB103Dialect<% } else if (prodDatabaseType === 'postgresql') { %>io.github.jhipster.domain.util.FixedPostgreSQL10Dialect<% } else if (prodDatabaseType === 'h2Disk') { %>org.hibernate.dialect.H2Dialect<% } else if (prodDatabaseType === 'oracle') { %>org.hibernate.dialect.Oracle12cDialect<% } else if (prodDatabaseType === 'mssql') { %>org.hibernate.dialect.SQLServer2012Dialect<% } %>&amp;hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&amp;hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy</referenceUrl>
<verbose>true</verbose>
<logging>debug</logging>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>${maven-clean-plugin.version}</version>
<executions>
<execution>
<id>clean-artifacts</id>
<phase>install</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>target</directory>
<excludes>
<exclude>*.jar</exclude>
</excludes>
<followSymlinks>false</followSymlinks>
</fileset>
<fileset>
<directory>node_modules</directory>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Loading

0 comments on commit e516c77

Please sign in to comment.