Skip to content

Commit

Permalink
Merge pull request #442 from codeigniter4projects/develop
Browse files Browse the repository at this point in the history
Deploy
  • Loading branch information
kenjis authored May 18, 2024
2 parents 97f1b22 + baad5ea commit 3a9a4c6
Show file tree
Hide file tree
Showing 26 changed files with 850 additions and 568 deletions.
58 changes: 58 additions & 0 deletions .github/scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/sh -e

# Deploys the official site to the production server.
# See ../workflows/deploy.yml

REPO="/opt/website"
RELEASE_DIR="/home/public_html/site/releases"
SHARED_DIR="/home/public_html/site/shared"
USERGUIDE_DIR="/home/public_html/userguides"
CONFIG_FILE="/home/public_html/config/.env.site"

if [ "$(id -u)" = "0" ]; then
echo "Cannot be run as root. Please run as the user for deployment."
exit 1
fi

RELEASE=`date +"%Y-%m-%d-%H-%M-%S"`

echo 'Update website repository\n'
cd $REPO
git switch master
git pull

echo 'Copy current release\n'
cd $RELEASE_DIR
sudo cp -pr $REPO ./$RELEASE

echo 'Install composer dependencies\n'
cd $RELEASE_DIR/$RELEASE
composer install --no-dev

if [ ! -d "$SHARED_DIR" ]; then
echo 'Create shared directory\n'
sudo mkdir -p "$SHARED_DIR"
echo 'Setup folder permissions\n'
sudo chown -R www-data:www-data writable
sudo chmod -R 755 writable
sudo cp -rp writable "$SHARED_DIR"
fi

echo 'Link writable\n'
sudo rm -rf writable
sudo ln -nsf "$SHARED_DIR/writable" writable

echo 'Link .env\n'
sudo ln -nsf $CONFIG_FILE .env

echo 'Link user guides\n'
ln -nsf $USERGUIDE_DIR/userguide4 public/user_guide
ln -nsf $USERGUIDE_DIR/userguide3 public/userguide3
ln -nsf $USERGUIDE_DIR/userguide2 public/userguide2

echo 'Deploy: update symlink\n'
cd $RELEASE_DIR
sudo ln -nsf $RELEASE_DIR/$RELEASE "../current"

echo 'Reload PHP8.1-FPM\n'
sudo service php8.1-fpm reload
63 changes: 8 additions & 55 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,59 +13,12 @@ jobs:
with:
ref: master

- name: Install SSH key
uses: shimataro/ssh-key-action@v2
- name: executing remote ssh commands using ssh key
uses: appleboy/ssh-action@v1
with:
key: ${{ secrets.DEPLOY_KEY }}
name: id_rsa
known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }}

- name: Deploy to Webserver
uses: yeshan333/rsync-deploy-action@main
id: rsync-deploy-action
with:
ssh_login_username: ${{ secrets.DEPLOY_USER }}
remote_server_ip: ${{ secrets.DEPLOY_SSH_BOX }}
ssh_port: ${{ secrets.DEPLOY_PORT }}
ssh_private_key: ${{ secrets.DEPLOY_KEY }}
source_path: "./*"
destination_path: "/home/public_html/site/latest"

- name: Finalize deployment
uses: appleboy/ssh-action@master
env:
RELEASE_DIR: "/home/public_html/site/releases/"
RSYNC_DIR: "/home/public_html/site/latest/"
USERGUIDE_DIR: "/home/public_html/userguides"
CONFIG_FILE: "/home/public_html/config/.env.site"
with:
host: ${{ secrets.DEPLOY_SSH_BOX }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
script_stop: true
envs: RELEASE_DIR,CONFIG_FILE,RSYNC_DIR,USERGUIDE_DIR
script: |
cd ~/
RELEASE=`date +"%d-%m-%Y-%H-%M-%S"`
echo $'Copy current release\n'
cd $RELEASE_DIR
cp -r ../latest ./$RELEASE
echo $'Install composer dependencies\n'
cd $RELEASE_DIR/$RELEASE
composer install
echo $'Setup FS\n'
cd $RELEASE_DIR/$RELEASE
sudo chmod -R 777 writable
sudo chmod -R a+rx vendor
sudo ln -nsf $CONFIG_FILE .env
echo $'Link current user guide\n'
sudo ln -nsf $USERGUIDE_DIR/userguide4 public/user_guide
echo $'Set up Links\n'
cd $RELEASE_DIR
sudo ln -nsf $RELEASE_DIR/$RELEASE "../current"
sudo service php8.1-fpm reload
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
fingerprint: ${{ secrets.FINGERPRINT }}
script: /opt/website/.github/scripts/deploy.sh
9 changes: 5 additions & 4 deletions app/Config/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ class Autoload extends AutoloadConfig
* their location on the file system. These are used by the autoloader
* to locate files the first time they have been instantiated.
*
* The '/app' and '/system' directories are already mapped for you.
* you may change the name of the 'App' namespace if you wish,
* The 'Config' (APPPATH . 'Config') and 'CodeIgniter' (SYSTEMPATH) are
* already mapped for you.
*
* You may change the name of the 'App' namespace if you wish,
* but this should be done prior to creating any namespaced classes,
* else you will need to modify all of those classes for this to work.
*
Expand All @@ -44,8 +46,7 @@ class Autoload extends AutoloadConfig
* @var array<string, list<string>|string>
*/
public $psr4 = [
APP_NAMESPACE => APPPATH, // For custom app namespace
'Config' => APPPATH . 'Config',
APP_NAMESPACE => APPPATH,
];

/**
Expand Down
1 change: 0 additions & 1 deletion app/Config/Boot/development.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@
| the system. This will control whether Kint is loaded, and a few other
| items. It can always be used within your own application too.
*/

defined('CI_DEBUG') || define('CI_DEBUG', true);
7 changes: 5 additions & 2 deletions app/Config/Boot/production.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
|--------------------------------------------------------------------------
| Don't show ANY in production environments. Instead, let the system catch
| it and display a generic error message.
|
| If you set 'display_errors' to '1', CI4's detailed error report will show.
*/
error_reporting(E_ALL & ~E_DEPRECATED);
// If you want to suppress more types of errors.
// error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
ini_set('display_errors', '0');
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);

