CodeIgniter Forums
gitlab CI/CD pipeline cannot run php spark - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: gitlab CI/CD pipeline cannot run php spark (/showthread.php?tid=77284)



gitlab CI/CD pipeline cannot run php spark - adty - 08-11-2020

i'm implementing gitlab CI/CD pipeline in my CI4 project.

running 
PHP Code:
php spark migrate 

 in gitlab CI/CD script get this error

Code:
CodeIgniter CLI Tool - Version 4.0.4 - Server-Time: 2020-08-11 16:49:30pm

ERROR: 404
Can't find a route for 'cimigrate'.

ERROR: Job failed: exit status 1

I don't get error when execute migration on live server.

is it bug? please help...
thanks.


RE: gitlab CI/CD pipeline cannot run php spark - adty - 08-11-2020

Found the problem in CodeIgniter.php file, detectEnvironment() function.

PHP Code:
protected function detectEnvironment()
{
    
// Make sure ENVIRONMENT isn't already set by other means.
    
if (! defined('ENVIRONMENT'))
    {
        
// running under Continuous Integration server?
        
if (getenv('CI') !== false)
        {
            
define('ENVIRONMENT''testing');
        }
        else
        {
            
define('ENVIRONMENT'$_SERVER['CI_ENVIRONMENT'] ?? 'production');
        }
    }


When we run under CI server, we will always get ENVIRONMENT = testing.

Testing environment can't get clirequest in getRequestObject() function if we run it in cli.

PHP Code:
protected function getRequestObject()
{
    if (
$this->request instanceof Request)
    {
        return;
    }

    if (
is_cli() && ENVIRONMENT !== 'testing')
    {
        
// @codeCoverageIgnoreStart
        
$this->request Services::clirequest($this->config);
        
// @codeCoverageIgnoreEnd
    
}
    else
    {
        
$this->request Services::request($this->config);
        
// guess at protocol if needed
        
$this->request->setProtocolVersion($_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1');
    }


It means we dont have flexibility to change/use custom ENVIRONMENT in CI/CD server.

Can i request to remove the code that always set ENVIRONMENT = testing in CI/CD server?
or
request to allow testing environment to get/use clirequest?


RE: gitlab CI/CD pipeline cannot run php spark - InsiteFX - 08-12-2020

You can set the environment in the env file.

Code:
#--------------------------------------------------------------------
# ENVIRONMENT
#--------------------------------------------------------------------

# CI_ENVIRONMENT = production
CI_ENVIRONMENT = developement
# CI_ENVIRONMENT = testing

You can also set it in the root .htaccess file.

Code:
#SetEnv CI_ENVIRONMENT 'production'
SetEnv CI_ENVIRONMENT 'development'
#SetEnv CI_ENVIRONMENT 'testing'

Worse case add the environment to the spark file.


RE: gitlab CI/CD pipeline cannot run php spark - adty - 08-18-2020

My work around right now is by ignoring environment (start with an empty environment)

PHP Code:
env -i php spark migrate -n App 

I'm still digging to find a better way

(08-12-2020, 05:03 AM)InsiteFX Wrote: You can set the environment in the env file.

Code:
#--------------------------------------------------------------------
# ENVIRONMENT
#--------------------------------------------------------------------

# CI_ENVIRONMENT = production
CI_ENVIRONMENT = developement
# CI_ENVIRONMENT = testing

You can also set it in the root .htaccess file.

Code:
#SetEnv CI_ENVIRONMENT 'production'
SetEnv CI_ENVIRONMENT 'development'
#SetEnv CI_ENVIRONMENT 'testing'

Worse case add the environment to the spark file.

Changing environment in .env file doesnt work for me. I'll try the .htaccess approach


RE: gitlab CI/CD pipeline cannot run php spark - janiscp - 01-03-2021

(08-18-2020, 08:01 PM)adty Wrote: My work around right now is by ignoring environment (start with an empty environment)

PHP Code:
env -i php spark migrate -n App 

Thank you for this!