DEV Community

Cover image for Fullstack app: Deploying the Fullstack Application on Render with Docker
Matheus Bernardes Spilari
Matheus Bernardes Spilari

Posted on

Fullstack app: Deploying the Fullstack Application on Render with Docker

This is the third part of this tutorial.

On the first part we have built the frontend, using Vite, React and Typescript.
The second part we build the backend using Spring Boot.

Now, we are going to deploy the application on Render.


Running locally

To test if everything is working fine, we are going to run all the parts of our application locally.

For that, we are going to use Docker-compose.

So, let's build our docker-compose.yaml file.

Create a docker-compose.yaml on the same level of the directories backend and frontend.

docker-compose.yaml



services:
  postgres-db:
    image: postgres:latest
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_DB=database
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD=1234
    volumes:
      - postgres_data:/var/lib/postgresql/data

  spring-app:
    build:
      context: "./backend"
      dockerfile: Dockerfile
    ports:
      - "8080:8080"
    environment:
      - SPRING_DATASOURCE_URL=jdbc:postgresql://postgres-db:5432/database
      - CORS_ALLOWED_ORIGINS=http://localhost:9090,http://react-app:9090
    depends_on:
      - postgres-db

  react-app:
    build:
      context: ./frontend
      dockerfile: Dockerfile
      args:
        - VITE_GET_MESSAGES_URL=http://localhost:8080/allmessages
        - VITE_POST_MESSAGES_URL=http://localhost:8080/sendmessage
        - VITE_DELETE_MESSAGES_URL=http://localhost:8080/deletemessage
    ports:
      - "9090:9090"
    depends_on:
      - spring-app

volumes:
  postgres_data:  


Enter fullscreen mode Exit fullscreen mode

For this we create a PostgreSQL database inside the container and our backend is going to send the messages, that come from our frontend to him.

After this we can run the command, to start all of our containers



docker compose up -d 


Enter fullscreen mode Exit fullscreen mode

If everything is fine, you can open your frontend on your browser at the url http://localhost:9090 and writing your messages.


Setting up the Neon database

Make the login at the Neon.

Select the free plan.

Set a name and a region for your database

Select the java url for your database, copy this url and save, because we are going to pass this as a environment variable:

Save this database url

Now, your Neon database is ready to be connected with your backend.


Deploy on render

Login on Render.

Go to your dashboard and select Deploy a Web Service

Paste the public git repository of your project here:

Paste your public git repository url here

Front end deploy

After you connect the repository with render. Scroll down the page a little bit.

Another configurations
  • Language: Docker
  • Branch: I'm using master, if yours are main feel free to change.
  • Root directory: We are building frontend, then the root directory is ./frontend

Scroll down and set the environment variables.

You can see in the docker compose file that we are going to use three environment variables:

  • VITE_GET_MESSAGES_URL=""
  • VITE_POST_MESSAGES_URL=""
  • VITE_DELETE_MESSAGES_URL=""

But the values, for now, will remain empty. Because we need the url from our backend.
We'll come back later and set these variables to the correct value.

Environment variables with empty values

You can deploy your app now, but remember, you can't send or read messages, for now.

Remember to save the url of the front end to pass to our backend.

Save this url to pass to our backend

Back end deploy

Go to your dashboard and select Deploy a Web Service

Paste the public git repository of your project here:

Paste your public git repository url here

After you connect the repository with render. Scroll down the page a little bit.

Configurations of backend
  • Language: Docker
  • Branch: I'm using master, if yours are main feel free to change.
  • Root directory: We are building frontend, then the root directory is ./backend

Scroll down and set the environment variables.

You can see in the docker compose file that we are going to use two environment variables:

Backend environment variables

Deploy your app.

Save the url of your backend.


Fix the front end variables

Now, we are going to set the values of our front end variables:

Save, rebuild and deploy your frontend app.


Conclusion

That's it you build the front-end, back-end of an application and connected to a database.

You can increment this project whatever you like.

Thanks for reading !


📍 Reference

💻 Project Repository

👋 Talk to me

Top comments (0)