/*
|--------------------------------------------------------------------------
Expand All @@ -18,5 +22,4 @@
| the system. It's not widely used currently, and may not survive
| release of the framework.
*/

defined('CI_DEBUG') || define('CI_DEBUG', false);
1 change: 0 additions & 1 deletion app/Config/Boot/testing.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@
| the system. It's not widely used currently, and may not survive
| release of the framework.
*/

defined('CI_DEBUG') || define('CI_DEBUG', true);
38 changes: 19 additions & 19 deletions app/Config/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,6 @@ class Cache extends BaseConfig
*/
public string $storePath = WRITEPATH . 'cache/';

/**
* --------------------------------------------------------------------------
* Cache Include Query String
* --------------------------------------------------------------------------
*
* Whether to take the URL query string into consideration when generating
* output cache files. Valid options are:
*
* false = Disabled
* true = Enabled, take all query parameters into account.
* Please be aware that this may result in numerous cache
* files generated for the same page over and over again.
* array('q') = Enabled, but only take into account the specified list
* of query parameters.
*
* @var bool|list<string>
*/
public $cacheQueryString = false;

/**
* --------------------------------------------------------------------------
* Key Prefix
Expand Down Expand Up @@ -167,4 +148,23 @@ class Cache extends BaseConfig
'redis' => RedisHandler::class,
'wincache' => WincacheHandler::class,
];

/**
* --------------------------------------------------------------------------
* Web Page Caching: Cache Include Query String
* --------------------------------------------------------------------------
*
* Whether to take the URL query string into consideration when generating
* output cache files. Valid options are:
*
* false = Disabled
* true = Enabled, take all query parameters into account.
* Please be aware that this may result in numerous cache
* files generated for the same page over and over again.
* ['q'] = Enabled, but only take into account the specified list
* of query parameters.
*
* @var bool|list<string>
*/
public $cacheQueryString = false;
}
105 changes: 105 additions & 0 deletions app/Config/Cors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

namespace Config;

use CodeIgniter\Config\BaseConfig;

/**
* Cross-Origin Resource Sharing (CORS) Configuration
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
*/
class Cors extends BaseConfig
{
/**
* The default CORS configuration.
*
* @var array{
* allowedOrigins: list<string>,
* allowedOriginsPatterns: list<string>,
* supportsCredentials: bool,
* allowedHeaders: list<string>,
* exposedHeaders: list<string>,
* allowedMethods: list<string>,
* maxAge: int,
* }
*/
public array $default = [
/**
* Origins for the `Access-Control-Allow-Origin` header.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
*
* E.g.:
* - ['http://localhost:8080']
* - ['https://www.example.com']
*/
'allowedOrigins' => [],

/**
* Origin regex patterns for the `Access-Control-Allow-Origin` header.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
*
* NOTE: A pattern specified here is part of a regular expression. It will
* be actually `#\A<pattern>\z#`.
*
* E.g.:
* - ['https://\w+\.example\.com']
*/
'allowedOriginsPatterns' => [],

/**
* Weather to send the `Access-Control-Allow-Credentials` header.
*
* The Access-Control-Allow-Credentials response header tells browsers whether
* the server allows cross-origin HTTP requests to include credentials.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials
*/
'supportsCredentials' => false,

/**
* Set headers to allow.
*
* The Access-Control-Allow-Headers response header is used in response to
* a preflight request which includes the Access-Control-Request-Headers to
* indicate which HTTP headers can be used during the actual request.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers
*/
'allowedHeaders' => [],

/**
* Set headers to expose.
*
* The Access-Control-Expose-Headers response header allows a server to
* indicate which response headers should be made available to scripts running
* in the browser, in response to a cross-origin request.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers
*/
'exposedHeaders' => [],

/**
* Set methods to allow.
*
* The Access-Control-Allow-Methods response header specifies one or more
* methods allowed when accessing a resource in response to a preflight
* request.
*
* E.g.:
* - ['GET', 'POST', 'PUT', 'DELETE']
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods
*/
'allowedMethods' => [],

/**
* Set how many seconds the results of a preflight request can be cached.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age
*/
'maxAge' => 7200,
];
}
Loading

0 comments on commit 3a9a4c6

Please sign in to comment.