How to upload static files when deploying a go app?


I’m a newbie to Fly. I managed to deploy a toy go app by following the tutorial. But my real app needs to access some static files. Say I have a directory named ‘templates’ that has files the go app needs to read. When I try to deploy the app, the templates directory is not ‘uploaded’ so deployment always fails. Is there a way to “push” the local files upstream? I know I can do it with go embed but I just want to know if there are other ways.

Hey, yeah, so one way to serve static assets is to use the [[statics]] section in fly.toml. Something like

guest_path = "/app/dist"
url_prefix = "/static"

When you deploy, fly will pull the directory /app/dist from your app and serve requests like https://<app>/static from the cache on the edge servers. Outdated static urls are kept around so users won’t ever get a blank page too. Reference docs here → App Configuration (fly.toml) · Fly Docs

Apart from what shortdiv said, make sure the dockerfile is including the files you need in its final image layer. Look at .dockerignore to see if any interesting dirs are being excluded. Also, check the COPY and ADD directives, if those are including in the image the files and dirs you need.