user8371723
user8371723

Reputation:

Spring Boot/Java Heroku Gitlab Continous Deployment

I would like to deploy Spring Boot app from gitlab using Gitlab runner to Heroku. I find some tutorials but for ruby.

gitlab-ci.yml

image: maven:3-jdk-8 

before_script:
    - java -version
    - mvn -version

    variables:
      MAVEN_OPTS: "-Dmaven.repo.local=.m2"

cache:
  paths:
    - .m2/

stages:
  - install
  - test
  - deploy

project-install:
  stage: install
  script:
      - mvn install -P gitlab

backend-test:
 stage: test
  script:
      - mvn verify -pl backend -P itTest,gitlab

heroku-deploy:
????

I found maven heroku plugin but my project is under gitlab repository not heroku repository. Moreover i cannot find proper configuration for this plugin. I want to pass login and password via this plugin to connect to heroku.

My current config:

<plugin>
   <groupId>com.heroku.sdk</groupId>
   <artifactId>heroku-maven-plugin</artifactId>
   <version>1.2.0</version>
   <configuration>
       <appName>app-name</appName>
       <processTypes>
           <web>java $JAVA_OPTS -jar target/*.jar</web>
       </processTypes>
   </configuration>
</plugin>

Maybe I could do continuous deployment. Can anyone help?

Upvotes: 2

Views: 3640

Answers (1)

Kanishka Srinivasan
Kanishka Srinivasan

Reputation: 19

Guess this would help. This works for spring boot application, where we use ruby 'gem' to deploy the app in heroku.

  1. Replace the "appName" with the Heroku app you already created at your Heroku dashboard.
  2. Also add HEROKU_API_KEY(can be found in heroku) as variable in Gitlab CI/CD settings.

And the maven plugin is NOT needed.

gitlab-ci.yml

stages:
  - build
  - test
  - deploy

maven-build:
  image: maven:3-jdk-8
  stage: build
  script: "mvn package -B"

maven-test:
  image: maven:3-jdk-8
  stage: test
  script: "mvn test -B"

deploy:
  stage: deploy
  image: ruby:latest
  script:
  - apt-get update -qy
  - apt-get install -y ruby-dev
  - gem install dpl
  - dpl --provider=heroku --app=<appName> --api-key=$HEROKU_API_KEY
  only:
  - master

Upvotes: 1

Related Questions