# Import site theme via console

**URL:** https://meta.discourse.org/t/import-site-theme-via-console/66586
**Category:** Support
**Created:** [July 21, 2017, 10:03am UTC](https://meta.discourse.org/t/import-site-theme-via-console/66586 "2017-07-21T10:03:14Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![meldsza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/meldsza/32/120840_2.png) [@meldsza](https://meta.discourse.org/u/meldsza)
#### Post date: [July 21, 2017, 10:03am UTC](https://meta.discourse.org/t/import-site-theme-via-console/66586/1 "2017-07-21T10:03:14Z")

</div>

I am looking for a way to import my site theme (.dcstyle.json file) via the command line so that the configuration can be applied automatically when we run docker.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 21, 2017, 1:58pm UTC](https://meta.discourse.org/t/import-site-theme-via-console/66586/2 "2017-07-21T13:58:25Z")

</div>

The theme is stored in the site backup file, so there is no need to do this unless your intent is to be able to create a brand new Discourse with that theme. And if that’s the case, it’s probably easier to just restore a particular backup on those new sites.

You can restore from a backup like this:

```plaintext
cd /var/discourse
./launcher enter app
rails c
SiteSetting.allow_restore=true
exit
discourse restore BACKUPFILENAME

```

---

<div class="post-metadata">

### Author: ![meldsza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/meldsza/32/120840_2.png) [@meldsza](https://meta.discourse.org/u/meldsza)
#### Post date: [July 22, 2017, 5:14am UTC](https://meta.discourse.org/t/import-site-theme-via-console/66586/3 "2017-07-22T05:14:42Z")

</div>

The problem with this approach is that all the posts and users get transferred as well which is what I don’t want  
The thing is that we made a test production environment to import our 65k users and 80k posts to discourse. We were using a custom forum and so we had to make our own importer. We got frustrated with the import process taking more than a week, so we decided to limit the number of users to those who have actually had some forum data and manage the rest using SSO.  
Now that the script was ready we need to deploy it.  
We effectively manage our servers using puppet so I made a puppet script to install discourse. All I need is to automatically set it up  
I want to import afresh and so I need to import the theme separately  
Therefore I want to include a Ruby script to be run after install. The script currently adds the SSO config and stuff but the theme needs to be done via the website  
I wanted to import theme in the same script

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 22, 2017, 1:01pm UTC](https://meta.discourse.org/t/import-site-theme-via-console/66586/4 "2017-07-22T13:01:46Z")

</div>

Hmm. Surprising that 80k posts would take a week. I’d think much less than a day. Did you base your script on one of the existing ones?

What I generally do in situations as I understand yours, is to do those changes before running the importer. It seems like we’ve already spent more time on this than a it’ll save, but the I’m no stranger to desiring such solutions.

---

<div class="post-metadata">

### Author: ![michaeld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michaeld/32/1594_2.png) [@michaeld](https://meta.discourse.org/u/michaeld)
#### Post date: [July 22, 2017, 7:14pm UTC](https://meta.discourse.org/t/import-site-theme-via-console/66586/5 "2017-07-22T19:14:23Z")

</div>

I think we’re drifting away a bit from the original question…

```
filename = '/tmp/theme.dcstyle.json'
File.open(filename) do |file|
  json = JSON::parse(file.read)
  theme = json['theme']
  puts theme
  t = Theme.new(name: theme["name"], user_id: -1)
  theme["theme_fields"]&.each do |field|
     t.set_field(target: field["target"], name: field["name"], value: field["value"])
  end
  t.save
end

```

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [July 6, 2019, 9:47pm UTC](https://meta.discourse.org/t/import-site-theme-via-console/66586/6 "2019-07-06T21:47:52Z")

</div>



---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [July 8, 2019, 9:44am UTC](https://meta.discourse.org/t/import-site-theme-via-console/66586/7 "2019-07-08T09:44:26Z")

</div>

You might want to have a look at the Discourse Theme CLI 😉

> [@Install the Discourse Theme CLI console app to help you build themes](https://meta.discourse.org/t/discourse-theme-cli-console-app-to-help-you-build-themes/82950):
>
> The [[discourse] Discourse Theme CLI](https://github.com/discourse/discourse_theme) is a ruby gem that allows you to use your editor of choice when developing Discourse themes and theme components. As you save files the CLI will update the remote theme or component and changes to it will appear live! Installing To play with it, make sure you have Ruby 2.5 or up installed. If you are on Windows, you have 2 options: Option 1: [Windows Subsystem for Linux](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux). Windows 10 has access to a full Linux environment, you can use it to install …

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [July 8, 2019, 9:44am UTC](https://meta.discourse.org/t/import-site-theme-via-console/66586/8 "2019-07-08T09:44:27Z")

</div>


