Background
My app was built specifically for Deno Deploy so it’s tightly coupled with Deno KV. Also, there are JSON files that are constantly modified on the local to provide another set of data. Before Deno Deploy Classic was closed, all I need was to update those JSON files locally, git push --force the whole project to GitHub and the data from JSON would be updated, while the data from the KV was unchanged. I didn’t have to care about Docker and database, and didn’t think I would need to understand them.
Now Deno Deploy requires me to update the app to Deno 2, which looks not trivial to me, as my app depends on some old packages. As I intend to rewrite it in a different language anyway, I want to keep the app as is, with little modification as possible. However I’m willing to learn new DevOp knowledge.
Problem
Is it possible to achieve that workflow in Fly? It seems to me that I have to launch the app and the database separately. Is it possible to launch both as one, especially when git push --force is an easy way for me to update the JSON files. I think with doing the volume right this can be done, as Deno KV is just an sqlite3 file. But I’m not sure how to config the fly.toml file.
Currently here is how I setup:
dockerfile
FROM denoland/deno:1.46.3 AS builder
RUN apt-get update && apt-get install -y procps && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY deno.json ./
COPY . .
EXPOSE 8000
CMD ["deno", "task", "start"]
docker-compose.yaml
services:
main:
build: .
ports:
- "8000:8000"
volumes:
- ./Cấu hình và dữ liệu:/app/Cấu hình và dữ liệu
environment:
- DENO_DIR=/app/.deno_dir
restart: unless-stopped
volumes:
deno_kv:
driver: local
fly.toml
app = "doi-thoai"
build = { }
primary_region = "sin"
[env]
CORS_API = "https://doi-thoai.fly.dev"
DATABASE_URL = "https://denokv-test.fly.dev"
DENO_KV_ACCESS_TOKEN = "xxxxxxxxxxx"
ORIGIN = "http://doi-thoai.fly.dev"
[http_service]
auto_start_machines = true
auto_stop_machines = true
force_https = true
internal_port = 8_000
min_machines_running = 0
processes = [ "app" ]
[[vm]]
cpu_kind = "shared"
cpus = 1
memory = "1gb"
memory_mb = 1_024
When I run the container on my local, it looks working. But on Fly the app only shows up the UI but no data. The log says:
Machines are not listening on
0.0.0.0:8000so our proxy is having a hard time finding a candidate to route requests to. This is an issue with your application code.
- Your app could be missing environment variables. Some frameworks require specific environment variables to be set otherwise they stop your app.
- The app could be listening to the wrong port, you can either change your fly.toml
internal_portor modify your application code to listen on the correct port.- Make sure your app is listening to
0.0.0.0and notlocalhostor127.0.0.1.- Your app could not be listening at all, check your logs to make sure it’s running correctly.
Checking the browser console it says:
Loading module from “https://doi-thoai.fly.dev/_frsh/js/5515824eaf1af6b89dfc73010a29137508b5de18/chunk-2EHLMYDL.js” was blocked because of a disallowed MIME type (“text/html”).
It also looks like that the deps are only downloaded on the first load, making it’s super slow.
I’m not sure how to fix this. In theory, even when the database is failed, the JSON data should still work, as it is a part of the code.
