🚀 Feature: Embed static assets into binary rather than expecting they exist #422

Closed
opened 2025-10-07 00:14:27 +03:00 by OVERLORD · 2 comments
Owner

Originally created by @j-baker on GitHub.

Feature description

At present, the backend binary assumes that various resources are available at predetermined paths with respect to the working directory. For example, migrations are expected to be found at migrations/, images at images/.

It would be convenient if pocket-id used go-embed or similar to bundle all relevant data directly into the binary. An alternative would be to store the assets relative to the binary instead and reference them relative to the binary path and not the working directory, ideally using an FHS style path scheme (e.g. bin/pocket-id-backend, share/migrations, etc).

Pitch

Thanks for writing this service - really like the minimal implementation. I run pocket-id on nixos as a systemd service. I build and package pocketid such that I have a directory scheme which looks like:

derivation-path/ (read only)
    bin/pocket-id-backend
    var/migrations/{migrations, email-templates, images}.

I then run the backend in the directory /var/lib/pocket-id, so I have a working directory that is stable across upgrades. Unfortunately, this errors because the three listed directories are not present. In order for this to work, I have to rsync -a $(dirname $(which pocket-id-backend)/../var/ ./ to ensure that the static assets are copied across.

I would like instead to have a clear separation of 'assets that come with the binary' which can be stored in or alongside the binary, and 'assets provided by the user' which can be stored in the working directory.

Originally created by @j-baker on GitHub. ### Feature description At present, the backend binary assumes that various resources are available at predetermined paths with respect to the working directory. For example, migrations are expected to be found at `migrations/`, images at `images/`. It would be convenient if pocket-id used [go-embed](https://pkg.go.dev/embed) or similar to bundle all relevant data directly into the binary. An alternative would be to store the assets relative to the binary instead and reference them relative to the binary path and not the working directory, ideally using an FHS style path scheme (e.g. `bin/pocket-id-backend`, `share/migrations`, etc). ### Pitch Thanks for writing this service - really like the minimal implementation. I run pocket-id on nixos as a systemd service. I build and package pocketid such that I have a directory scheme which looks like: ``` derivation-path/ (read only) bin/pocket-id-backend var/migrations/{migrations, email-templates, images}. ``` I then run the backend in the directory `/var/lib/pocket-id`, so I have a working directory that is stable across upgrades. Unfortunately, this errors because the three listed directories are not present. In order for this to work, I have to `rsync -a $(dirname $(which pocket-id-backend)/../var/ ./` to ensure that the static assets are copied across. I would like instead to have a clear separation of 'assets that come with the binary' which can be stored in or alongside the binary, and 'assets provided by the user' which can be stored in the working directory.
OVERLORD added the feature label 2025-10-07 00:14:27 +03:00
Author
Owner

@stonith404 commented on GitHub:

Released in v0.23.0.

@stonith404 commented on GitHub: Released in `v0.23.0`.
Author
Owner

@stonith404 commented on GitHub:

Thank you for the suggestion! This is my first larger Go project, and I wasn’t aware that resources could be embedded directly into the binary. I’ve updated the code on the main branch to include the static assets from backend/resources as part of the binary.

Let me know if there are more changes needed.

@stonith404 commented on GitHub: Thank you for the suggestion! This is my first larger Go project, and I wasn’t aware that resources could be embedded directly into the binary. I’ve updated the code on the main branch to include the static assets from `backend/resources` as part of the binary. Let me know if there are more changes needed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pocket-id#422