Skip to content

Commit

Permalink
Revert "wip"
Browse files Browse the repository at this point in the history
This reverts commit e9e53a3.
  • Loading branch information
Oleksandr-Moik committed Jan 24, 2024
1 parent 95ce59c commit 7006658
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 183 deletions.
39 changes: 3 additions & 36 deletions config/gitlab-deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,13 @@

return [

/*
|--------------------------------------------------------------------------
| GitLab server
|--------------------------------------------------------------------------
|
| Uses for `ssh-keyscan` command to fetch public keys
| and put to known hosts file on remote server
|
*/
'gitlab-server' => env('GITLAB_HOST', 'gitlab.hexide-digital.com'),
'gitlab-server' => env('GITLAB_HOST', 'gitlab.hexide-digital.com,188.34.141.230'),

/*
|--------------------------------------------------------------------------
| Deployer file
|--------------------------------------------------------------------------
|
| Path to deployer file
|
*/
'deployer-php' => base_path('deploy.php'),

/*
|--------------------------------------------------------------------------
| Working directory
|--------------------------------------------------------------------------
|
| Uses for store logs, env and other files across execution
|
*/
'working-dir' => base_path('.deploy'),
'store-log-folder' => base_path('.deploy/logs'),
'config-file' => base_path('.deploy/deploy-prepare.yml'),

'ssh' => [
'key_name' => 'id_rsa',
Expand All @@ -45,16 +22,6 @@
// 'folder' => base_path('.ssh/{{STAGE}}'),
],

/*
|--------------------------------------------------------------------------
| Deploy prepare tasks
|--------------------------------------------------------------------------
|
| List of tasks to execute on deploy prepare command.
| You can edit this list as you want.
| To add new task extend from `HexideDigital\GitlabDeploy\Tasks\BaseTask`
|
*/
'tasks' => [
Tasks\GenerateSshKeysOnLocalhost::class,
Tasks\CopySshKeysOnRemoteHost::class,
Expand Down
59 changes: 16 additions & 43 deletions examples/deploy-prepare.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,44 @@
# How to work with the file, read here
# https://github.com/hexidedigital/laravel-gitlab-deploy#configurations-and-prepare-access

version: 1.4
version: 1

# Repository configurations
git-lab:
project:
# Read where to get this token - https://github.com/hexidedigital/laravel-gitlab-deploy#gitlab-api-access-token
# Auth token for GitLab API
token: "XXXXXXXXXX"

# Project ID
# Read where to get this id - https://github.com/hexidedigital/laravel-gitlab-deploy#project-id
project-id: 000000
#project-id: "namespace/project_name"
# project-id: "namespace/project_name"

# Git remote url for clone
git-url: [email protected]:NAMESPACE/PROJECT_NAME.git

# GitLab Server url for API access
domain: https://gitlab.hexide-digital.com


# Server configurations
stages:
# Server configurations for stage.
# Stage name (or branch name)
# Stage name to prepare command
- name: dev
# General options for prepare command.
options:
# Server domain or url.
domain: https://example.com
# Deployment directory on server. Only absolute path. Supports replaces.
git-url: [email protected]:NAMESPACE/PROJECT_NAME.git
base-dir-pattern: "/home/{{USER}}/web/{{HOST}}/public_html"
# to detect path - execute `whereis composer`
bin-composer: /usr/bin/php8.1 /usr/bin/composer
# to detect path - execute `whereis php`
bin-php: /usr/bin/php8.1

# Configurations for database
database:
database: application_db
username: application_db
password: XXXXXXXXXX_db

# Configurations for server
# ssh options
server:
# Remote server ip or domain. Uses as HOST replacement.
ssh-port: 22
domain: https://example.com
host: example.com
# Remote server user. Uses as USER replacement.
login: example-user
# Password for remote server. Can be omitted if ssh-key is specified.
#password: XXXXXXXXXX
# Port for ssh connection. Default 22.
#ssh-port: 22
# Specify ssh key for access to server. Only absolute path. Supports replaces.
#ssh-key: "{{PROJ_DIR}}.ssh/id_rsa"
# Options for ssh connection. Can be omitted.
ssh-options:
- "-o IdentitiesOnly=yes"
- "-o StrictHostKeyChecking=no"
- "-o UserKnownHostsFile=/dev/null"
- "-o PasswordAuthentication=no"
password: XXXXXXXXXX

# Configurations for mail server
#mail:
# hostname: mail.example.com
# username: [email protected]
# password: XXXXXXXXXX_mail
database:
database: proj_db
username: proj_db
password: XXXXXXXXXX

# mail:
# hostname: devs.hexide-digital.com
# username: template@host
# password: mail_pass
10 changes: 5 additions & 5 deletions examples/deploy.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Keep this version number to manage file versions in projects
*
* @version 1.4
* @version 1.3
*/

namespace Deployer;
Expand All @@ -26,15 +26,15 @@ $DEPLOY_BASE_DIR = getenv('DEPLOY_BASE_DIR');
$DEPLOY_SERVER = getenv('DEPLOY_SERVER');
$DEPLOY_USER = getenv('DEPLOY_USER');
$SSH_PORT = getenv('SSH_PORT');
/*CI_ENV*/ // - do not remote this comment. Uses for replacement.
/*CI_ENV*/


/* ----------------------------------
* Configs
*/

// TODO: Project name
set('application', 'ApplicationName');
set('application', 'AdminLTE');
// github token
// TODO: CHANGE OAUTH TOKEN
set('github_oauth_token', '66efxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0eae');
Expand Down Expand Up @@ -119,9 +119,9 @@ before('artisan:migrate', function () {

// Maintenance mode

//after('deploy:vendors', 'artisan:down');
after('deploy:vendors', 'artisan:down');

//after('deploy:unlock', 'artisan:up');
after('deploy:unlock', 'artisan:up');

/*
* Note:
Expand Down
3 changes: 2 additions & 1 deletion src/Console/Commands/GitlabDeployInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ protected function getSshDir(): string

protected function getWorkingDir(): string
{
return Str::of(config('gitlab-deploy.working-dir'))
return Str::of(config('gitlab-deploy.config-file'))
->replace(base_path(), '')
->dirname()
->replace(DIRECTORY_SEPARATOR, '/')
->value();
}
Expand Down
4 changes: 1 addition & 3 deletions src/Console/Commands/PrepareDeployCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ protected function getOptions(): array
protected function createLoggers(): void
{
$this->logger = new LoggerBag();

$dir = str(config('gitlab-deploy.working-dir'))->finish('/')->append('logs');
$this->logger->setFileLogger(new FileLogger((string)$dir));
$this->logger->setFileLogger(new FileLogger(config('gitlab-deploy.store-log-folder')));
$this->logger->setConsoleLogger(new ConsoleLogger());

$this->logger->init();
Expand Down
3 changes: 1 addition & 2 deletions src/DeployerState.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public function parseConfigurations(string $stageName): void
{
$parser = app(ParseConfiguration::class);

$filePath = str(config('gitlab-deploy.working-dir'))->finish('/')->append('deploy-prepare.yml');
$fileData = $parser->parseFile((string)$filePath);
$fileData = $parser->parseFile(config('gitlab-deploy.config-file'));

$builder = app(ConfigurationBuilder::class);

Expand Down
10 changes: 1 addition & 9 deletions src/DeploymentOptions/Options/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ final class Server implements BaseOption
public string $domain;
public string $host;
public string $login;
public ?string $password;
public string $password;
public int $sshPort;
public string $sshOptions;

public function __construct(array $source)
{
Expand All @@ -20,17 +19,12 @@ public function __construct(array $source)
$this->login = data_get($source, 'login');
$this->password = data_get($source, 'password');
$this->sshPort = intval(data_get($source, 'ssh-port')) ?: 22;

$this->sshOptions = collect(data_get($source, 'ssh-options'))
->filter()
->implode(' ');
}

public function toArray(): array
{
return [
'sshPort' => $this->sshPort,
'sshOptions' => $this->sshOptions,
'domain' => $this->domain,
'host' => $this->host,
'login' => $this->login,
Expand All @@ -45,8 +39,6 @@ public function toReplacesArray(): array
'HOST' => $this->host,

'SSH_PORT' => $this->sshPort,
'SSH_OPTIONS' => $this->sshOptions,

'DEPLOY_DOMAIN' => $this->domain,
'DEPLOY_SERVER' => $this->host,
'DEPLOY_USER' => $this->login,
Expand Down
8 changes: 0 additions & 8 deletions src/Exceptions/GitlabDeployException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,4 @@ public static function emptyGitlabProjectCredentials(array $values): GitlabDeplo
'To process deploy prepare you must specify Gitlab credentials - ' . implode(', ', $values)
);
}

public static function unsupportedConfigurationVersion(string $actual): GitlabDeployException
{
return new GitlabDeployException(
"Unsupported configuration version [$actual]. " .
"Please update your configuration file to the latest version",
);
}
}
1 change: 0 additions & 1 deletion src/Gitlab/GitlabProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public function __construct(
public readonly string|int $id,
public readonly string $token,
public readonly string $url,
public readonly string $gitUrl,
) {
if (empty($this->token)) {
throw new GitlabDeployException('Provide api token for Gitlab project');
Expand Down
10 changes: 1 addition & 9 deletions src/Helpers/Builders/ConfigurationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,8 @@ public function build(array $array): Configurations
{
$version = floatval(Arr::get($array, 'version'));

// Support only 1.4 and higher
if (version_compare((string)$version, '1.4', '<')) {
throw new GitlabDeployException('Unsupported configuration version. Please');
}

$gitlab = $this->gitlabProjectBuilder->build(Arr::get($array, 'git-lab', []));
$stageBag = $this->stageBagBuilder->build(
$gitlab['project'],
Arr::get($array, 'stages', [])
);
$stageBag = $this->stageBagBuilder->build(Arr::get($array, 'stages', []));

return new Configurations(
$version,
Expand Down
13 changes: 7 additions & 6 deletions src/Helpers/Builders/GitlabProjectBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ final class GitlabProjectBuilder
*/
public function build(array $gitlab): array
{
$project = $gitlab['project'] ?? [];
$project = $gitlab['project'];

$this->validate($project);

$project = new GitlabProject(
id: data_get($project, 'project-id'),
token: data_get($project, 'token'),
url: data_get($project, 'domain'),
gitUrl: data_get($project, 'git-url'),
id: $project['project-id'],
token: $project['token'],
url: $project['domain'],
);

return [
Expand All @@ -37,9 +36,11 @@ public function build(array $gitlab): array
}

/**
* @param array|null $project
* @return void
* @throws GitlabDeployException
*/
public function validate(array $project): void
public function validate(?array $project): void
{
/*todo - validate before create*/
/** @var Collection<string, bool> $listOfEmptyOptions */
Expand Down
Loading

0 comments on commit 7006658

Please sign in to comment.