Luigi
Published on

Deploy a Go and Svelte mono repo using Render and Netlify

Let's say you have a web application that you would like to deploy to production for your users to use, how would you do it?

In this article, I'll demonstrate how to deploy a fullstack web application using Render for the Go backend and Netlify for the Svelte frontend.

Here's the link to the code ready for deployment https://github.com/morelmiles/event-tickets

Tech stack

  • Go
  • Gorilla Mux (PS: It's deprecated now)
  • PostgreSQL

Jump ahead

Deploy the Go backend on render.com

First things first, sign up for a free account on render.com - No payment details required

  1. Select web service from the menu

    selecting a service

  2. Connect a repository (you could use Github or Gitlab)

    connect a repository

  3. Fill in the details for you application

    service details

  • Name is how you'd like to identify your service. I used events

  • Region is where you'd want your service to be deployed. Use the one nearest to you.

  • Branch is the Git branch you'd like to deploy (ideally one that has the latest changes)

  • Runtime is your service's tech stack. We are using Go

  • Build command specifies how you'd like to build your application. If you take a look at our repository, you do realize that the main.go file resides in the cmd/app/ directory

    The command

    go build -tags netgo -ldflags '-s -w' -o app cmd/app/main.go

    builds our binary and the resulting binary output is saved as app

  • Build command is us running the Go binary from the Build command step

  • Select a free instance for your service (I'm assuming you did not provide payment details )

  • Then, hit the Create Web Service button at the bottom of your screen

  1. You will then be redirected to the build page. See if you have any errors or your service gets built successfully

For my case, I have an error (It's intentional )

build screen

At this point, ensure that your service is running successfully.

Setting up a database

  1. Create a new database

create a new database

  1. Fill in the details for your dabatase

create a new database

  1. Go to the Environment section of your web service and upload your .env file containing your database details

env setup

Deploy the frontend on Netlify

  1. Select the repository you'd like to deploy

choose a repo netlify

  1. Add details to your deployment

deploy to netlify

Note: Deployment of Svelte to Netlify requires the usage of an adapter. Here's the documentation SvelteKit on Netlify

Conclusion

And, that's it! You've successfully deployed a mono-repo web application.


Let me know what your thoughts are about this article hi[at]luigimorel.com. Cheers!

© 2022 - 2024 Luigi Morel. All rights reserved.