Skip to content
This repository has been archived by the owner on Apr 7, 2024. It is now read-only.

336 dktl host mode #337

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# EditorConfig helps keep your project formatting consistent.
# See https://EditorConfig.org
#
# PHP PSR-2 Coding Standards
# http://www.php-fig.org/psr/psr-2/
#
# Author: Sal Ferrarello (@salcode)
#
# You can download this file directly
# to your project from the command-line with
# curl -O https://gist.githubusercontent.com/salcode/18eaa8cfa3b097da2f58b582197906d7/raw/.editorconfig

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2

[*.php]
indent_size = 4

[*.md]
trim_trailing_whitespace = false
12 changes: 11 additions & 1 deletion bin/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@
use Consolidation\AnnotatedCommand\CommandFileDiscovery;
use Symfony\Component\Console\Output\ConsoleOutput;

require_once __DIR__ . '/../vendor/autoload.php';
foreach ([
// Legacy-style autoload.
'/../vendor/autoload.php',
// Under vendor.
'/../../vendor/autoload.php',
] as $path) {
$pathy = __DIR__ . $path;
if (file_exists($pathy)) {
require_once $pathy;
}
}

putenv("COMPOSER_MEMORY_LIMIT=-1");

Expand Down
64 changes: 35 additions & 29 deletions bin/dktl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ main() {

set_project_directory "$@"
set_slug

if [ "$DKTL_MODE" = "DOCKER" ]; then
dktl_docker_run "$@"
elif [ "$DKTL_MODE" = "HOST" ]; then
Expand Down Expand Up @@ -52,28 +52,28 @@ dktl_docker_run() {

# Proxy-pass to docker and save exit status. The command will re-
# run in host mode inside the cli container, so dktl_run will still
# ultimately be run whichever mode dktl is set to.
# ultimately be run whichever mode dktl is set to.
dc_base exec $EXEC_OPTS cli dktl "$1" "${@:2}"
exit_status=$?

dktl_docker_cleanup "$@"

# if we encountered a non-zero exit status during the docker exec,
# if we encountered a non-zero exit status during the docker exec,
# pass it on.
if [ $exit_status -ne 0 ]; then
exit $exit_status
fi
}

# Set DKTL_PLATFORM to which platform we're running on (linux and mac
# Set DKTL_PLATFORM to which platform we're running on (linux and mac
# supported)
set_platform() {
if [ -z $PLATFORM ]; then
export PLATFORM=`uname`
fi
}

# Set DKTL_MODE. Determine whether we want to run inside the docker container
# Set DKTL_MODE. Determine whether we want to run inside the docker container
# or in the host machine.
set_mode() {
if [ -z $DKTL_MODE ] || [ "$DKTL_MODE" = "DOCKER" ]; then
Expand Down Expand Up @@ -103,40 +103,46 @@ check_dependencies() {

# Set DKTL_PROJECT_DIRECTORY. Needs "$@" because dktl init hsa different logic.
set_project_directory() {
# Find project root so we can run from anywhere
find_up () {
path=$(pwd)
while [[ "$path" != "" && ! -e "$path/$1" ]]; do
path=${path%/*}
done
echo "$path"
}

if [ "$1" = "init" ] || [ "$1" = "down" ]; then
if [ -z "$DKTL_PROJECT_DIRECTORY" ]; then
DKTL_PROJECT_DIRECTORY=$(pwd)
else
DKTL_PROJECT_DIRECTORY=$(find_up dktl.yml)
if [ -z "$DKTL_PROJECT_DIRECTORY" ]; then
echo "DKTL is running outside of a DKTL project. Run dktl init in the project directory first."
exit 1
# Find project root so we can run from anywhere
find_up () {
path=$(pwd)
while [[ "$path" != "" && ! -e "$path/$1" ]]; do
path=${path%/*}
done
echo "$path"
}

if [ "$1" = "init" ] || [ "$1" = "down" ]; then
DKTL_PROJECT_DIRECTORY=$(pwd)
else
DKTL_PROJECT_DIRECTORY=$(find_up dktl.yml)
if [ -z "$DKTL_PROJECT_DIRECTORY" ]; then
echo "DKTL is running outside of a DKTL project. Run dktl init in the project directory first."
exit 1
fi
fi
fi
export DKTL_PROJECT_DIRECTORY
}

# Set DKTL_DIRECTORY
set_directory() {
DKTL_DIRECTORY=$(which dktl)
if [ -z "$DKTL_DIRECTORY" ]; then
DKTL_DIRECTORY=$(which dktl)

if [[ -L $(which dktl) ]]; then
# readlink command needs -f to work properly in linux
if [ "$PLATFORM" = "Linux" ]; then RL_OPT='-f'; fi;
DKTL_DIRECTORY=$(readlink $RL_OPT "$DKTL_DIRECTORY")
fi
if [[ -L $(which dktl) ]]; then
# readlink command needs -f to work properly in linux
if [ "$PLATFORM" = "Linux" ]; then RL_OPT='-f'; fi;
DKTL_DIRECTORY=$(readlink $RL_OPT "$DKTL_DIRECTORY")
fi

# Currently DKTL_DIRECTORY contains <path/to/dktl/root>/bin/dktl, strip the
# /bin/dktl to get the root dktl directory.
DKTL_DIRECTORY="${DKTL_DIRECTORY%/bin/dktl}"
# TODO: Figure out a way to modify the path without making assumptions.
# Currently DKTL_DIRECTORY contains <path/to/dktl/root>/bin/dktl, strip the
# /bin/dktl to get the root dktl directory.
DKTL_DIRECTORY="${DKTL_DIRECTORY%/bin/dktl}"
fi

export DKTL_DIRECTORY
}
Expand Down
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"pear/archive_tar": "^1.4",
"aws/aws-sdk-php": "^3.67"
},
"bin": [
"bin/dktl",
"bin/app.php"
],
"autoload": {
"psr-4": {
"DkanTools\\": "src",
Expand All @@ -15,5 +19,8 @@
"platform": {
"php": "7.4"
}
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.7"
}
}
63 changes: 60 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer"
xsi:noNamespaceSchemaLocation="phpcs.xsd">
<description>The coding standard for DKAN Tools.</description>

<exclude-pattern>*/bin/dktl</exclude-pattern>
<exclude-pattern>*/assets</exclude-pattern>
<exclude-pattern>*/vendor</exclude-pattern>


<arg name="basepath" value="."/>
<arg name="colors"/>
<arg name="parallel" value="75"/>

<rule ref="PSR2"/>

<rule ref="Generic.Files.LineLength">
<exclude name="Generic.Files.LineLength.TooLong"/>
</rule>

</ruleset>
3 changes: 1 addition & 2 deletions src/Command/ProjectCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ protected function symlinkOrInstallCypress(): void
if ($result->getExitCode() !== 0) {
throw new \RuntimeException('Failed to symlink cypress package folder');
}
}
else {
} else {
$this->io()->warning('Cypress installation not found in standard location; Attempting to install cypress locally...');
$result = $this->taskExec('npm install cypress')
->dir(self::TESTS_DIR)
Expand Down
16 changes: 11 additions & 5 deletions src/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
class Util
{

const TMP_DIR = "/tmp/dktl";

public static function getDktlDirectory()
Expand All @@ -27,12 +28,13 @@ public static function getDktlProxyDomain()

public static function getProjectDirectory()
{
if ($proj_dir = getenv("DKTL_PROJECT_DIRECTORY")) {
return $proj_dir;
}
if (isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == "init") {
$directory = exec("pwd");
return $directory;
}

return getenv("DKTL_PROJECT_DIRECTORY");
}

public static function getUri()
Expand Down Expand Up @@ -80,7 +82,7 @@ public static function urlExists($url)
$headers = @get_headers($url);
return (count(preg_grep('/^HTTP.*404/', $headers)) > 0) ? false : true;
}

public static function directoryAndFileCreationCheck(\Robo\Result $result, $df, $io)
{
if ($result->getExitCode() == 0 && file_exists($df)) {
Expand All @@ -95,7 +97,11 @@ public static function directoryAndFileCreationCheck(\Robo\Result $result, $df,
*/
public static function generateHashSalt($count = 32)
{
return str_replace(['+', '/', '='], ['-', '_', ''], base64_encode(random_bytes($count)));
return str_replace(['+', '/', '='], [
'-',
'_',
'',
], base64_encode(random_bytes($count)));
}

/**
Expand All @@ -106,7 +112,7 @@ public static function generateHashSalt($count = 32)
public static function ensureFilesExist(array $paths, $message)
{
foreach ($paths as $path) {
if (! file_exists($path)) {
if (!file_exists($path)) {
throw new \Exception("{$path} is missing.");
}
}
Expand Down