Le’s talk about Odoo deployment. It will be easy because we will using container based method. In my content here, I talk about how to running Odoo application on a Docker container. It’s relatively easy to do and can be alternative way to running Odoo application on your local environment. In this post, after you know about how to running it on Docker, I will talk about how to deploy Odoo application to Fly.io .
Prerequisite
To deploy your Odoo application to Fly.io, you need to register and verify your account first in Fly.io official website. You can refer to this link to register. You need to bind your payment account to verify your Fly.io account. After all register process done, you are ready to deploy your application there. If you want to read my content about basic knowledge of Fly.io, you can visit this post. You also need to make sure that your Odoo application is running well on your local environment over Docker container. This is because Fly.io works like Docker, when your application has trouble when running over Docker container, it can be issue or error when you try to deploy it application to Fly.io .
Deploy Odoo application
After you got prerequisites above, you can start to deploy your Odoo application by following this steps:
Setup fly.toml configuration
fly.toml is a configuration file that define how Fly.io will setting up container for your application . Here is the sample of fly.toml based on my case:
# The name of your Fly.io application (must be unique across Fly.io).
app = 'odoo-app'
# Primary region to deploy the app in (sin = Singapore datacenter).
primary_region = 'sin'
[mounts]
# Persistent storage configuration (data survives restarts/redeploys).
# Name of the Fly.io volume to attach.
source = "odoo_data"
# Path inside the container where the volume will be mounted.
# For Odoo, /var/lib/odoo stores the database filestore & attachments.
destination = "/var/lib/odoo"
[http_service]
# Settings for exposing the app over HTTP/HTTPS.
# The internal container port Fly will route traffic to.
internal_port = 8080
# Redirect all HTTP requests to HTTPS.
force_https = true
# Prevent Fly from stopping idle machines automatically.
auto_stop_machines = false
# Automatically start machines when traffic comes in.
auto_start_machines = true
# Ensure at least 1 machine is always running (important for Odoo uptime).
min_machines_running = 1
# The process group this service applies to — usually "app" for the main process.
processes = ['app']
[[vm]]
# Virtual machine hardware configuration.
# Amount of RAM allocated.
memory = '1gb'
# CPU type (shared = cheaper, but performance may vary).
cpu_kind = 'shared'
# Number of virtual CPUs allocated.
cpus = 1
Login fly.io
Authenticate your account using flyctl and choose your verified account
fly auth login
Create container in fly.io for Odoo app
The next step is to creating application container for the Odoo application. I just want to create the container but not deploy my Odoo application automatically because there are some steps that I must be done before deploy the application. I will trigger deployment manually after all the setup is set.
fly launch --name odoo-app --dockerfile Dockerfile --no-deploy
This command will trigger flyctl to setup the container. Follow configuration guidance that appears in your console, it will ask you to setup instance memory, core specification, volume size, etc. Just follow and adjust to your needs.
Create container in fly.io for database
Next, you must create container for your database instance. Odoo use Postgres, and in Fly.io you can easily setting up Postgres database using flyctl. Here the sample:
fly postgres create --name odoo-db --region sin --initial-cluster-size 1 --volume-size 2
In my case above, I want to create database instance in Singapore region (sin) with 1 cluster and 2GB volume. You can adjust this based on your needs.
Attach database to your application
Basically in process above, it creates 2 different container, the first is for Odoo application, and the second is for the database. It needs to attach database to the application manually.
fly postgres attach --app odoo-app
Deploy odoo app
The last step is to trigger deployment manually.
fly deploy
The command above will trigger fyctl to build the image, push to fly.io, and setting up the environment. Wait until the process finish. After finish, you will see url to access your website on your terminal.
Conclusion
Deploy Odoo application to Fly.io is not a hard step. We can use flyctl to set up and deploy it all by command line.