Skip to content

Commit

Permalink
Embed openproject-related packager addons
Browse files Browse the repository at this point in the history
  • Loading branch information
crohr committed May 17, 2021
1 parent f2d8f1d commit 0edc69e
Show file tree
Hide file tree
Showing 13 changed files with 838 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .pkgr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ wizards:
- ./packaging/addons/openproject-edition
- https://github.com/pkgr/addon-postgres
- https://github.com/pkgr/addon-apache2.git
- https://github.com/opf/addon-repositories.git
- ./packaging/addons/repositories
- https://github.com/pkgr/addon-smtp.git
- https://github.com/pkgr/addon-memcached.git
- https://github.com/opf/addon-openproject.git
- ./packaging/addons/openproject
buildpack: https://github.com/opf/heroku-buildpack-multi.git
63 changes: 63 additions & 0 deletions packaging/addons/openproject/bin/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

set -e

. "${INSTALLER_DIR}/wizard"

input_start() {
local server_autoinstall=$(wiz_get "server/autoinstall" || echo "skip")
if [ "$server_autoinstall" = "skip" ] ; then
STATE="input_hostname"
else
STATE="done"
fi
}

input_hostname_params() {
local default_hostname=$(hostname -f 2>/dev/null || hostname || echo "example.com")

if ! wiz_get "server/hostname" &>/dev/null ; then
wiz_set "server/hostname" "$default_hostname"
wiz_unseen "server/hostname"
fi

wiz_put "server/hostname"
if wiz_ask ; then
STATE="input_protocol"
else
STATE="start"
fi
}

input_protocol_params() {
wiz_put "server/ssl"
if wiz_ask ; then
STATE="done"
else
STATE="input_hostname"
fi
}

state_machine() {
case "$1" in
"start")
input_start
;;
"input_hostname")
input_hostname_params
;;
"input_protocol")
input_protocol_params
;;
"done")
echo "DONE"
exit 0
;;
*)
echo "invalid state ${STATE}"
exit 1
;;
esac
}

wizard "start"
108 changes: 108 additions & 0 deletions packaging/addons/openproject/bin/postinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/bin/bash

set -e

. ${INSTALLER_DIR}/wizard

CLI="${APP_NAME}"

# Check for custom gems
custom_gemfile=$(${CLI} config:get CUSTOM_PLUGIN_GEMFILE || echo "")
if [ -n "$custom_gemfile" ] && [ -f "$custom_gemfile" ]; then

# Need to override the frozen setting for the vendored gems
${CLI} run bundle config --local frozen 0

# Re-bundle the application including gems
${CLI} run bundle install

# Mark backend for recompilation in the OpenProject postinstall rake step
echo "Custom Gemfile present. Need to recompile rails assets. Setting RECOMPILE_RAILS_ASSETS=true"
${CLI} config:set RECOMPILE_RAILS_ASSETS="true"
fi

# Check for server prefix
server_prefix=$(${CLI} config:get SERVER_PATH_PREFIX || echo "/")
if [ "$server_prefix" != "/" ]; then
echo "Server prefix is set. Need to recompile rails assets. Setting RECOMPILE_RAILS_ASSETS=true"
# Mark backend for recompilation in the OpenProject postinstall rake step
${CLI} config:set RECOMPILE_RAILS_ASSETS="true"
fi

# Check for server prefix changes
last_server_prefix=$(${CLI} config:get SERVER_PATH_PREFIX_PREVIOUS || echo "/")
if [ "$last_server_prefix" != "$server_prefix" ]; then
echo "Server prefix was changed from ${last_server_prefix} to ${server_prefix}. Need to recompile rails assets. Setting RECOMPILE_RAILS_ASSETS=true"
# Mark backend for recompilation in the OpenProject postinstall rake step
${CLI} config:set RECOMPILE_RAILS_ASSETS="true"
fi


# Check if we need to compile angular as well
must_rebuild=$(${CLI} config:get RECOMPILE_ANGULAR_ASSETS || echo "")
if [ -n "$must_rebuild" ]; then
echo "RECOMPILE_ANGULAR_ASSETS was set. Installing node dependencies..."
# Skip printing audit for installation
openproject run npm set audit false
openproject run npm install --silent
fi

# Set execjs to node since that's installed
# And we can use it for backend precompilation
${CLI} config:set EXECJS_RUNTIME="Node"

rake_commands="db:migrate db:seed"

# set rails_cache_store
memcached_servers="$(${CLI} config:get MEMCACHED_SERVERS || echo "")"
if [ -z "$memcached_servers" ]; then
${CLI} config:set RAILS_CACHE_STORE=file_store
else
${CLI} config:set RAILS_CACHE_STORE=memcache
fi

# create attachments folder
attachments_path=$(${CLI} config:get ATTACHMENTS_STORAGE_PATH || echo "/var/db/${APP_NAME}/files")
mkdir -p "${attachments_path}"
chown ${APP_USER}.${APP_GROUP} "${attachments_path}"
${CLI} config:set ATTACHMENTS_STORAGE_PATH="${attachments_path}"

# set web host
${CLI} config:set HOST=127.0.0.1

# set web timeout
web_timeout=$(${CLI} config:get WEB_TIMEOUT || echo "300")
${CLI} config:set WEB_TIMEOUT=${web_timeout}

# set SECRET_KEY_BASE env variable
secret_token=$(${CLI} config:get SECRET_KEY_BASE || ${CLI} config:get SECRET_TOKEN || ${CLI} run rake -s secret | tail -1)
${CLI} config:set SECRET_KEY_BASE="$secret_token"

# set SECRET_TOKEN env variable for backwards compatibility
${CLI} config:set SECRET_TOKEN="$secret_token"

# set installation type
installation_type="$(${CLI} config:get OPENPROJECT_INSTALLATION__TYPE || echo "")"
if [ -z "$installation_type" ]; then
${CLI} config:set OPENPROJECT_INSTALLATION__TYPE=packager
fi

# Allow other tasks to run before the environment is loaded
${CLI} run rake "packager:before_postinstall"

# Use the OpenProject internal setup in one environment task
${CLI} run rake "${rake_commands} packager:postinstall"

# For some reason RHEL8 creates files with chmod 0600
find "${APP_HOME}/public" -type f -exec chmod 0644 {} \;

# Allow OpenProject to perform custom initialization steps in the context of this installer
if [ -e "${APP_HOME}/packaging/scripts/postinstall" ]; then
source "${APP_HOME}/packaging/scripts/postinstall"
fi

# scale
${CLI} scale web=1 worker=1 || true

# restart
service ${APP_NAME} restart
3 changes: 3 additions & 0 deletions packaging/addons/openproject/bin/preinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

exit 0
15 changes: 15 additions & 0 deletions packaging/addons/openproject/templates
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Template: server/ssl
Type: select
Choices: no, yes
Translations: No, Yes
Default: no
Description: Do you use SSL to access _APP_NAME_
Enabling SSL makes your _APP_NAME_ installation more secure.
.
If you choose YES, the application server will only respond to https. You need to manually configure SSL certificates for your web server.

Template: server/hostname
Type: string
Default: www.example.com
Description: Your fully qualified domain name:
Enter the fully qualified domain name (FQDN), where this server can be reached.
126 changes: 126 additions & 0 deletions packaging/addons/repositories/bin/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/bin/bash

set -e

. "${INSTALLER_DIR}/wizard"

input_start() {
if [ "$(wiz_get "server/autoinstall")" = "skip" ] ; then
echo "No server installed. Skipping."
STATE="done"
else
STATE="params"
fi
}

input_params() {
# API key for OpenProject
local random_key=$(< /dev/urandom tr -dc A-Za-z0-9 | head -c32;echo;)
if ! wiz_get "repositories/api-key" &>/dev/null ; then
wiz_set "repositories/api-key" "${random_key}"
fi

wiz_put "repositories/api-key"

if wiz_ask ; then
STATE="svn_setup"
else
echo "Aborting configuration."
exit 1
fi
}

select_svn_installation() {
wiz_put "repositories/svn-install"
if wiz_ask ; then
RET=$(wiz_get "repositories/svn-install")
if [ "$RET" = "install" ] ; then
STATE="svn_params"
else
STATE="git_setup"
fi
else
STATE="done"
echo "SVN configuration canceled."
exit 1
fi
}

input_svn_params() {
# Access token for Apache wrapper
local random_key=$(< /dev/urandom tr -dc A-Za-z0-9 | head -c32;echo;)
if ! wiz_get "repositories/apache-wrapper-token" &>/dev/null ; then
wiz_set "repositories/apache-wrapper-token" "${random_key}"
fi

wiz_put "repositories/svn-path"
wiz_put "repositories/apache-wrapper-token"

if wiz_ask ; then
STATE="git_setup"
else
echo "Aborting configuration."
exit 1
fi
}

select_git_installation() {
wiz_put "repositories/git-install"
if wiz_ask ; then
RET=$(wiz_get "repositories/git-install")
if [ "$RET" = "install" ] ; then
STATE="git_params"
else
STATE="done"
fi
else
STATE="done"
echo "Git configuration canceled."
exit 1
fi
}

input_git_params() {
wiz_put "repositories/git-path"
wiz_put "repositories/git-http-backend"

if wiz_ask ; then
STATE="done"
else
echo "Aborting configuration."
exit 1
fi
}

state_machine() {
case "$1" in
"start")
input_start
;;
"params")
input_params
;;
"svn_setup")
select_svn_installation
;;
"svn_params")
input_svn_params
;;
"git_setup")
select_git_installation
;;
"git_params")
input_git_params
;;
"done")
echo "DONE"
exit 0
;;
*)
echo "invalid state: ${STATE}"
exit 1
;;
esac
}

wizard "start"
Loading

0 comments on commit 0edc69e

Please sign in to comment.