Skip to content
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
9 changes: 7 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
APP_NAME=Laravel
APP_NAME=Webapps
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost:8000
APP_URL=http://webapps

APP_LOCALE=en
APP_FALLBACK_LOCALE=en
Expand Down Expand Up @@ -72,6 +72,7 @@ REPLICADO_USERNAME=
REPLICADO_PASSWORD=
REPLICADO_CODUNDCLG=
REPLICADO_SYBASE=
REPLICADO_FAKE=1

SENHAUNICA_KEY=faker
SENHAUNICA_SECRET=faker
Expand All @@ -94,6 +95,10 @@ PORTAINER_URL=http://192.168.0.95:9000
PORTAINER_USERNAME='admin'
PORTAINER_PASSWORD='portainer-agent-stack'

DUSK_DRIVER_URL='http://selenium:4444/wd/hub'
DUSK_START_MAXIMIZED=true
DUSK_HEADLESS_DISABLED=true




65 changes: 65 additions & 0 deletions .github/workflows/dusk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Dusk Tests

on:
push:
pull_request:

jobs:
dusk:
runs-on: ubuntu-latest

env:
SERVICE_NAME: COLOCAR-NOME-DO-SISTEMA-USADO-NO-DOCKER-COMPOSE

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Create .env
run: cp .env.example .env

- name: Add auth.local to hosts to senhaunica-faker works properly
run: |
echo "127.0.0.1 auth.local" | sudo tee -a /etc/hosts

- name: Set UID/GID
run: |
echo "UID=$(id -u)" >> $GITHUB_ENV
echo "GID=$(id -g)" >> $GITHUB_ENV

- name: Build and start containers
run: docker compose up -d --build

- name: Wait for MariaDB
run: |
for i in {1..40}; do
if docker compose exec -T mariadb mariadb -u${{ env.SERVICE_NAME }} -p${{ env.SERVICE_NAME }} -e "SELECT 1;" &> /dev/null; then
echo "MariaDB is ready"
exit 0
fi
echo "Waiting for MariaDB..."
sleep 2
done

- name: Install Composer dependencies
run: docker compose exec -T ${{ env.SERVICE_NAME }} composer install --no-interaction --prefer-dist

- name: Generate APP_KEY
run: docker compose exec -T ${{ env.SERVICE_NAME }} php artisan key:generate

- name: Run migrations
run: docker compose exec -T ${{ env.SERVICE_NAME }} php artisan migrate --force

- name: Install ChromeDriver
run: docker compose exec -T ${{ env.SERVICE_NAME }} php artisan dusk:chrome-driver --detect

- name: Run Dusk
run: docker compose exec -T ${{ env.SERVICE_NAME }} php artisan dusk --without-tty

- name: Show logs on failure
if: failure()
run: docker compose logs

- name: Stop containers
if: always()
run: docker compose down -v
43 changes: 43 additions & 0 deletions app/Actions/AuthenticatePortainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Actions;

use Illuminate\Support\Facades\Http;

class AuthenticatePortainer
{
/**
* Create a new class instance.
*/
public function __construct()
{
//
}

public static function execute()
{
$portainerUrl = env('PORTAINER_URL');
$username = env('PORTAINER_USERNAME');
$password = env('PORTAINER_PASSWORD');

$auth = Http::post(
"{$portainerUrl}/api/auth",
[
'username' => $username,
'password' => $password,
]
);

$jwt = $auth->json('jwt');

$endpoints = Http::withToken($jwt)
->get("{$portainerUrl}/api/endpoints")
->json();
$endpointId = $endpoints[0]['Id'];

return [
'jwt' => $jwt,
'endpointId' => $endpointId
];
}
}
22 changes: 22 additions & 0 deletions app/Actions/CreateDatabaseAppVariables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Actions;

use App\Models\Webapp;
use App\Models\ImageVariable;

class CreateDatabaseAppVariables
{
/**
* Create a new class instance.
*/
public function __construct()
{
//
}

public function execute()
{

}
}
55 changes: 55 additions & 0 deletions app/Actions/GenerateComposeYml.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace App\Actions;

use App\Models\DockerImage;
use App\Models\Webapp;
use Symfony\Component\Yaml\Yaml;

class GenerateComposeYml
{
/**
* Create a new class instance.
*/
public function __construct()
{
//
}

public static function execute(DockerImage $dockerImage, Webapp $webapp)
{
$env_variables = $webapp->appVariables;
$environment = [];
$padrao = '^\{\{.*\}\}$^';
foreach ($env_variables as $env_variable):
if(preg_match($padrao, $env_variable->value)) {
$environment[$env_variable->imageVariable->name] = GetDbVariableValue::execute($env_variable);
} else {
$environment[$env_variable->imageVariable->name] = $env_variable->value;
}
endforeach;



$composeArray = [
'services' => [
'app' => [
'image' => "{$dockerImage->path}:{$dockerImage->tag}",
'restart' => 'unless-stopped',
'ports' => ['8888:80'],
'environment' => $environment,
'entrypoint' => [
'sh',
'-c',
'php artisan migrate --force && exec apache2-foreground'
]
]
]
];

$composeYaml = Yaml::dump($composeArray, 4, 2);
$composeYaml = str_replace("'-c'", "-c", $composeYaml);

return $composeYaml;
}
}
36 changes: 36 additions & 0 deletions app/Actions/GetDbVariableValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Actions;

use App\Models\AppVariable;

class GetDbVariableValue
{
/**
* Create a new class instance.
*/
public function __construct()
{
//
}

public static function execute(AppVariable $variable)
{
$database = $variable->App->AppDatabase;
$variableName = $variable->imageVariable->name;
$variableNameTrimed = trim($variableName, '{}');
if($variableNameTrimed == 'dbuser') {
return $database->user;
}

if($variableNameTrimed == 'dbname') {
return $database->name;
}

if($variableNameTrimed == 'dbpassword') {
return $database->password;
}

return '';
}
}
30 changes: 30 additions & 0 deletions app/Actions/GetGwmariadbPayload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Actions;

class GetGwmariadbPayload
{
/**
* Create a new class instance.
*/
public function __construct()
{
//
}

public static function execute(string $action, string $siteName = '')
{
if($siteName == ''):
$payload = [
'action' => $action
];
else:
$payload = [
'action' => $action,
'nome' => $siteName
];
endif;

return $payload;
}
}
25 changes: 25 additions & 0 deletions app/Actions/SendGwmariadbRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Actions;

use Illuminate\Support\Facades\Http;

class SendGwmariadbRequest
{
/**
* Create a new class instance.
*/
public function __construct()
{
//
}

public static function execute(array $payload)
{
$response = Http::withHeaders([
'X-Token' => env('GWMARIADB_TOKEN'),
])->post(env('GWMARIADB_URL'), $payload);

return $response->json();
}
}
27 changes: 27 additions & 0 deletions app/Actions/StoreAppVariablesOnImageSelection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Actions;

use App\Models\AppVariable;
use App\Models\ImageVariable;
use App\Models\Webapp;

class StoreAppVariablesOnImageSelection
{
/**
* Create a new class instance.
*/
public function __construct()
{
//
}

public static function execute(Webapp $webapp, ImageVariable $imageVariable)
{
AppVariable::create([
'image_variable_id' => $imageVariable->id,
'app_id' => $webapp->id,
'value' => null
]);
}
}
28 changes: 28 additions & 0 deletions app/Http/Controllers/BucketController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class BucketController extends Controller
{
public function index()
{

}

public function store()
{

}

public function update()
{

}

public function test_connection()
{

}
}
Loading