zcuric
(Zdravko)
April 21, 2020, 9:30am
1
Hi,
do you guys have suggestion how to approach theme deployment in CI/CD fashion? Client expects new theme releases every two weeks and we would like to ship theme in automated process. We are using discourse docker.
We would like to avoid manual installation for each release.
Side note, I don’t know if this is a bug, but the it seems branch doesn’t get saved on first theme installation. (Need to double check this to confirm)
Thanks
2 Likes
fzngagan
(Faizaan Gagan)
April 21, 2020, 9:52am
2
Its already there. If you install a theme via a git repo, you can update the theme to the latest commit in a single click.
zcuric
(Zdravko)
April 21, 2020, 10:09am
3
I know that, but that’s not the way we want to do it.
We want to have dynamic process without touching the discourse admin. I was thinking using themes command https://github.com/discourse/discourse/blob/master/lib/tasks/themes.rake
docker exec -it app rails themes:install -- # theme data
I don’t know if this command can read files. For example - theme.yaml file which would contain theme info for instalation.
That file could be deployed to shared folder and docker command could read it from there and install the theme or make updates.
david
(David Taylor)
April 21, 2020, 10:19am
4
8 Likes
zcuric
(Zdravko)
April 21, 2020, 10:24am
5
@david thanks, but it doesn’t seem clear to me if I can put path to file as an argument. Would this work?
bin/rake themes:install -- theme.yaml
Maybe I could try.
david
(David Taylor)
April 21, 2020, 10:29am
6
I think you would pipe it to STDIN, so something like
cat theme_config.yml | bin/rake themes:install
But I haven’t tested that. Let us know if it works for you
6 Likes
zcuric
(Zdravko)
April 21, 2020, 11:21am
7
Your approach works fine. Thanks! Mine doesn’t.
I did experiment a bit with modifying themes.rake
by adding
rake themes:install themeFile="theme.yml"
And this:
task "themes:install" => :environment do |task, args|
if ENV['themeFile']
theme_args = YAML.load_file(ENV['themeFile'])
else
theme_args = (STDIN.tty?) ? '' : STDIN.read
use_json = theme_args == ''
theme_args =
begin
use_json ? JSON.parse(ARGV.last.gsub('--', '')) : YAML::load(theme_args)
rescue
puts use_json ? "Invalid JSON input. \n#{ARGV.last}" : "Invalid YML: \n#{theme_args}"
exit 1
end
end
log, counts = ThemesInstallTask.install(theme_args)
puts log
puts
puts "Results:"
puts " Installed: #{counts[:installed]}"
puts " Updated: #{counts[:updated]}"
puts " Errors: #{counts[:errors]}"
if counts[:errors] > 0
exit 1
end
end
Works fine.
How to run spec for this file?
1 Like
You should be able to do this:
bin/rake themes:install theme.yml
I added support for passing in JSON, but this code was originally designed to take a yml file as the argument.
2 Likes
zcuric
(Zdravko)
April 21, 2020, 12:30pm
9
It throws that it’s not valid json
Invalid JSON input.
theme.yml
My theme.yml
test:
url: "https://github.com/discourse/discourse-faria-theme"
2 Likes
I believe that should work! I will look into why it is not working anymore.
2 Likes
Alright, the proper format is bin/rake themes:install < theme.yml
. I will document this better in the code
15 Likes
zcuric
(Zdravko)
April 21, 2020, 1:14pm
12
Nice! Thanks! Glad I could help a bit
4 Likes