How to deploy local environment to production

Hi everyone,

How is it possible to migrate data and models from my local server to the production server ?

It’s been few days I’m looking everywhere to find a proper procedure for a production deployment…

I already tried the following :

  • Dump configuration using strapi config:dump > dump.json
  • Dump local sqlite DB
  • Create new Strapi app using strapi new my-project command on the production server
  • Launch strapi develop, then close it
  • Restore configuration from previous dump using strapi config:restore < dump.json command (also tried with the -s replace, merge, keep...
  • Replace SQLite DB with local dump
  • Reset admin password
  • Log in again through the admin UI

Also tried :

  • Copy / paste the entire project — FAIL

I’ve been able to log in after all those steps but none of the models that should have been imported are listed in the admin UI; I realized while fetching the folders that in the api folder, there was no model folder… I might be thinking wrong here, but does the config:restore command does replicate the models also ? Do I have to recreate them myself ?

I’m using Strapi for a professional project, if I can’t find a way through then I might be using somehing else… what a shame cause I really like the way it feels using Strapi.

Thanks in advance,

System Information
  • Strapi Version: 3.3.2
  • Operating System: Linux
  • Database: SQLite
  • Node Version: 12.19.0
  • NPM Version: 6.14.8
  • Yarn Version: 1.22.5

Hi,

New to Strapi myself but what I’ve been doing is committing the dev new-project, ignoring node_modules etc like in any other node project, and using that to deploy to the live environment.

Actual data haven’t I ever tried as I’ve only got dev data on my local server. What I do miss is roles which would be nice to have setup in the repo so that it’s easy to restore if needed.

1 Like

Hello,

You should use git for this and not create a new project. Because all the main code is stored in api folder on your local env. You actually just created a Blank project on the production and imported configs from local, but without the most important files.

No, config:restore has nothing to do with the actual models. It restores only the core_store table, which contains the configurations of your app. Check here the code for dump and restore to understand whats going on with these two commands.

1 Like

Thanks a lot to both of you for those information, I will commit the files today and see how it goes.

It wasn’t pretty clear what the dump/restore command did but now it is !

I will post a reply once it’s done :slight_smile:

Best regards

1 Like

I will 2nd this, you should be using some kind of source control for the models as their structure is saved to files.

The only thing the core_store table in the DB holds is the “view” within the admin and a few other various settings. Something important to keep in mind is that the core_store does hold your secret keys for 3rd party auth providers, do not commit your dump into source control without encrypting it (or at all).

Eventually we do plan to add some migration tooling for users-permissions role/permissions dump/restore and the same for the Admin RBAC roles/permissions but for now you will need to do manual dumps and restores based on the database you are using.

Data is also the same, manual dump/restore via your database and a client that works with them (mysqldump / psql / mongodump / ect)

2 Likes

Hi everyone,

I’ve been able to replicate my entire project and configuration thanks to your advices. Thanks also @DMehaffy for joining the chat with some great explanation.

At the moment, the project is still light so here’s the procedure I choosed :

  • commit the local project (without database) to a git repository
  • dump configuration from local project config:dump
  • dump my models collections in separated CSV files
  • clone the project on the production server
  • setup from yarn
  • restore configuration config:restore
  • import data from the CSV files into the new project

Then I just had to recreate a admin profile since I didn’t need to import the local one, and everything was working fine !

Hope this would help someone in the future.

Case solved !

4 Likes

Perfect implementation @Romain_Karmann :+1:

1 Like

This idea saved me some time @Romain_Karmann. I ended using pg_dump and pg_restore to move my postgres data from my machine up to starging server.

I do have a question as to the config:dump contents - is this all settings from the admin apart from the data? - roles, permissions checkboxes, view configurations, third party credentials?