Logo

dev-resources.site

for different kinds of informations.

Deploying Julia Genie on Heroku

Published at
3/23/2023
Categories
julialang
genie
heroku
Author
jdwright
Categories
3 categories in total
julialang
open
genie
open
heroku
open
Author
8 person written this
jdwright
open
Deploying Julia Genie on Heroku

The tutorials for Genie, a web framework in the Julia language, are pretty good, but there were some holes that I wanted to fill in. In particular, I want to show as directly as possible how to get a Genie app running on Heroku. I'll assume some knowledge of Heroku. There's an official tutorial here:

https://genieframework.com/docs/genie/v5.11/tutorials/Deploying-With-Heroku-Buildpacks.html

My recommendation is that you follow most of it, but without using the sample app that's mentioned, as it doesn't work as is. Instead, use Genie to create a template as shown in these tutorials:

https://genieframework.com/docs/genie/v5.11/tutorials/Developing-Web-Services.html

https://genieframework.com/docs/genie/v5.11/tutorials/Developing-MVC-Web-Apps.html

For example:

julia> using Genie
julia> Genie.Generator.newapp_fullstack("GenieDemo5")
Enter fullscreen mode Exit fullscreen mode

You'll be prompted for a choice of db, and you should use postgres if you're going to deploy to Heroku, so I chose

3. PostgreSQL

This creates a Genie app in a new directory GenieDemo5, and also starts the web server. If you're already running postgres, this should work, but since I'm not, the server crashed. I normally run postgres via docker, so you could, for example, add a docker-compose.yml file to the app that looks like this:

version: '3'
services:
  database:
    image: postgres
    ports:
      - 5434:5432
    env_file:
      - .env.dev
    volumes:
      - db_data:/var/lib/postgresql/data
volumes:
  db_data:
Enter fullscreen mode Exit fullscreen mode

and a .env.dev file that looks like this:

POSTGRES_USER=postgres
POSTGRES_PASSWORD=long-password-for-genie-demo5
POSTGRES_DB=geniedemo5
Enter fullscreen mode Exit fullscreen mode

The details here aren't important. For example, I wanted to map the postgres port from 5432 in the container to 5434 on my machine to avoid conflicts. So if you have something like the above,

docker-compose up -d

will start your database in the background. Then you have to set the parameters in db/connection.yml to match your configuration, so for example:

env: ENV["GENIE_ENV"]

dev:
  adapter:  PostgreSQL
  host:     127.0.0.1
  port:     5434
  database: geniedemo5
  username: postgres
  password: long-password-for-genie-demo5
Enter fullscreen mode Exit fullscreen mode

If you've handled the db set up, then your app should start locally.
The tutorials don't tell you how to start the server other than creating a new app, but you can do it as follows:

bin/server

Browsing to

http://127.0.0.1:8000

will show the Genie welcome page. Now, we can deploy just this much to Heroku. Following the tutorial, create an app with the suggested Julia buildpack, for example:

heroku create geniedemo5 --buildpack https://github.com/Optomatica/heroku-buildpack-julia.git

This creates the Heroku app, and outputs the app url and the git url. If you've already created a git repo, it makes the remote for you as well, but if not, you can use the given url like this:

git init
git remote add heroku https://git.heroku.com/geniedemo5.git
Enter fullscreen mode Exit fullscreen mode

You also need a Procfile that looks like this:

web: bin/server
Enter fullscreen mode Exit fullscreen mode

If you commit, push to Heroku, and watch the logs, you'll see the app build and start, but then crash. Because we're using an app with different environments set up, you need to do

heroku config:set GENIE_ENV=prod

That's enough to get the welcome page working. Of course, you'd still need to set up the db on Heroku. Also note that I got memory warnings until I started using a 2x dyno. I'm not currently running this app since I didn't want to pay for a demo, but the code as described here is on github:

https://github.com/jdwright/GenieDemo5

julialang Article's
30 articles in total
Favicon
Here’s why Julia is THE language in scientific programming
Favicon
Stressify.jl Performance Testing
Favicon
What I learned in Quantum Computing this year (as a Junior Engineer)
Favicon
A Comprehensive Guide to Training a Simple Linear Regression Model in Julia
Favicon
Some Types - Part 2
Favicon
JuliaLang: Performance Prowess or Just Smoke and Mirrors? Unveiling the Real Story
Favicon
Some Types - Part 1
Favicon
Let's Implement Overloading/Multiple-Dispatch
Favicon
5 Lesser-Known Programming Languages That Are Easy to Learn and Highly Effective
Favicon
The programming languages I learned in my Quantum Computing job
Favicon
Transitioning from Lunr.js to Minisearch.js
Favicon
Where It All Starts and Ends
Favicon
Relax, Code, Repeat
Favicon
Julia : “The Harmonious Symphony of Programming”
Favicon
Julia: “The Uncelebrated Maestro of Algorithm Harmony”
Favicon
Weeks 3 and 4 of GSoC Journey: Steps towards Crafting An Enhanced Search Experience
Favicon
Julia: Is It the Final Answer to Programming's Grand Challenges?
Favicon
Two Weeks of Coding
Favicon
Conditionals in Julia
Favicon
Advancing AlgebraicJulia
Favicon
Cracking GSoC for Julia
Favicon
We are inundated with programming languages.
Favicon
Setting Up A Julia Development Environment
Favicon
Julia Plotting Cheat Sheet
Favicon
Manifest.toml vs Project.toml in Julia
Favicon
IJulia: The Julia Notebook
Favicon
Deploying Julia Genie on Heroku
Favicon
Structs in Julia
Favicon
Deep Learning with Julia – How to Build and Train a Model using a Neural Network
Favicon
Machine learning with Julia – How to Build and Deploy a Trained AI Model as a Web Service

Featured ones: