Skip to content

Commit

Permalink
DreamFactory - Upgrade Debian and fix setup (#2832)
Browse files Browse the repository at this point in the history
* VM - DreamFactory - Upgrade Debian

* dreamfactory

* fix: refactor setup
  • Loading branch information
armandomiani authored Jan 7, 2025
1 parent 6267a04 commit 58cb36b
Show file tree
Hide file tree
Showing 16 changed files with 303 additions and 28 deletions.
27 changes: 25 additions & 2 deletions vm/chef/cookbooks/dreamfactory/attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Google LLC
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,5 +14,28 @@

default['dreamfactory']['version'] = '6.3.0'
default['dreamfactory']['db']['name'] = 'dreamfactory'
default['dreamfactory']['packages'] = [
'git',
'curl',
'cron',
'zip',
'unzip',
'ca-certificates',
'apt-transport-https',
'lsof',
'mcrypt',
'libmcrypt-dev',
'libreadline-dev',
'wget',
'sudo',
'nginx',
'build-essential',
'unixodbc-dev',
'gcc',
'cmake',
'jq',
'libaio1',
'php-pear',
]

default['php81']['distribution'] = 'bullseye'
default['php81']['distribution'] = 'bookworm'
6 changes: 3 additions & 3 deletions vm/chef/cookbooks/dreamfactory/files/dreamfactory
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ systemctl stop nginx

echo "Installing dependencies..."
cd "${df_install_folder}"
composer update --no-install
composer install -n --no-dev
composer install -n --no-dev --ignore-platform-reqs

echo "Create database user..."
setup_mysql_user "${df_db_user}" "${df_db_password}" "${df_db_name}" "${mysql_root_password}"
Expand All @@ -51,6 +50,7 @@ setup_database \
"${df_admin_firstname}" "${df_admin_lastname}" "${df_admin_email}" "${df_admin_password}"

echo "Setting up folder permissions..."
chown -R "${nginx_usergroup}" "${df_install_folder}"
chown -R "${nginx_usergroup}" storage/ bootstrap/cache/
chmod -R 2775 storage/ bootstrap/cache/

Expand All @@ -65,7 +65,7 @@ configure_nginx
# remove web.config due security
echo "Enabling Website..."
rm -f "${df_install_folder}/public/web.config"
rm -f /etc/nginx/sites-enabled/default.conf
rm -f /etc/nginx/sites-enabled/default
ln -s /etc/nginx/sites-available/dreamfactory.conf /etc/nginx/sites-enabled/

echo "Starting Webserver..."
Expand Down
6 changes: 6 additions & 0 deletions vm/chef/cookbooks/dreamfactory/files/dreamfactory-utils
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ function create_config_file() {
local db_user="$2"
local db_password="$3"
local redis_password="$4"
local app_key="$(openssl rand -base64 16)"


php artisan df:env \
--db_connection="mysql" \
Expand All @@ -58,12 +60,16 @@ function create_config_file() {
--db_password="${db_password}" \
--no-interaction

# Set APP KEY
sed -i "s#APP_KEY=.*#APP_KEY=${app_key}#" "${df_config_file}"

# Configure Cache settings
sed -i "s/#CACHE_HOST=/CACHE_HOST=localhost/" "${df_config_file}"
sed -i "s/#CACHE_DATABASE=2/CACHE_DATABASE=2/" "${df_config_file}"
sed -i "s/CACHE_DRIVER=file/CACHE_DRIVER=redis/" "${df_config_file}"
sed -i "s/#CACHE_PORT=/CACHE_PORT=6379/" "${df_config_file}"
sed -i "s/#CACHE_PASSWORD=/CACHE_PASSWORD=${redis_password}/" "${df_config_file}"

}

#######################################
Expand Down
17 changes: 11 additions & 6 deletions vm/chef/cookbooks/dreamfactory/files/nginx-dreamfactory.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ server {
}

server {
listen 443;
server_name localhost;
listen 443 ssl;
ssl_certificate /etc/ssl/certs/c2d-temporary-self-signed-cert.pem;
ssl_certificate_key /etc/ssl/private/c2d-temporary-self-signed-cert.key;

server_name %SERVERNAME%;
root "/opt/dreamfactory/public";
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";

index index.html index.htm index.php;

charset utf-8;

ssl on;
ssl_certificate /etc/ssl/certs/c2d-temporary-self-signed-cert.pem;
ssl_certificate_key /etc/ssl/private/c2d-temporary-self-signed-cert.key;

location / {
try_files $uri $uri/ /index.php?$query_string;
}
Expand Down Expand Up @@ -68,4 +69,8 @@ server {
location ~ /\.ht {
deny all;
}

location ~ /web.config {
deny all;
}
}
48 changes: 48 additions & 0 deletions vm/chef/cookbooks/dreamfactory/files/setup-frontend
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

declare -r REPO_OWNER="dreamfactorysoftware/df-admin-interface"
declare -r REPO_URL="https://github.com/${REPO_OWNER}"
declare -r DF_FOLDER=/opt/dreamfactory
declare -r DESTINATION_FOLDER="${DF_FOLDER}/public"
declare -r TEMP_FOLDER="/tmp/df-ui"
declare -r RELEASE_FILENAME="release.zip"
declare -r FOLDERS_TO_REMOVE="dreamfactory filemanager df-api-docs-ui assets"

REPO_OWNER="dreamfactorysoftware/df-admin-interface"
REPO_URL="https://github.com/${REPO_OWNER}"
DF_FOLDER=/opt/dreamfactory
DESTINATION_FOLDER="${DF_FOLDER}/public"
TEMP_FOLDER="/tmp/df-ui"
RELEASE_FILENAME="release.zip"
FOLDERS_TO_REMOVE="dreamfactory filemanager df-api-docs-ui assets"

echo >&2 "Creating temporary directories..."
mkdir -p "${TEMP_FOLDER}" "${DESTINATION_FOLDER}"

echo >&2 "Setting up front-end..."
cd "${TEMP_FOLDER}"

# Getting the latest release
latest_release="$(curl -s \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${REPO_OWNER}/releases" \
| jq -r '.[0].tag_name')"
echo >&2 "- Latest release: ${latest_release}"

# Download the release
release_url="${REPO_URL}/releases/download/${latest_release}/release.zip"
curl -LO "${release_url}"

# Clean up destination folder
find "$DESTINATION_FOLDER" -type f \( -name "*.js" -o -name "*.css" \) -exec rm {} \;
for folder in ${FOLDERS_TO_REMOVE}; do
if [ -d "${DESTINATION_FOLDER}/${folder}" ]; then rm -rf "${DESTINATION_FOLDER}/${folder}"; fi;
done

# Extract the release
unzip -qo "${RELEASE_FILENAME}" -d "${TEMP_FOLDER}"
mv dist/index.html "${DF_FOLDER}/resources/views/index.blade.php"
mv dist/* "${DESTINATION_FOLDER}"
cd .. && rm -rf "${TEMP_FOLDER}"

echo >&2 "Finished."
4 changes: 2 additions & 2 deletions vm/chef/cookbooks/dreamfactory/metadata.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 Google LLC
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
name 'dreamfactory'
depends 'git'
depends 'composer'
depends 'php74'
depends 'php81'
depends 'nginx'
depends 'mysql'
depends 'redis'
Expand Down
69 changes: 55 additions & 14 deletions vm/chef/cookbooks/dreamfactory/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Google LLC
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -18,16 +18,28 @@
include_recipe 'nginx'
include_recipe 'redis::standalone'

include_recipe 'php74'
include_recipe 'php74::module_curl'
include_recipe 'php74::module_json'
include_recipe 'php74::module_mbstring'
include_recipe 'php74::module_mongodb'
include_recipe 'php74::module_mysql'
include_recipe 'php74::module_opcache'
include_recipe 'php74::module_sqlite'
include_recipe 'php74::module_simplexml'
include_recipe 'php74::module_zip'
include_recipe 'php81'
include_recipe 'php81::module_bcmath'
include_recipe 'php81::module_cli'
include_recipe 'php81::module_dev'
include_recipe 'php81::module_curl'
include_recipe 'php81::module_fpm'
include_recipe 'php81::module_http'
include_recipe 'php81::module_interbase'
include_recipe 'php81::module_ldap'
include_recipe 'php81::module_mbstring'
include_recipe 'php81::module_mongodb'
include_recipe 'php81::module_mysql'
include_recipe 'php81::module_odbc'
include_recipe 'php81::module_opcache'
include_recipe 'php81::module_pdo'
include_recipe 'php81::module_raphf'
include_recipe 'php81::module_soap'
include_recipe 'php81::module_sqlite'
include_recipe 'php81::module_simplexml'
include_recipe 'php81::module_sybase'
include_recipe 'php81::module_xml'
include_recipe 'php81::module_zip'
include_recipe 'composer::composer2'
include_recipe 'git'

Expand All @@ -37,27 +49,56 @@
action :update
end

package 'install_packages' do
package_name node['dreamfactory']['packages']
action :install
end

bash 'Install Pear Packages' do
user 'root'
code <<-EOH
DEBIAN_FRONTEND=noninteractive pecl channel-update pecl.php.net && \
echo '' | pecl install --force mcrypt && \
echo '' | pecl install --force igbinary && \
echo '' | pecl install --force sqlsrv-5.11.1 && \
echo '' | pecl install --force pdo_sqlsrv-5.11.1
EOH
end

cookbook_file '/etc/nginx/sites-available/dreamfactory.conf' do
source 'nginx-dreamfactory.conf'
owner 'root'
group 'root'
mode 0755
action :create
end

git '/usr/src/dreamfactory' do
repository 'https://github.com/dreamfactorysoftware/dreamfactory.git'
reference node['dreamfactory']['version']
action :checkout
end

bash 'Copy app' do
bash 'Copy DreamFactory to the production folder' do
user 'root'
code <<-EOH
cp -rf /usr/src/dreamfactory/ /opt/
EOH
end

cookbook_file '/etc/nginx/sites-available/dreamfactory.conf' do
source 'nginx-dreamfactory.conf'
# Copy and install the front end
cookbook_file '/opt/c2d/setup-frontend' do
source 'setup-frontend'
owner 'root'
group 'root'
mode 0755
action :create
end

execute 'install_frontend' do
command '/opt/c2d/setup-frontend'
end

cookbook_file '/opt/c2d/dreamfactory-utils' do
source 'dreamfactory-utils'
owner 'root'
Expand Down
19 changes: 19 additions & 0 deletions vm/chef/cookbooks/php81/recipes/module_fpm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package 'php8.1-fpm' do
action :install
retries 5
retry_delay 20
end
19 changes: 19 additions & 0 deletions vm/chef/cookbooks/php81/recipes/module_http.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package 'php8.1-http' do
action :install
retries 5
retry_delay 20
end
19 changes: 19 additions & 0 deletions vm/chef/cookbooks/php81/recipes/module_interbase.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package 'php8.1-interbase' do
action :install
retries 5
retry_delay 20
end
19 changes: 19 additions & 0 deletions vm/chef/cookbooks/php81/recipes/module_odbc.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package 'php8.1-odbc' do
action :install
retries 5
retry_delay 20
end
19 changes: 19 additions & 0 deletions vm/chef/cookbooks/php81/recipes/module_pdo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package 'php8.1-pdo' do
action :install
retries 5
retry_delay 20
end
Loading

0 comments on commit 58cb36b

Please sign in to comment.