Skip to content

Commit

Permalink
refactor states for doil apply command
Browse files Browse the repository at this point in the history
  • Loading branch information
daniwe4 committed Mar 23, 2023
1 parent 972f375 commit 7d3df11
Show file tree
Hide file tree
Showing 19 changed files with 108 additions and 38 deletions.
33 changes: 19 additions & 14 deletions app/src/Commands/Instances/ApplyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ class ApplyCommand extends Command
{
protected const PATH_STATES = "/usr/local/share/doil/stack/states";

protected static array $non_user_states = [
"autoinstall",
"base",
"composer",
"composer2",
"composer54",
"dev",
"ilias",
"mailservices",
"proxyservices",
"reactor",
"change-roundcube-password",
"nodejs"
];

protected static $defaultName = "instances:apply";
protected static $defaultDescription =
"Apply state for the given instance. This is useful for re-applying singular state to your instance.";
Expand Down Expand Up @@ -62,12 +77,7 @@ public function execute(InputInterface $input, OutputInterface $output) : int
throw new InvalidArgumentException("Not enough arguments (missing: \"instance\" or \"all\")");
}

if (
$state == "mailservices" ||
$state == "proxyservices" ||
$state == "reactor" ||
$state == "change-roundcube-password"
) {
if (in_array($state, self::$non_user_states)) {
$this->writer->error(
$output,
"State '$state' is not allowed!",
Expand Down Expand Up @@ -96,17 +106,12 @@ public function execute(InputInterface $input, OutputInterface $output) : int
if (is_null($state)) {
$states = $this->filesystem->getFilesInPath(self::PATH_STATES);

$states = array_filter($states, function ($s) {
if (
$s == "mailservices" ||
$s == "proxyservices" ||
$s == "reactor" ||
$s == "change-roundcube-password"
) {
$states = array_values(array_filter($states, function ($s) {
if (in_array($s, self::$non_user_states)) {
return false;
}
return true;
});
}));

$helper = $this->getHelper("question");
$question = new ChoiceQuestion(
Expand Down
16 changes: 13 additions & 3 deletions app/src/Commands/Instances/CreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ public function execute(InputInterface $input, OutputInterface $output) : int
$this->docker->applyState($instance_salt_name, "base");
$this->writer->endBlock();

// apply apache state
$this->writer->beginBlock($output, "Apply apache state");
$this->docker->applyState($instance_salt_name, "apache");
$this->writer->endBlock();

// apply dev state
$this->writer->beginBlock($output, "Apply dev state");
$this->docker->applyState($instance_salt_name, "dev");
Expand Down Expand Up @@ -360,9 +365,14 @@ public function execute(InputInterface $input, OutputInterface $output) : int
$this->docker->applyState($instance_salt_name, "access");
$this->writer->endBlock();

// apply access state
$this->writer->beginBlock($output, "Apply ilias-postinstall state");
$this->docker->applyState($instance_salt_name, "ilias-postinstall");
// apply enable-whoops-devmode state
$this->writer->beginBlock($output, "Apply enable-whoops-devmode state");
$this->docker->applyState($instance_salt_name, "enable-whoops-devmode");
$this->writer->endBlock();

// apply compile-skins state
$this->writer->beginBlock($output, "Apply compile-skins state");
$this->docker->applyState($instance_salt_name, "compile-skins");
$this->writer->endBlock();

// finalizing docker image
Expand Down
14 changes: 10 additions & 4 deletions setup/stack/config/master.cnf
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,10 @@ file_roots:
- /srv/salt/states/disable-xdebug
enable-xdebug:
- /srv/salt/states/enable-xdebug
disable-whoops-devmode:
- /srv/salt/states/disable-whoops-devmode
enable-whoops-devmode:
- /srv/salt/states/enable-whoops-devmode
php7.2:
- /srv/salt/states/php7.2
php7.3:
Expand All @@ -672,16 +676,16 @@ file_roots:
- /srv/salt/states/php8.2
ilias:
- /srv/salt/states/ilias
ilias-postinstall:
- /srv/salt/states/ilias-postinstall
compile-skins:
- /srv/salt/states/compile-skins
composer:
- /srv/salt/states/composer
composer2:
- /srv/salt/states/composer2
composer54:
- /srv/salt/states/composer54
composerupdate:
- /srv/salt/states/composerupdate
composer-install:
- /srv/salt/states/composer-install
autoinstall:
- /srv/salt/states/autoinstall
access:
Expand All @@ -692,6 +696,8 @@ file_roots:
- /srv/salt/states/proxyservices
nodejs:
- /srv/salt/states/nodejs
apache:
- /srv/salt/states/apache


# The master_roots setting configures a master-only copy of the file_roots dictionary,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,17 @@ apache_supervisor_signal:
supervisord.running:
- name: apache2
- restart: True
- user: root
- watch:
- file: /etc/supervisor/conf.d/apache2.conf
- file: /etc/apache2/sites-enabled/000-default.conf

restart_apache:
cmd.run:
- name: supervisorctl restart apache2
- watch:
- apache_supervisor_signal

apache_grain:
grains.present:
- value: True
Expand Down
3 changes: 3 additions & 0 deletions setup/stack/states/apache/top.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
apache:
'*':
- apache
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ compile_skins:
cmd.run:
- name: /var/www/html/CI/tools/compile-skins.sh
- cwd: /var/www/html
- runas: root
{%- endif %}
3 changes: 3 additions & 0 deletions setup/stack/states/compile-skins/top.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
compile-skins:
'*':
- compileskins
5 changes: 5 additions & 0 deletions setup/stack/states/composer-install/composer-install/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ilias-composer-install:
cmd.run:
- name: composer install
- cwd: /var/www/html
- runas: root
3 changes: 3 additions & 0 deletions setup/stack/states/composer-install/top.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
composer-install:
'*':
- composer-install
4 changes: 0 additions & 4 deletions setup/stack/states/composerupdate/composerupdate/init.sls

This file was deleted.

3 changes: 0 additions & 3 deletions setup/stack/states/composerupdate/top.sls

This file was deleted.

3 changes: 3 additions & 0 deletions setup/stack/states/disable-whoops-devmode/top.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
disable-whoops-devmode:
'*':
- whoops-devmode
11 changes: 11 additions & 0 deletions setup/stack/states/disable-whoops-devmode/whoops-devmode/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
remove_use_whoops:
file.line:
- name: /var/www/html/data/ilias/client.ini.php
- match: '^USE_WHOOPS'
- mode: delete

remove_devmode:
file.line:
- name: /var/www/html/data/ilias/client.ini.php
- match: '^DEVMODE'
- mode: delete
3 changes: 3 additions & 0 deletions setup/stack/states/enable-whoops-devmode/top.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
enable-whoops-devmode:
'*':
- whoops-devmode
27 changes: 27 additions & 0 deletions setup/stack/states/enable-whoops-devmode/whoops-devmode/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
remove_use_whoops:
file.line:
- name: /var/www/html/data/ilias/client.ini.php
- match: '^USE_WHOOPS'
- mode: delete

add_use_whoops:
file.line:
- name: /var/www/html/data/ilias/client.ini.php
- after: '^\[system\]'
- before: '^ROOT_FOLDER_ID'
- mode: insert
- content: 'USE_WHOOPS = "1"'

remove_devmode:
file.line:
- name: /var/www/html/data/ilias/client.ini.php
- match: '^DEVMODE'
- mode: delete

add_devmode:
file.line:
- name: /var/www/html/data/ilias/client.ini.php
- after: '^\[system\]'
- before: '^ROOT_FOLDER_ID'
- mode: insert
- content: 'DEVMODE = "1"'
6 changes: 0 additions & 6 deletions setup/stack/states/ilias-postinstall/devmode/init.sls

This file was deleted.

4 changes: 0 additions & 4 deletions setup/stack/states/ilias-postinstall/top.sls

This file was deleted.

0 comments on commit 7d3df11

Please sign in to comment.