Install a Theme programatically

If you want to install themes via your app.yml, use the following format:

run:
  - exec: echo "Beginning of custom commands"

  - file:
      path: /tmp/mythemes.yml
      contents: |
        discourse-gifs:
          url: https://github.com/discourse/discourse-gifs.git
          add_to_all_themes: true

  - exec:
      cd: $home
      cmd: su discourse -c 'bundle exec rake themes:install < /tmp/mythemes.yml'

  - exec: echo "End of custom commands"

YAML format options

The YAML file supports a short format (URL only) and a long format with additional options:

# Short format - just the URL
theme_name: https://github.com/example/theme.git

# Long format - with options
theme_name:
  url: https://github.com/example/theme_name.git
  branch: "main"
  private_key: ""
  default: false
  add_to_all_themes: false
  skip_update: false
Option Description
url (required) The git repository URL
branch Git branch to use (defaults to the repo’s default branch)
private_key SSH private key for private repositories
default Set as the default theme (boolean)
add_to_all_themes For components only — install on every theme (boolean)
skip_update Skip updating if the theme is already installed (boolean)

Installing from an archive

You can also install a theme from a local .zip or .tar.gz archive:

THEME_ARCHIVE=/path/to/theme.zip bundle exec rake themes:install:archive

Set UPDATE_COMPONENTS=0 to skip updating included components.

Last edited by @JammyDodger 2024-05-25T11:03:53Z

Check documentPerform check on document:
12 Likes

Oh I’m so glad this is possible…I was trying to find a way to load themes across a multisite instance and this may be the easiest way. Thank you!

2 Likes

If anyone else is looking for a programmatical way to import a Theme from the local device with a zip file:

export THEME_ARCHIVE=<abolute-path-to-file> 
bundle exec rake themes:install:archive

or

THEME_ARCHIVE=<abolute-path-to-file> bundle exec rake themes:install:archive

is your friend.

6 Likes

(also works with tar.gz)

2 Likes