add manual deployment scripts #96

Merged
maxime.batista merged 1 commits from manual-deploy into master 1 year ago

4
.gitignore vendored

@ -8,13 +8,15 @@ vendor
.nfs*
composer.lock
*.phar
/dist
dist
.guard
outputs
# sqlite database files
*.sqlite
views-mappings.php
.env.PROD
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

@ -37,8 +37,9 @@ steps:
- echo n | /tmp/moshell_setup.sh
- echo "VITE_API_ENDPOINT=/IQBall/$DRONE_BRANCH/public/api" >> .env.PROD
- echo "VITE_BASE=/IQBall/$DRONE_BRANCH/public" >> .env.PROD
- apt update && apt install jq -y
-
- /root/.local/bin/moshell ci/build_react.msh
- BASE="/IQBall/$DRONE_BRANCH/public" OUTPUT=/outputs /root/.local/bin/moshell ci/build_react.msh
- image: ubuntu:latest
name: "prepare php"
@ -48,7 +49,8 @@ steps:
commands:
- mkdir -p /outputs/public
# this sed command will replace the included `profile/dev-config-profile.php` to `profile/prod-config-file.php` in the config.php file.
- sed -iE 's/\\/\\*PROFILE_FILE\\*\\/\\s*".*"/"profiles\\/prod-config-profile.php"/' config.php
- sed -E -i 's/\\/\\*PROFILE_FILE\\*\\/\\s*".*"/"profiles\\/prod-config-profile.php"/' config.php
- sed -E -i "s/const BASE_PATH = .*;/const BASE_PATH = \"\\/IQBall\\/$DRONE_BRANCH\\/public\";/" profiles/prod-config-profile.php
- rm profiles/dev-config-profile.php
- mv src config.php sql profiles vendor /outputs/

@ -0,0 +1,17 @@
Review

The shebang is missing.

