5

So I'm trying to deploy my app to Heroku. Here is my docker-compose.yml

version: '3'

#Define services
services:

  #Back-end Spring Boot Application
  entaurais:
    #The docker file in scrum-app build the jar and provides the docker image with the following name.
    build: ./entauraIS
    container_name: backend
    #Environment variables for Spring Boot Application.
    ports:
     - 8080:8080 # Forward the exposed port 8080 on the container to port 8080 on the host machine
    depends_on:
    - postgresql

  postgresql:
    image: postgres:13
    environment:
      - POSTGRES_PASSWORD=root
      - POSTGRES_USER=postgres
      - POSTGRES_DB=entauracars
    ports:
      - "5433:5433"
    expose:
      - "5433"

  entaura-front:
    build: ./entaura-front
    container_name: frontend
    ports:
      - "4200:4200"
    volumes:
      - /usr/src/app/node_modules

My frontend Dockerfile:

FROM node:14.15.0
RUN mkdir /usr/src/app
WORKDIR /usr/src/app
COPY package*.json /usr/src/app/
RUN npm install
COPY . /usr/src/app
EXPOSE 4200
CMD [ "npm", "start" ]

My backend Dockerfile:

FROM maven:3.6.0-jdk-11-slim AS build
COPY src /usr/src/app/src  
COPY pom.xml /usr/src/app  
RUN mvn -f /usr/src/app/pom.xml clean package

FROM openjdk:11-jre-slim
COPY --from=build /usr/src/app/target/entauraIS.jar /usr/app/entauraIS.jar
ENTRYPOINT ["java","-jar","/usr/app/entauraIS.jar"]

As far as I'm aware heroku needs it's own heroku.yml file, but with the examples I've seen I have no idea how to convert it to my sitaution. Any help is appreaciated, I am completely lost with Heroku.

One of the examples of heroku.yml that I looked at:

build:
  docker:
    web: Dockerfile
run:
  web: npm run start
release:
  image: web
  command:
    -npm run migrate up
Mantas
  • 83
  • 1
  • 10

1 Answers1

-1

docker-compose.yml to heroku.yml

docker-compose has some similar fields that heroku.yml. You could create manually.

It will be awesome the creation of some npm module to convert the docker-compose to heroku.yml. You just need to read the docker-compose.yml and pick some values to create a heroku.yml. Check this to know how read and write yml files.

docker is not required in heroku

If you are looking for a platform to deploy your apps and avoid infrastructure nightmares, heroku is an option for you.

Even more, if your application are standard (java & nodejs), does not need crazy configurations to build and is self-contained (no private libraries), you don't need docker :D

If your nodejs package.json has the standard scripts: start and build, it will run in heroku just perform git push to heroku without Dockerfile. Heroku will detect the nodejs, version and your app will start.

If your java has the spring-boot standard configurations, is the same, just push your code to heroku. In this case, previously to the push, add the postgress add-on manually and use environment variables in your application.properties jdbc url.

one process by app in heroku

If you have api + frontend you will need two apps in heroku. Also your api will need the postgress add-on

Heroku does not work like docker-compose, I mean : one host with all of your apps: front + api + db

Docker

If you want to use Docker, just put the Dockerfile and git push. Heroku will detect that docker is required and will perform the standard commands : docker build ... docker run... so, no extra configuration is required

heroku.yml

If you Docker is mandatory for your apps, and the standard docker build ... and docker run... is not enough for your apps, you wil need heroku.yml

You will need one heroku.yml by each app in heroku.

One advantage of this could be that the manually addition of postgress add-on will not required because is defined in heroku.yml

JRichardsz
  • 14,356
  • 6
  • 59
  • 94
  • So if I want to run 3 containers (frontend, backend and postgresql) would that mean I would need to run them as 3 seperate apps? Wouldn't that be a nightmare communication-wise between them? Sorry this is very confusing to me. Using docker is required in my case, and docker-container let's me launch everything simultaneously. What do you think is my best option to making that app accessable to the public? – Mantas Apr 17 '21 at 14:34
  • Did you hear about distributed systems? Java app and database process in the same host is just for development or testing purposes. In real or production environments, database must be in a separate host, the backend api in another host and the frontend yes, in another host. This is the most current approach and heroku or docker and other technologies are designed for that. As you said, docker-compose let's you launch everything simultaneously. That is good but for development or testing, nor for production. maybe in a very limited production environment prone to many errors – JRichardsz Apr 17 '21 at 16:24
  • Is your apps just a poc in your job, some homework or is an app for real users? In all cases, the easiest way is heroku. If your apps are standard, docker is not required. From development to production, heroku is a good choice. Another complex options could be to use amazon, azure or gcp with docker and kubernetes. – JRichardsz Apr 17 '21 at 16:28
  • It's a personal project that won't see any real users. I just wanted to somehow implement docker into this but I'm probably way over my head here. – Mantas Apr 17 '21 at 16:34
  • Yes. For your current approach, docker is not required. First create a new app in heroku, add the postgress add-on and perform the git push without Dockerfile. Heroku will detect the pom.xml existence and will determinate that is a java application. If everything works, test your api with postman. If everything works, a new app in heroku for frontend. That is all you need ;) – JRichardsz Apr 17 '21 at 16:43
  • Thanks for the help. Deploying in heroku with standard apps is no issue at all, just tried it and it's just a few git commands. I'll come back to docker later on, time is not on my side at the moment – Mantas Apr 17 '21 at 16:47