Questions about Shopify deployment

I encountered a problem when deploying shopify Embedded development. shopifycli contained database.sqlite and lost data when the server automatically restarted. How to solve this problem. I tried using Volume, but it didn’t work.

Thank you very much in advance for your help.

Can you share your fly.toml? Putting the sqlite database in a volume will keep the data intact even with a restart.

First of all, thank you very much for your reply. I wrote the code in the fly.toml file:

[mounts]

source=“myapp_data”

destination=“/data”

And where are you storing your sqlite database?

image
这是我的sqlite database路径

Is that ./data/database.sqlite, relative to your current directory? If so, make sure the path starts with a / and not a . , like /data/database.sqlite.

Can you share your Dockerfile and the code that opens the database as well?

路径
该图片是我的dockerfile文件,读取数据库的代码如下:
const database = new sqlite3.Database(join(process.cwd(), “data/database.sqlite”));
这是我第一次用docker和fly.io,所以有很多东西都不太会。
再一次感谢你的帮助。

process.cwd() returns /app when you run it in fly.io, so your data is actually being stored at /app/data/database.sqlite

Instead, your code should look something like this:

let databasePath;
if (process.env.NODE_ENV === 'production')
  databasePath = '/data/database.sqlite';
else
  databasePath = join(process.cwd(), 'data/database.sqlite');

const database = new sqlite3.Database(databasePath);

and make sure you set NODE_ENV=production in your Dockerfile:

ENV NODE_ENV=production
RUN npm install
RUN cd frontend && npm install && npm run build
CMD ["npm", "run", "serve"]

非常感谢您的帮助,我改一下我的代码试一下,再次非常感谢

很抱歉再次打扰您,首先非常感谢在您的帮助下,数据已经可以永久存储了。但是我还有几点疑惑:
1、在我修改代码再次执行flyctl deploy的时候,我是否需要把fly.toml中的
[mounts]
source=“myapp_data”
destination=“/data”
代码删除掉。如果不删除是否会将Volume中的数据覆盖掉。
2、在Volume中的sqlite database我可以通过什么方式下载到我本地。
再一次非常感谢您的帮助!

You need to keep this in your fly.toml:

[mounts]
source="myapp_data"
destination="/data"

You can download your sqlite database from the app by using:

fly sftp get /data/database.sqlite

非常高兴收到您的回复!
很抱歉因为时差,我现在才回复您的消息。
我先试一下您说的方式,如果有其他问题可能还要打扰您。
再次非常感谢您的帮助!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.