rodydavis / pocketbase-cloudrun

Run PocketBase on CloudRun with mounted volumes via Google Cloud Storage
Apache License 2.0
26 stars 12 forks source link

pb_public, pb_hooks, and pb_migrations not copying to cloud storage #1

Open tewshi opened 2 months ago

tewshi commented 2 months ago

After applying the changes as suggested, I deployed successfully, but noticed that the pb_hooks, pb_public and pb_migrations directories are not saved on cloud storage.

The pb_data directory copies, which I believe it does so because it is generated at run time and not at build time.

when I run the docker build locally, I can see the /cloud/storage folder in the files of the image (which is expected since I'm not mounting any cloud directory in my local machine), but I expect this /cloud/storage to be mapped (at docker build time) to the actual mounted directory pointing to Google cloud storage

rodydavis commented 2 months ago

That is correct!

https://github.com/rodydavis/pocketbase-cloudrun/blob/main/Dockerfile#L27

You need to upload the files for pb_public and pb_hooks directly to cloud storage in the same location beside pb_data. It is already mapped but pb_data is created the first time it is run

tewshi commented 2 months ago

wish there's a way to handle this, wanted to. use gcloud storage cp but that will require authentication in the docker image... also tried docker --mount option, mount only works when running the image, not when building.

there has to be an easier way to get it done...

rodydavis commented 2 months ago

Well as per the command you can customize the paths.

If you want them to be local to the container, just modify the Dockerfile to change where they point to.

Then you would just copy the files in on docker build.

tewshi commented 2 months ago

after doing some findings, I was able to automate it.

moved the copy command to use the cloud build config, while cloud run is running, copy the files to storage

cloudbuild.yaml

steps:
  - name: 'gcr.io/cloud-builders/gsutil'
    args: ['-m', 'cp', '-r', 'migrations/', 'gs://${_CLOUD_BUCKET}/']

then the docker build step followed, I've also been able to use this flow to generate and copy frontend files

@rodydavis

rodydavis commented 2 months ago

Woah that is awesome!!

Could you make a PR with the changes?

tewshi commented 2 months ago

Okay, I'll do it, give me some time.

rodydavis commented 2 months ago

Not a problem! Really appreciate it 🚀