The shebang is missing.
export OUTPUT=$1
export BASE=$2
rm -rf $OUTPUT/*
Review

Quote the variable as it may contain spaces. Also, if $1 isn't defined, this will literally execute rm -rf /*

Quote the variable as it may contain spaces. Also, if `$1` isn't defined, this will literally execute `rm -rf /*`
echo "VITE_API_ENDPOINT=$BASE/api" >> .env.PROD
echo "VITE_BASE=$BASE" >> .env.PROD
Review

Just pass those as environment variables? They don't need to be in a file.

Just pass those as environment variables? They don't need to be in a file.
ci/build_react.msh
mkdir -p $OUTPUT/profiles/
sed -E 's/\/\*PROFILE_FILE\*\/\s*".*"/"profiles\/prod-config-profile.php"/' config.php > $OUTPUT/config.php
sed -E "s/const BASE_PATH = .*;/const BASE_PATH = \"$(sed s/\\//\\\\\\//g <<< "$BASE")\";/" profiles/prod-config-profile.php > $OUTPUT/profiles/prod-config-profile.php
cp -r vendor sql src public $OUTPUT

@ -1,20 +1,17 @@
#!/usr/bin/env moshell
mkdir -p /outputs/public
val base = std::env("BASE").unwrap()
val outputs = std::env("OUTPUT").unwrap()
apt update && apt install jq -y
mkdir -p $outputs/public
val drone_branch = std::env("DRONE_BRANCH").unwrap()
val base = "/IQBall/$drone_branch/public"
npm run build -- --base=$base --mode PROD
// Read generated mappings from build
val result = $(jq -r 'to_entries|map(.key + " " +.value.file)|.[]' dist/manifest.json)
val mappings = $result.split('\n')
echo '<?php\nconst ASSETS = [' > views-mappings.php
echo '<?php const ASSETS = [' > views-mappings.php
while $mappings.len() > 0 {
val mapping = $mappings.pop().unwrap();
@ -28,5 +25,5 @@ echo "];" >> views-mappings.php
chmod +r views-mappings.php
mv dist/* front/assets/ front/style/ public/* /outputs/public/
mv views-mappings.php /outputs/
cp -r dist/* front/assets/ front/style/ public/* $outputs/public/
cp -r views-mappings.php $outputs/

@ -18,6 +18,10 @@ function asset(string $assetURI): string {
return _asset($assetURI);
}
function get_base_path(): string {
return _get_base_path();
}
global $_data_source_name;
$data_source_name = $_data_source_name;
const DATABASE_USER = _DATABASE_USER;

@ -121,15 +121,7 @@ function EditorView({
const [content, setContent, saveState] = useContentState(
initialContent,
isInGuestMode ? SaveStates.Guest : SaveStates.Ok,
useMemo(
() =>
debounceAsync(
(content) =>
onContentChange(content).then((success) =>
success ? SaveStates.Ok : SaveStates.Err,
),
250,
),
useMemo(() => debounceAsync(onContentChange),
[onContentChange],
),
)

@ -30,3 +30,7 @@ function _init_database(PDO $pdo): void {
$accounts->setIsAdmin($id, true);
}
}
function _get_base_path(): string {
return "";
}

@ -4,6 +4,9 @@
// in an `ASSETS` array constant.
require __DIR__ . "/../views-mappings.php";
// THIS VALUE IS TO SET IN THE CI
const BASE_PATH = null;
Review

"" is a reasonable default.

`""` is a reasonable default.
const _SUPPORTS_FAST_REFRESH = false;
$database_file = __DIR__ . "/../database.sqlite";
$_data_source_name = "sqlite:/$database_file";
@ -23,3 +26,7 @@ function _asset(string $assetURI): string {
function _init_database(PDO $pdo): void {}
function _get_base_path(): string {
return BASE_PATH;
}

@ -0,0 +1,4 @@
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ ./index.php [NC,L,QSA]

@ -0,0 +1,4 @@
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ ./index.php [NC,L,QSA]

@ -3,7 +3,6 @@
require "../../config.php";
require "../../vendor/autoload.php";
require "../../sql/database.php";
require "../../src/index-utils.php";
use IQBall\Api\API;
use IQBall\Api\Controller\APIAccountsController;
@ -19,7 +18,8 @@ use IQBall\Core\Gateway\TacticInfoGateway;
use IQBall\Core\Model\AuthModel;
use IQBall\Core\Model\TacticModel;
$basePath = get_public_path(__DIR__);
$basePath = get_base_path() . "/api";
function getTacticController(): APITacticController {
return new APITacticController(new TacticModel(new TacticInfoGateway(new Connection(get_database()))));
@ -41,8 +41,8 @@ function getServerController(): APIServerController {
}
function getRoutes(): AltoRouter {
$router = new AltoRouter();
global $basePath;
$router = new AltoRouter();
$router->setBasePath($basePath);
$router->map("POST", "/auth", Action::noAuth(fn() => getAuthController()->authorize()));

@ -4,7 +4,6 @@ require "../vendor/autoload.php";
require "../config.php";
require "../sql/database.php";
require "../src/App/react-display.php";
require "../src/index-utils.php";
use IQBall\App\App;
use IQBall\App\Controller\AuthController;
@ -125,6 +124,6 @@ function runMatch($match, MutableSessionHandle $session): HttpResponse {
}
//this is a global variable
$basePath = get_public_path(__DIR__);
$basePath = get_base_path();
App::render(runMatch(getRoutes()->match(), PhpSessionHandle::init()), fn() => getTwig());

@ -38,7 +38,7 @@ class API {
*/
public static function handleMatch($match, callable $tryGetAuthorization): HttpResponse {
if (!$match) {
return new JsonHttpResponse([ValidationFail::notFound("not found")]);
return new JsonHttpResponse([ValidationFail::notFound("not found")], HttpCodes::NOT_FOUND);
}
$action = $match['target'];

@ -49,6 +49,7 @@ class APITacticController {
/**
* @param int $id
* @param Account $account
* @return HttpResponse
*/
public function saveContent(int $id, Account $account): HttpResponse {

@ -84,7 +84,7 @@ class App {
if ($account == null) {
// put in the session the initial url the user wanted to get
$session->setInitialTarget($_SERVER['REQUEST_URI']);
return HttpResponse::redirect($authRoute);
return HttpResponse::redirectAbsolute($authRoute);
}
if ($action->getAuthType() == Action::AUTH_ADMIN && !$account->getUser()->isAdmin()) {

@ -1,21 +0,0 @@
<?php
/**
* relative path of the public directory from the server's document root.
*/
function get_public_path(string $public_dir): string {
// find the server path of the index.php file
$basePath = substr($public_dir, strlen($_SERVER['DOCUMENT_ROOT']));
$basePathLen = strlen($basePath);
if ($basePathLen == 0) {
return "";
}
$c = $basePath[$basePathLen - 1];
if ($c == "/" || $c == "\\") {
$basePath = substr($basePath, 0, $basePathLen - 1);
}
return $basePath;
}
Loading…
Cancel
Save