diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..dd9a2b5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.{yml,yaml}] +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..c09f81e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,20 @@ +# Path-based git attributes +# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html + +# Ignore all test and documentation with "export-ignore". +/.github export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/phpunit.xml.dist export-ignore +/art export-ignore +/docs export-ignore +/tests export-ignore +/workbench export-ignore +/.editorconfig export-ignore +/.php_cs.dist.php export-ignore +/psalm.xml export-ignore +/psalm.xml.dist export-ignore +/testbench.yaml export-ignore +/UPGRADING.md export-ignore +/phpstan.neon.dist export-ignore +/phpstan-baseline.neon export-ignore diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..ef22319 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: uselagoon diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml new file mode 100644 index 0000000..fe4cfe6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -0,0 +1,66 @@ +name: Bug Report +description: Report an Issue or Bug with the Package +title: "[Bug]: " +labels: ["bug"] +body: + - type: markdown + attributes: + value: | + We're sorry to hear you have a problem. Can you help us solve it by providing the following details. + - type: textarea + id: what-happened + attributes: + label: What happened? + description: What did you expect to happen? + placeholder: I cannot currently do X thing because when I do, it breaks X thing. + validations: + required: true + - type: textarea + id: how-to-reproduce + attributes: + label: How to reproduce the bug + description: How did this occur, please add any config values used and provide a set of reliable steps if possible. + placeholder: When I do X I see Y. + validations: + required: true + - type: input + id: package-version + attributes: + label: Package Version + description: What version of our Package are you running? Please be as specific as possible + placeholder: 2.0.0 + validations: + required: true + - type: input + id: php-version + attributes: + label: PHP Version + description: What version of PHP are you running? Please be as specific as possible + placeholder: 8.2.0 + validations: + required: true + - type: input + id: laravel-version + attributes: + label: Laravel Version + description: What version of Laravel are you running? Please be as specific as possible + placeholder: 9.0.0 + validations: + required: true + - type: dropdown + id: operating-systems + attributes: + label: Which operating systems does with happen with? + description: You may select more than one. + multiple: true + options: + - macOS + - Windows + - Linux + - type: textarea + id: notes + attributes: + label: Notes + description: Use this field to provide any other notes that you feel might be relevant to the issue. + validations: + required: false diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..2a41515 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,11 @@ +blank_issues_enabled: false +contact_links: + - name: Ask a question + url: https://github.com/uselagoon/sailinglagoon/discussions/new?category=q-a + about: Ask the community for help + - name: Request a feature + url: https://github.com/uselagoon/sailinglagoon/discussions/new?category=ideas + about: Share ideas for new features + - name: Report a security issue + url: https://github.com/uselagoon/sailinglagoon/security/policy + about: Learn how to notify us for sensitive bugs diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..41fa8a4 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,55 @@ +name: run-tests + +on: + push: + paths: + - '**.php' + - '.github/workflows/run-tests.yml' + - 'phpunit.xml.dist' + - 'composer.json' + - 'composer.lock' + +jobs: + test: + runs-on: ${{ matrix.os }} + timeout-minutes: 5 + strategy: + fail-fast: true + matrix: + os: [ubuntu-latest] + php: [8.3, 8.2, 8.1] + laravel: [10.*] + stability: [prefer-stable] + include: + - laravel: 10.* + testbench: 8.* + carbon: ^2.63 + + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo + coverage: none + + - name: Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update + composer update --${{ matrix.stability }} --prefer-dist --no-interaction + + - name: List Installed Dependencies + run: composer show -D + + - name: Execute tests + run: vendor/bin/pest --ci diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a7f372d --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +.idea +.phpunit.cache +build +composer.lock +coverage +docs +phpunit.xml +phpstan.neon +testbench.yaml +vendor +node_modules diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..61f6d47 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# Changelog + +All notable changes to `sailinglagoon` will be documented in this file. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..82a9b98 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,45 @@ +# Contributing to Sail on Lagoon + +Welcome to Sail on Lagoon! We appreciate your interest in contributing to this project. Please take a moment to review the guidelines below for contributing. + +## How to Contribute + +### Reporting Issues + +If you encounter a bug or have a feature request, please [open an issue](https://github.com/bomoko/sailinglagoon/issues) on GitHub. Before creating a new issue, search existing ones to avoid duplicates. + +When reporting an issue, include: + +- Detailed description of the issue. +- Steps to reproduce the issue. +- Expected behavior. +- Any relevant screenshots or error messages. + +### Submitting Pull Requests (PRs) + +We welcome pull requests that address bugs, add new features, or improve existing code. To submit a PR: + +1. Fork the repository to your GitHub account. +2. Create a new branch for your feature or fix (`git checkout -b feature/YourFeature`). +3. Make your changes and ensure code follows project coding standards. +4. Write tests for your changes if applicable. +5. Commit your changes (`git commit -am 'Add some feature'`). +6. Push to the branch (`git push origin feature/YourFeature`). +7. Submit a pull request to the `main` branch of the original repository. + +### Coding Standards + +- Follow the coding style and conventions used in the project. +- Write clear, concise, and meaningful commit messages. +- Keep code clean, readable, and maintainable. +- Write tests if appropriate + +### Pull Request Review Process + +All PRs will be reviewed by project maintainers. Feedback and discussions may occur before changes are accepted. + +## Resources + +- [Issue Tracker](https://github.com/bomoko/sailinglagoon/issues) +- [License](LICENSE) + diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..2aa046e --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) uselagoon + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..5f27661 --- /dev/null +++ b/README.md @@ -0,0 +1,67 @@ +# Sail on Lagoon + +[![Latest Version on Packagist](https://img.shields.io/packagist/v/bomoko/sailinglagoon.svg?style=flat-square)](https://packagist.org/packages/bomoko/sailinglagoon) +[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/bomoko/sailinglagoon/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/bomoko/sailinglagoon/actions?query=workflow%3Arun-tests+branch%3Amain) +[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/bomoko/sailinglagoon/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/bomoko/sailinglagoon/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain) +[![Total Downloads](https://img.shields.io/packagist/dt/bomoko/sailinglagoon.svg?style=flat-square)](https://packagist.org/packages/bomoko/sailinglagoon) + +Sail on Lagoon is a Laravel extension that simplifies the process of Lagoonizing Laravel sites +that are already using Laravel Sail to generate their docker-compose setup. +This extension provides additional features and configurations tailored for Lagoon environments. + +## Installation + +The assumption is that you've already set up your Laravel development environment locally using [Sail](https://laravel.com/docs/11.x/sail). + +Once you have your Laravel site running locally, you can install `Sail on Lagoon` via composer: + +```bash +composer require bomoko/sailinglagoon +``` + +To use Sail on Lagoon, run the following Artisan command: + +```bash +php artisan sail:onlagoon [--projectName=my-lagoon-project] [--no-interaction] +``` + +This will read your sail generated docker-compose.yml file and attempt to generate the required files for a Lagoon installation. +You can, optionally, specify the name of your project and skip the interactive question. +Specifying `--no-interaction` will skip any interaction (including warnings) and Lagoonize the project. + +## Supported Services + +Sail-on-Lagoon currently supports the following service types: + + MySQL + PostgreSQL + MariaDB + Redis + MeiliSearch + +## Testing + +```bash +composer test +``` + +## Changelog + +Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. + +## Contributing + +Please see [CONTRIBUTING](CONTRIBUTING.md) for details. + +## Security Vulnerabilities + +Please review [our security policy](../../security/policy) on how to report security vulnerabilities. + +## Credits + +- [Blaize Kaye](https://github.com/bomoko) +- [All Contributors](../../contributors) + +## License + +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..5c48b1c --- /dev/null +++ b/composer.json @@ -0,0 +1,80 @@ +{ + "name": "bomoko/sailinglagoon", + "description": "Sail on Lagoon", + "keywords": [ + "uselagoon", + "laravel", + "sailinglagoon" + ], + "homepage": "https://github.com/bomoko/sailinglagoon", + "license": "MIT", + "authors": [ + { + "name": "Blaize Kaye", + "email": "blaize.kaye@amazee.io", + "role": "Developer" + } + ], + "require": { + "php": "^8.1", + "spatie/laravel-package-tools": "^1.14.0", + "illuminate/contracts": "^10.0||^11.0" + }, + "require-dev": { + "laravel/pint": "^1.0", + "nunomaduro/collision": "^7.8", + "orchestra/testbench": "^8.8", + "pestphp/pest": "^2.20", + "pestphp/pest-plugin-arch": "^2.5", + "pestphp/pest-plugin-laravel": "^2.0" + }, + "autoload": { + "psr-4": { + "Uselagoon\\Sailinglagoon\\": "src/", + "Uselagoon\\Sailinglagoon\\Database\\Factories\\": "database/factories/" + } + }, + "autoload-dev": { + "psr-4": { + "Uselagoon\\Sailinglagoon\\Tests\\": "tests/", + "Workbench\\App\\": "workbench/app/" + } + }, + "scripts": { + "post-autoload-dump": "@composer run prepare", + "clear": "@php vendor/bin/testbench package:purge-sailinglagoon --ansi", + "prepare": "@php vendor/bin/testbench package:discover --ansi", + "build": [ + "@composer run prepare", + "@php vendor/bin/testbench workbench:build --ansi" + ], + "start": [ + "Composer\\Config::disableProcessTimeout", + "@composer run build", + "@php vendor/bin/testbench serve" + ], + "analyse": "vendor/bin/phpstan analyse", + "test": "vendor/bin/pest", + "test-coverage": "vendor/bin/pest --coverage", + "format": "vendor/bin/pint" + }, + "config": { + "sort-packages": true, + "allow-plugins": { + "pestphp/pest-plugin": true, + "phpstan/extension-installer": true + } + }, + "extra": { + "laravel": { + "providers": [ + "Uselagoon\\Sailinglagoon\\SailinglagoonServiceProvider" + ], + "aliases": { + "Sailinglagoon": "Uselagoon\\Sailinglagoon\\Facades\\Sailinglagoon" + } + } + }, + "minimum-stability": "dev", + "prefer-stable": true +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..93ad1fc --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,38 @@ + + + + + tests + + + + + + + + + + + + + + + ./src + + + diff --git a/src/Commands/SailinglagoonCommand.php b/src/Commands/SailinglagoonCommand.php new file mode 100644 index 0000000..5cb726e --- /dev/null +++ b/src/Commands/SailinglagoonCommand.php @@ -0,0 +1,233 @@ + 'Not yet implemented', + 'selenium' => 'Selenium on Lagoon requires customization - see Lagoon documentation', + 'soketi' => 'Soketi is not yet supported', + 'memcached' => 'On Lagoon we encourage the adoption of Redis as a caching backend', + ]; + + /** @var string[] $defaultServices keeps track of services in lagoon that should always exist for Laravel installations */ + protected $defaultServices = [ + 'cli', + 'php', + 'nginx', + ]; + + /** + * The name and signature of the console command. + * + * @var string + */ + protected $signature = 'sail:onlagoon {--projectName=}'; + + /** + * The console command description. + * + * @var string + */ + protected $description = 'This will read your docker-compose.yaml file and attempt to generate the required files for a Lagoon installation'; + + /** + * Execute the console command. + */ + public function handle() + { + $dockerComposeFile = base_path("docker-compose.yml"); + $parsedCompose = Yaml::parseFile($dockerComposeFile); + + // We go through the services defined here and see if we can match them with existing definitions. + if (!key_exists("services", $parsedCompose)) { + throw new \Exception( + "Invalid structure to docker-compose.yml, no services found" + ); + } + + $defaultProjectName = "my-project"; + // Let's see if there already exists some lagoon.yml + $existantInstall = $this->loadExisting(base_path()); + if($existantInstall != false) { + $this->warn("Warning, it seems as though there is already a .lagoon.yml present"); + $this->warn("Continuing with this process could cause loss of Lagoon configuration information."); + if($this->option("no-interaction") == true) { + $this->error("If running in no-interaction, please remove .lagoon.yml to continue"); + return; + } else { + if(!$this->confirm("Continue?")) { + return; + } + } + if(!empty($existantInstall['project'])) { + $defaultProjectName = $existantInstall['project']; + } + } + + // ensure that the user has set their options + $projectName = $this->option('projectName'); + if(empty($projectName)) { + if($this->option("no-interaction") == true) { + $this->error("If using 'no-interaction', please ensure you've set a project name using the `--projectName=` option"); + return 1; + } + $projectName = $this->ask("Please enter a project name", $defaultProjectName); + } + + $services = collect(array_keys($parsedCompose['services']))->merge($this->defaultServices); + + // Here we ensure that none of the incoming services aren't on our unsupported list + $disallowedServices = array_intersect(array_keys($parsedCompose['services']), array_keys($this->unsupportedServices)); + if(count($disallowedServices) > 0) { + $this->info("The following unsupported services have been detected:"); + foreach ($disallowedServices as $key) { + $this->info(sprintf("* %s: %s", $key, $this->unsupportedServices[$key])); + } + if($this->option("no-interaction") == false && !$this->confirm("Continue Lagoonizing while ignoring these services?", true)) { + $this->error("Will not continue"); + return 1; + } + } + + //Let's build the service list and then parse + $stubsRootPath = join_paths(__DIR__, "sailingLagoonAssets/stubs"); + $yamlFile = file_get_contents(join_paths($stubsRootPath, "docker-compose.stub")); + + $dockerComposeFile = $this->generateDockerCompose($services, $stubsRootPath, $yamlFile); + + if(!file_put_contents(join_paths(base_path(), $this->dockerComposeName), Yaml::dump($dockerComposeFile,5))) { + throw new \Exception("Unable to write docker-compose file"); + } + + $this->info(sprintf("Successfully created %s", $this->dockerComposeName)); + + // Let's now do the same for env stubs + + $stubsRootPath = join_paths(__DIR__, "sailingLagoonAssets/envstubs"); + $stubContents = ""; + foreach ($services as $serviceName) { + $stubPath = join_paths($stubsRootPath, $serviceName.".stub"); + if(file_exists($stubPath)) { + $stubContents .= sprintf("\n## %s\n\n%s\n", $serviceName, file_get_contents($stubPath)); + } + } + if(!empty($stubContents)) { + file_put_contents(join_paths(base_path(), ".lagoon.env"), $stubContents); + } + + // now let's copy the files we require to build everything to .lagoon + $copySource = join_paths(__DIR__, "sailingLagoonAssets", "Lagoon"); + $copyDest = join_paths(base_path(), "lagoon"); + + if(File::copyDirectory($copySource, $copyDest)) { + $this->info("Successfully copied Lagoon assets to .lagoon"); + } + + // Let's generate the .lagoon.yml file + $lagoonYml = file_get_contents(join_paths(__DIR__, "sailingLagoonAssets",".lagoon.yml")); + $replacements = [ + '%projectName%' => $projectName, + ]; + + $lagoonYml = str_replace(array_keys($replacements), $replacements, $lagoonYml); + + + if(file_put_contents(join_paths(base_path(), ".lagoon.yml"), $lagoonYml)) { + $this->info("Successfully created .lagoon.yml"); + } + + return true; + } + + /** + * @param $services + * @param Collection $existentServices + * @return array + */ + public function removeUnusedServiceDependencies($services, Collection $existentServices): array + { + foreach ($services as $serviceName => &$service) { + if (key_exists("depends_on", $service)) { + $dependsOnNew = []; + for ($i = 0; $i < count($service["depends_on"]); $i++) { + if (in_array($service["depends_on"][$i], $existentServices->toArray())) { + $dependsOnNew[] = $service["depends_on"][$i]; + } + } + if (count($dependsOnNew) > 0) { + $service["depends_on"] = $dependsOnNew; + } else { + unset($service["depends_on"]); + } + } + } + return $services; + } + + /** + * Checks for an existing lagoon.yml file and returns a parsed version of it + * @param $baseDir + * @return false|mixed + */ + public function loadExisting($baseDir) { + //search for existing .lagoon.yml file in base + $lagoonYmlFile = join_paths($baseDir, ".lagoon.yml"); + if(file_exists($lagoonYmlFile)) { + $currentLagoonYml = file_get_contents($lagoonYmlFile); + $parsedCurrentLagoonYml = Yaml::parse($currentLagoonYml); + return $parsedCurrentLagoonYml; + } + return FALSE; + } + + /** + * @param Collection $services + * @param string $stubsRootPath + * @param string $yamlFile + * @param mixed $dockerComposeFile + * @return array + */ + public function generateDockerCompose(Collection $services, string $stubsRootPath, string $yamlFile): mixed + { + foreach ($services as $serviceName) { + $stubPath = join_paths($stubsRootPath, $serviceName . ".stub"); + if (file_exists($stubPath)) { + $yamlFile .= file_get_contents($stubPath); + } + } + $dockerComposeFile = Yaml::parse($yamlFile); + // now we go through the services and remove any depends on that doesn't appear in our total service list + $serviceList = $dockerComposeFile["services"]; + $dockerComposeFile["services"] = self::removeUnusedServiceDependencies($serviceList, $services); + return $dockerComposeFile; + } + +} diff --git a/src/Commands/sailingLagoonAssets/.lagoon.env b/src/Commands/sailingLagoonAssets/.lagoon.env new file mode 100644 index 0000000..e69de29 diff --git a/src/Commands/sailingLagoonAssets/.lagoon.yml b/src/Commands/sailingLagoonAssets/.lagoon.yml new file mode 100644 index 0000000..26c67e2 --- /dev/null +++ b/src/Commands/sailingLagoonAssets/.lagoon.yml @@ -0,0 +1,22 @@ +docker-compose-yaml: ./lagoon-docker-compose.yml + +project: %projectName% + + +tasks: + post-rollout: + - run: + name: Prepare Storage + command: mkdir -p /app/storage/framework/sessions /app/storage/framework/views /app/storage/framework/cache /app/storage/framework/cache/data + service: cli + shell: bash + - run: + name: Run migrations + command: php artisan -n migrate --force + service: cli + shell: bash + - run: + name: Clear Caches + command: php artisan -n cache:clear && php artisan -n route:clear && php artisan -n view:cache + service: cli + shell: bash diff --git a/src/Commands/sailingLagoonAssets/Lagoon/01-entry-point-setup-laravel.sh b/src/Commands/sailingLagoonAssets/Lagoon/01-entry-point-setup-laravel.sh new file mode 100644 index 0000000..8656d30 --- /dev/null +++ b/src/Commands/sailingLagoonAssets/Lagoon/01-entry-point-setup-laravel.sh @@ -0,0 +1,109 @@ +#!/bin/sh + +# Loading environment variables from .env and friends +source /lagoon/entrypoints/50-dotenv.sh + +# Generate some additional enviornment variables +source /lagoon/entrypoints/55-generate-env.sh + +if [ -z "$APP_URL" ]; then + echo "Settng APP_URL to $LAGOON_ROUTE" + export APP_URL=$LAGOON_ROUTE + + if [ -f "/app/.env" ]; then + APP_URL_EXISTS=`grep APP_URL .env || echo` + fi + + if [ -z "$APP_URL_EXISTS" ]; then + echo "APP_URL=$LAGOON_ROUTE" >> /app/.env + fi +fi + +if [ "$APP_ENV" == "local" ]; then + echo "Settng local APP_ENV to $LAGOON_ENVIRONMENT" + export APP_ENV=$LAGOON_ENVIRONMENT + + if [ -f "/app/.env" ]; then + APP_ENV_EXISTS=`grep APP_ENV .env || echo` + fi + + if [ -z "$APP_ENV_EXISTS" ]; then + echo "APP_ENV=$LAGOON_ENVIRONMENT" >> /app/.env + fi +fi + +if [ -z $APP_ENVA ]; then + echo "Settng empty APP_ENV to $LAGOON_ENVIRONMENT" + export APP_ENV=$LAGOON_ENVIRONMENT + + if [ -f "/app/.env" ]; then + APP_ENV_EXISTS=`grep APP_ENV .env || echo` + fi + + if [ -z "$APP_ENV_EXISTS" ]; then + echo "APP_ENV=$LAGOON_ENVIRONMENT" >> /app/.env + fi +fi + +mkdir -p /app/storage/framework/sessions +mkdir -p /app/storage/framework/views +mkdir -p /app/storage/framework/cache +mkdir -p /app/storage/framework/cache/data +mkdir -p /app/storage/app/public +mkdir -p /app/storage/logs +mkdir -p /app/storage/debugbar +mkdir -p /app/storage/img + +fix-permissions /app/storage/framework +fix-permissions /app/storage/app +fix-permissions /app/storage/logs +fix-permissions /app/storage/debugbar +fix-permissions /app/storage/img + +cd /app + +if [ -f "artisan" ] && [ "$LAGOON_ENVIRONMENT" != "local" ] ; then + php artisan config:clear + php artisan route:clear + php artisan view:clear + php artisan event:clear + php artisan optimize:clear +fi + +if [ "$LAGOON_ENVIRONMENT_TYPE" == "production" ]; then + if [ -f "artisan" ]; then + php artisan config:cache + php artisan route:cache + php artisan view:cache + php artisan event:cache + php artisan optimize + fi +elif [ "$LAGOON_LARAVEL_SEED_DB" == "true" ] && [ "$LAGOON_ENVIRONMENT_TYPE" == "development" ] && [ "$SERVICE_NAME" == "cli" ]; then + if [ -f "artisan" ]; then + TABLES=`echo "show tables" | mysql -h$DB_HOST -u$DB_USERNAME -p$DB_PASSWORD $DB_DATABASE` + + if [ -z "$TABLES" ]; then + echo "Loading up a new database" + php artisan db:seed + else + echo "There is already a database loaded up" + fi + else + echo "Skipping DB loading check - Laravel is not installed" + fi +fi + + +if [ -f "artisan" ] && [ -z "$APP_KEY" ]; then + APP_KEY=`php artisan key:generate --show --no-ansi` + echo "Settng APP_KEY to $APP_KEY" + export APP_KEY=$APP_KEY + + if [ -f "/app/.env" ]; then + APP_KEY_EXISTS=`grep APP_KEY .env || echo` + fi + + if [ -z "$APP_KEY_EXISTS" ]; then + echo "APP_KEY=$APP_KEY" >> /app/.env + fi +fi diff --git a/src/Commands/sailingLagoonAssets/Lagoon/README.md b/src/Commands/sailingLagoonAssets/Lagoon/README.md new file mode 100644 index 0000000..1cf7e35 --- /dev/null +++ b/src/Commands/sailingLagoonAssets/Lagoon/README.md @@ -0,0 +1,4 @@ +# SailingLagoon Assets + +This directory contains all the files needed to build any of the images etc. +built by the resulting docker-compose.yml for Lagoon. diff --git a/src/Commands/sailingLagoonAssets/Lagoon/cli.dockerfile b/src/Commands/sailingLagoonAssets/Lagoon/cli.dockerfile new file mode 100644 index 0000000..ca2910d --- /dev/null +++ b/src/Commands/sailingLagoonAssets/Lagoon/cli.dockerfile @@ -0,0 +1,50 @@ +FROM uselagoon/lagoon-cli:latest as LAGOONCLI +FROM uselagoon/php-8.3-cli + +####################################################### +# Install PHP extensions +####################################################### +RUN docker-php-ext-install pcntl +RUN docker-php-ext-install posix +RUN docker-php-ext-install exif + +####################################################### +# Setup Laravel Directories needed for composer install +####################################################### +RUN mkdir -p /app/storage/framework/sessions +RUN mkdir -p /app/storage/framework/views +RUN mkdir -p /app/storage/framework/cache +RUN mkdir -p /app/storage/app/public +RUN mkdir -p /home/.config/psysh +RUN fix-permissions /home/.config/psysh + +####################################################### +# Install Lagoon Tools Globally +####################################################### +# Lagoon CLI +COPY --from=LAGOONCLI /lagoon /usr/bin/lagoon + +# Lagoon Sync +RUN DOWNLOAD_PATH=$(curl -sL "https://api.github.com/repos/uselagoon/lagoon-sync/releases/latest" | grep "browser_download_url" | cut -d \" -f 4 | grep linux_386) && wget -O /usr/bin/lagoon-sync $DOWNLOAD_PATH && chmod +x /usr/bin/lagoon-sync + +####################################################### +# Copy files, and run installs for composer and yarn +####################################################### +COPY . /app +RUN if [ -f "composer.json" ]; then \ + COMPOSER_MEMORY_LIMIT=-1 composer install --no-interaction --prefer-dist --optimize-autoloader; \ + php artisan storage:link; \ + fi + +RUN if [ -f "package.json" ]; then \ + npm install; \ + npm ci; \ + npm run build; \ + fi + +####################################################### +# Finalize Environment +####################################################### +COPY lagoon/01-entry-point-setup-laravel.sh /lagoon/entrypoints/98-env-setup-laravel.sh +ENV WEBROOT=public +# ENV PHP_MEMORY_LIMIT=8192M diff --git a/src/Commands/sailingLagoonAssets/Lagoon/nginx-laravel.conf b/src/Commands/sailingLagoonAssets/Lagoon/nginx-laravel.conf new file mode 100644 index 0000000..0caf85f --- /dev/null +++ b/src/Commands/sailingLagoonAssets/Lagoon/nginx-laravel.conf @@ -0,0 +1,31 @@ +server { + listen ${NGINX_LISTEN:-8080} default_server; + + include /etc/nginx/helpers/*.conf; + + root /app/${WEBROOT:-}; + index index.php; + + + ## The 'default' location. + location / { + ## Disallow access to any dot files, but send the request to laravel + location ~* /\. { + try_files /dev/null @php; + } + + ## Direct Access to .php files is not alled and is sent to laravel instead + location ~* ^.+\.php$ { + try_files /dev/null @php; + } + + ## Try to find a file with given URL, if not pass to laravel + try_files $uri $uri/ /index.php?$args; + } + + ## PHP Location + location @php { + include /etc/nginx/fastcgi.conf; + fastcgi_pass ${NGINX_FASTCGI_PASS:-php}:9000; + } +} diff --git a/src/Commands/sailingLagoonAssets/Lagoon/nginx.dockerfile b/src/Commands/sailingLagoonAssets/Lagoon/nginx.dockerfile new file mode 100644 index 0000000..d17e163 --- /dev/null +++ b/src/Commands/sailingLagoonAssets/Lagoon/nginx.dockerfile @@ -0,0 +1,18 @@ +ARG CLI_IMAGE +FROM ${CLI_IMAGE} as cli +FROM amazeeio/nginx + +####################################################### +# Customize Nginx to Laravel Land +####################################################### +COPY lagoon/nginx-laravel.conf /etc/nginx/conf.d/app.conf + +####################################################### +# Copy the prebuild laravel app to the Nginx container +####################################################### +COPY --from=cli /app /app + +####################################################### +# Finalize Environment +####################################################### +ENV WEBROOT=public diff --git a/src/Commands/sailingLagoonAssets/Lagoon/php.dockerfile b/src/Commands/sailingLagoonAssets/Lagoon/php.dockerfile new file mode 100644 index 0000000..8845d87 --- /dev/null +++ b/src/Commands/sailingLagoonAssets/Lagoon/php.dockerfile @@ -0,0 +1,23 @@ +ARG CLI_IMAGE +FROM ${CLI_IMAGE} as cli +FROM uselagoon/php-8.3-fpm + +####################################################### +# Setup Laravel Directories needed +####################################################### +RUN mkdir -p /app/storage/framework/sessions +RUN mkdir -p /app/storage/framework/views +RUN mkdir -p /app/storage/framework/cache +RUN mkdir -p /app/storage/app/public +RUN mkdir -p /home/.config/psysh +RUN fix-permissions /home/.config/psysh + +####################################################### +# Copy the prebuild laravel app to the Nginx container +####################################################### +COPY --from=cli /app /app + +####################################################### +# Finalize Environment +####################################################### +COPY lagoon/01-entry-point-setup-laravel.sh /lagoon/entrypoints/98-env-setup-laravel.sh diff --git a/src/Commands/sailingLagoonAssets/Lagoon/redis.dockerfile b/src/Commands/sailingLagoonAssets/Lagoon/redis.dockerfile new file mode 100644 index 0000000..71e4dd1 --- /dev/null +++ b/src/Commands/sailingLagoonAssets/Lagoon/redis.dockerfile @@ -0,0 +1,8 @@ +FROM amazeeio/redis-persistent + +####################################################### +# Finalize Environment +####################################################### + +# Horizon runs nicely with multiple databases +ENV DATABASES=5 diff --git a/src/Commands/sailingLagoonAssets/Lagoon/tasks/post-rollout-non-prod b/src/Commands/sailingLagoonAssets/Lagoon/tasks/post-rollout-non-prod new file mode 100644 index 0000000..716de31 --- /dev/null +++ b/src/Commands/sailingLagoonAssets/Lagoon/tasks/post-rollout-non-prod @@ -0,0 +1,19 @@ +#!/bin/sh + +# This script is run by lagoon as a POST-ROLLOUT task for non-production +# It runs in the CLI container only (so not the worker, or the PHP container) + +cd /app + +# Loading environment variables from .env and friends +source /lagoon/entrypoints/50-dotenv.sh + +# Generate some additional enviornment variables +source /lagoon/entrypoints/55-generate-env.sh + +# NB: See /app/lagoon/entry-point-setup-laravel.sh for more insight into +# container startup scripts that cache views, run migrations, load the db +# if it is blank, etc, etc + +### Additional Post Rollout +php artisan migrate --force diff --git a/src/Commands/sailingLagoonAssets/Lagoon/tasks/post-rollout-prod b/src/Commands/sailingLagoonAssets/Lagoon/tasks/post-rollout-prod new file mode 100644 index 0000000..db3ecc1 --- /dev/null +++ b/src/Commands/sailingLagoonAssets/Lagoon/tasks/post-rollout-prod @@ -0,0 +1,15 @@ +#!/bin/sh + +# This script is run by lagoon as a POST-ROLLOUT task for non-production +# It runs in the CLI container only (so not the worker, or the PHP container) + +cd /app + +# Loading environment variables from .env and friends +source /lagoon/entrypoints/50-dotenv.sh + +# Generate some additional enviornment variables +source /lagoon/entrypoints/55-generate-env.sh + +# Run production migrations automatically in prod +php artisan migrate --force diff --git a/src/Commands/sailingLagoonAssets/Lagoon/workers/start-horizon.sh b/src/Commands/sailingLagoonAssets/Lagoon/workers/start-horizon.sh new file mode 100644 index 0000000..d5d6ad9 --- /dev/null +++ b/src/Commands/sailingLagoonAssets/Lagoon/workers/start-horizon.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +# LAGOON_ENVIRONMENT_TYPE="TEST" + +if [ -f "/app/config/horizon.php" ]; then + /usr/local/bin/php artisan horizon +else + echo "Horizon is not installed"; + sleep 10 +fi diff --git a/src/Commands/sailingLagoonAssets/Lagoon/workers/start-schedule.sh b/src/Commands/sailingLagoonAssets/Lagoon/workers/start-schedule.sh new file mode 100644 index 0000000..bd7a262 --- /dev/null +++ b/src/Commands/sailingLagoonAssets/Lagoon/workers/start-schedule.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +# LAGOON_ENVIRONMENT_TYPE="TEST" + +if [ -f "/app/artisan" ]; then + /usr/local/bin/php artisan schedule:work +else + echo "Laravel is not installed"; + sleep 10 +fi diff --git a/src/Commands/sailingLagoonAssets/Lagoon/workers/status-horizon.sh b/src/Commands/sailingLagoonAssets/Lagoon/workers/status-horizon.sh new file mode 100644 index 0000000..e32291e --- /dev/null +++ b/src/Commands/sailingLagoonAssets/Lagoon/workers/status-horizon.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +if [ -f "/app/config/horizon.php" ]; then + COUNT=`ps ax | grep horizon:work | grep -v grep | wc -l` + + if [ $COUNT -gt 0 ]; then + echo Horizon is running + else + echo Horizon is not running + fi +else + echo "[Status] - Horizon is not installed"; + sleep 10 +fi diff --git a/src/Commands/sailingLagoonAssets/envstubs/cli.stub b/src/Commands/sailingLagoonAssets/envstubs/cli.stub new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/Commands/sailingLagoonAssets/envstubs/cli.stub @@ -0,0 +1 @@ + diff --git a/src/Commands/sailingLagoonAssets/envstubs/mariadb.stub b/src/Commands/sailingLagoonAssets/envstubs/mariadb.stub new file mode 100644 index 0000000..9a7128d --- /dev/null +++ b/src/Commands/sailingLagoonAssets/envstubs/mariadb.stub @@ -0,0 +1,5 @@ +DB_HOST="${MARIADB_HOST:-mariadb}" +DB_PORT="${MARIADB_PORT:-3306}" +DB_DATABASE="${MARIADB_DATABASE:-lagoon}" +DB_USERNAME="${MARIADB_USERNAME:-lagoon}" +DB_PASSWORD="${MARIADB_PASSWORD:-lagoon}" diff --git a/src/Commands/sailingLagoonAssets/envstubs/meilisearch.stub b/src/Commands/sailingLagoonAssets/envstubs/meilisearch.stub new file mode 100644 index 0000000..85bc2eb --- /dev/null +++ b/src/Commands/sailingLagoonAssets/envstubs/meilisearch.stub @@ -0,0 +1,3 @@ +SCOUT_DRIVER=meilisearch +MEILISEARCH_HOST=http://meilisearch:7700 +MEILISEARCH_NO_ANALYTICS=false diff --git a/src/Commands/sailingLagoonAssets/envstubs/mysql.stub b/src/Commands/sailingLagoonAssets/envstubs/mysql.stub new file mode 100644 index 0000000..9a7128d --- /dev/null +++ b/src/Commands/sailingLagoonAssets/envstubs/mysql.stub @@ -0,0 +1,5 @@ +DB_HOST="${MARIADB_HOST:-mariadb}" +DB_PORT="${MARIADB_PORT:-3306}" +DB_DATABASE="${MARIADB_DATABASE:-lagoon}" +DB_USERNAME="${MARIADB_USERNAME:-lagoon}" +DB_PASSWORD="${MARIADB_PASSWORD:-lagoon}" diff --git a/src/Commands/sailingLagoonAssets/envstubs/nginx.stub b/src/Commands/sailingLagoonAssets/envstubs/nginx.stub new file mode 100644 index 0000000..aa04cbd --- /dev/null +++ b/src/Commands/sailingLagoonAssets/envstubs/nginx.stub @@ -0,0 +1 @@ +# No environment vars diff --git a/src/Commands/sailingLagoonAssets/envstubs/php.stub b/src/Commands/sailingLagoonAssets/envstubs/php.stub new file mode 100644 index 0000000..581afc1 --- /dev/null +++ b/src/Commands/sailingLagoonAssets/envstubs/php.stub @@ -0,0 +1 @@ +# No Env Vars diff --git a/src/Commands/sailingLagoonAssets/envstubs/redis.stub b/src/Commands/sailingLagoonAssets/envstubs/redis.stub new file mode 100644 index 0000000..e4c9dec --- /dev/null +++ b/src/Commands/sailingLagoonAssets/envstubs/redis.stub @@ -0,0 +1,3 @@ +# if defined you should already have the env vars: +REDIS_HOST="${REDIS_HOST:-redis}" +REDIS_PORT="${REDIS_PORT:-6379}" diff --git a/src/Commands/sailingLagoonAssets/stubs/README.md b/src/Commands/sailingLagoonAssets/stubs/README.md new file mode 100644 index 0000000..88aa749 --- /dev/null +++ b/src/Commands/sailingLagoonAssets/stubs/README.md @@ -0,0 +1,9 @@ +# Sailing Lagoon Stubs + +Essentially inspired by (stolen from?) Sail's implementation, +this directory contains a number of stubs used to generate the Lagoon specific docker-compose file. + +Each "stub" is a yaml file that should define a service, which is merged into the "services" stanza of the docker-compose.stub file. +This file with all merged services will end up in ./lagoon/docker-compose.yml + +It is generated by looking at the existing docker-compose.yml file in a Sail Laravel installation, and generating the corresponding version of the stubs there. diff --git a/src/Commands/sailingLagoonAssets/stubs/cli.stub b/src/Commands/sailingLagoonAssets/stubs/cli.stub new file mode 100644 index 0000000..209c379 --- /dev/null +++ b/src/Commands/sailingLagoonAssets/stubs/cli.stub @@ -0,0 +1,16 @@ + # SERVICE: cli + cli: + build: + context: . + dockerfile: lagoon/cli.dockerfile + image: &cli-image sailonlagoon + labels: + lagoon.type: cli-persistent + lagoon.persistent.name: nginx + lagoon.persistent: /app/storage + depends_on: + - redis + - mariadb + - worker + - meilisearch + diff --git a/src/Commands/sailingLagoonAssets/stubs/docker-compose.stub b/src/Commands/sailingLagoonAssets/stubs/docker-compose.stub new file mode 100644 index 0000000..0baad47 --- /dev/null +++ b/src/Commands/sailingLagoonAssets/stubs/docker-compose.stub @@ -0,0 +1 @@ +services: diff --git a/src/Commands/sailingLagoonAssets/stubs/mariadb.stub b/src/Commands/sailingLagoonAssets/stubs/mariadb.stub new file mode 100644 index 0000000..c4afacf --- /dev/null +++ b/src/Commands/sailingLagoonAssets/stubs/mariadb.stub @@ -0,0 +1,6 @@ + mariadb: + image: amazeeio/mariadb + labels: + lagoon.type: mariadb + environment: + SERVICE_NAME: worker diff --git a/src/Commands/sailingLagoonAssets/stubs/meilisearch.stub b/src/Commands/sailingLagoonAssets/stubs/meilisearch.stub new file mode 100644 index 0000000..96bcff0 --- /dev/null +++ b/src/Commands/sailingLagoonAssets/stubs/meilisearch.stub @@ -0,0 +1,8 @@ + meilisearch: + image: getmeili/meilisearch:latest + labels: + lagoon.type: basic-persistent + lagoon.persistent: /meili_data + lagoon.service.port: 7700 + lagoon.autogeneratedroute: false + diff --git a/src/Commands/sailingLagoonAssets/stubs/mysql.stub b/src/Commands/sailingLagoonAssets/stubs/mysql.stub new file mode 100644 index 0000000..c4afacf --- /dev/null +++ b/src/Commands/sailingLagoonAssets/stubs/mysql.stub @@ -0,0 +1,6 @@ + mariadb: + image: amazeeio/mariadb + labels: + lagoon.type: mariadb + environment: + SERVICE_NAME: worker diff --git a/src/Commands/sailingLagoonAssets/stubs/nginx.stub b/src/Commands/sailingLagoonAssets/stubs/nginx.stub new file mode 100644 index 0000000..33dcb8f --- /dev/null +++ b/src/Commands/sailingLagoonAssets/stubs/nginx.stub @@ -0,0 +1,17 @@ + # SERVICE: nginx + nginx: + build: + context: . + dockerfile: lagoon/nginx.dockerfile + args: + CLI_IMAGE: *cli-image + labels: + lagoon.type: nginx-php-persistent + lagoon.name: nginx + lagoon.persistent: /app/storage + volumes: + - ./:/app:delegated + depends_on: + - cli + - redis + - mariadb diff --git a/src/Commands/sailingLagoonAssets/stubs/php.stub b/src/Commands/sailingLagoonAssets/stubs/php.stub new file mode 100644 index 0000000..1e63d27 --- /dev/null +++ b/src/Commands/sailingLagoonAssets/stubs/php.stub @@ -0,0 +1,15 @@ + # SERVICE: php + php: + build: + context: . + dockerfile: lagoon/php.dockerfile + args: + CLI_IMAGE: *cli-image + labels: + lagoon.type: nginx-php-persistent + lagoon.name: nginx + lagoon.persistent: /app/storage/ + volumes: + - ./:/app:delegated + depends_on: + - mariadb diff --git a/src/Commands/sailingLagoonAssets/stubs/redis.stub b/src/Commands/sailingLagoonAssets/stubs/redis.stub new file mode 100644 index 0000000..fce391b --- /dev/null +++ b/src/Commands/sailingLagoonAssets/stubs/redis.stub @@ -0,0 +1,7 @@ + redis: + build: + context: . + dockerfile: lagoon/redis.dockerfile + image: amazeeio/redis-persistent + labels: + lagoon.type: redis-persistent diff --git a/src/Commands/sailingLagoonAssets/stubs/worker.stub b/src/Commands/sailingLagoonAssets/stubs/worker.stub new file mode 100644 index 0000000..7920ff7 --- /dev/null +++ b/src/Commands/sailingLagoonAssets/stubs/worker.stub @@ -0,0 +1,16 @@ + worker: + build: + context: . + dockerfile: lagoon/worker.dockerfile + args: + CLI_IMAGE: *cli-image + labels: + lagoon.type: worker-persistent + lagoon.name: worker + lagoon.persistent.name: nginx + lagoon.persistent: /app/storage/ + depends_on: + - cli + - redis + - mariadb + diff --git a/src/Facades/Sailinglagoon.php b/src/Facades/Sailinglagoon.php new file mode 100644 index 0000000..d10247a --- /dev/null +++ b/src/Facades/Sailinglagoon.php @@ -0,0 +1,16 @@ +name('sailinglagoon') + ->hasCommand(SailinglagoonCommand::class); + } +} diff --git a/tests/ArchTest.php b/tests/ArchTest.php new file mode 100644 index 0000000..87fb64c --- /dev/null +++ b/tests/ArchTest.php @@ -0,0 +1,5 @@ +expect(['dd', 'dump', 'ray']) + ->each->not->toBeUsed(); diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php new file mode 100644 index 0000000..5d36321 --- /dev/null +++ b/tests/ExampleTest.php @@ -0,0 +1,5 @@ +toBeTrue(); +}); diff --git a/tests/Pest.php b/tests/Pest.php new file mode 100644 index 0000000..bb26830 --- /dev/null +++ b/tests/Pest.php @@ -0,0 +1,5 @@ +in(__DIR__); diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..cce9009 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,36 @@ + 'Uselagoon\\Sailinglagoon\\Database\\Factories\\'.class_basename($modelName).'Factory' + ); + } + + protected function getPackageProviders($app) + { + return [ + SailinglagoonServiceProvider::class, + ]; + } + + public function getEnvironmentSetUp($app) + { + config()->set('database.default', 'testing'); + + /* + $migration = include __DIR__.'/../database/migrations/create_sailinglagoon_table.php.stub'; + $migration->up(); + */ + } +} diff --git a/tests/Unit/GenTest.php b/tests/Unit/GenTest.php new file mode 100644 index 0000000..7fe8b25 --- /dev/null +++ b/tests/Unit/GenTest.php @@ -0,0 +1,34 @@ + [ + "depends_on" => ["cli", "php", "shouldntexist"] + ] + ]; + + $newServices = $sailingLagoonCommand->removeUnusedServiceDependencies($services, $serviceList); + + expect($newServices["first"]["depends_on"])->not()->toContain("shouldntexist"); + expect($newServices["first"]["depends_on"])->toContain("cli"); +}); + +it("should successfully generate a docker-compose.yaml given stubs", function() { + $sailingLagoonCommand = new SailinglagoonCommand(); + $serviceList = collect(["cli", "mariadb"]); + $yamlFile = file_get_contents(join_paths(__DIR__, "assets/stubs", "docker-compose.stub")); + $dockerCompose = $sailingLagoonCommand->generateDockerCompose($serviceList, + join_paths(__DIR__, "assets/stubs"), $yamlFile); + + $yamlOutput = Yaml::dump($dockerCompose, 5); + expect($yamlOutput)->toContain("cli")->toContain("mariadb")->not()->toContain("php"); + +}); diff --git a/tests/Unit/assets/envstubs/cli.stub b/tests/Unit/assets/envstubs/cli.stub new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/Unit/assets/envstubs/cli.stub @@ -0,0 +1 @@ + diff --git a/tests/Unit/assets/envstubs/mariadb.stub b/tests/Unit/assets/envstubs/mariadb.stub new file mode 100644 index 0000000..9a7128d --- /dev/null +++ b/tests/Unit/assets/envstubs/mariadb.stub @@ -0,0 +1,5 @@ +DB_HOST="${MARIADB_HOST:-mariadb}" +DB_PORT="${MARIADB_PORT:-3306}" +DB_DATABASE="${MARIADB_DATABASE:-lagoon}" +DB_USERNAME="${MARIADB_USERNAME:-lagoon}" +DB_PASSWORD="${MARIADB_PASSWORD:-lagoon}" diff --git a/tests/Unit/assets/envstubs/mysql.stub b/tests/Unit/assets/envstubs/mysql.stub new file mode 100644 index 0000000..9a7128d --- /dev/null +++ b/tests/Unit/assets/envstubs/mysql.stub @@ -0,0 +1,5 @@ +DB_HOST="${MARIADB_HOST:-mariadb}" +DB_PORT="${MARIADB_PORT:-3306}" +DB_DATABASE="${MARIADB_DATABASE:-lagoon}" +DB_USERNAME="${MARIADB_USERNAME:-lagoon}" +DB_PASSWORD="${MARIADB_PASSWORD:-lagoon}" diff --git a/tests/Unit/assets/envstubs/nginx.stub b/tests/Unit/assets/envstubs/nginx.stub new file mode 100644 index 0000000..aa04cbd --- /dev/null +++ b/tests/Unit/assets/envstubs/nginx.stub @@ -0,0 +1 @@ +# No environment vars diff --git a/tests/Unit/assets/envstubs/php.stub b/tests/Unit/assets/envstubs/php.stub new file mode 100644 index 0000000..581afc1 --- /dev/null +++ b/tests/Unit/assets/envstubs/php.stub @@ -0,0 +1 @@ +# No Env Vars diff --git a/tests/Unit/assets/stubs/cli.stub b/tests/Unit/assets/stubs/cli.stub new file mode 100644 index 0000000..cc8e39e --- /dev/null +++ b/tests/Unit/assets/stubs/cli.stub @@ -0,0 +1,15 @@ + # SERVICE: cli + cli: + build: + context: . + dockerfile: lagoon/cli.dockerfile + image: &cli-image sailonlagoon + labels: + lagoon.type: cli-persistent + lagoon.persistent.name: nginx + lagoon.persistent: /app/storage + depends_on: + - redis + - mariadb + - worker + diff --git a/tests/Unit/assets/stubs/docker-compose.stub b/tests/Unit/assets/stubs/docker-compose.stub new file mode 100644 index 0000000..0baad47 --- /dev/null +++ b/tests/Unit/assets/stubs/docker-compose.stub @@ -0,0 +1 @@ +services: diff --git a/tests/Unit/assets/stubs/mariadb.stub b/tests/Unit/assets/stubs/mariadb.stub new file mode 100644 index 0000000..c4afacf --- /dev/null +++ b/tests/Unit/assets/stubs/mariadb.stub @@ -0,0 +1,6 @@ + mariadb: + image: amazeeio/mariadb + labels: + lagoon.type: mariadb + environment: + SERVICE_NAME: worker diff --git a/tests/Unit/assets/stubs/mysql.stub b/tests/Unit/assets/stubs/mysql.stub new file mode 100644 index 0000000..c4afacf --- /dev/null +++ b/tests/Unit/assets/stubs/mysql.stub @@ -0,0 +1,6 @@ + mariadb: + image: amazeeio/mariadb + labels: + lagoon.type: mariadb + environment: + SERVICE_NAME: worker diff --git a/tests/Unit/assets/stubs/nginx.stub b/tests/Unit/assets/stubs/nginx.stub new file mode 100644 index 0000000..33dcb8f --- /dev/null +++ b/tests/Unit/assets/stubs/nginx.stub @@ -0,0 +1,17 @@ + # SERVICE: nginx + nginx: + build: + context: . + dockerfile: lagoon/nginx.dockerfile + args: + CLI_IMAGE: *cli-image + labels: + lagoon.type: nginx-php-persistent + lagoon.name: nginx + lagoon.persistent: /app/storage + volumes: + - ./:/app:delegated + depends_on: + - cli + - redis + - mariadb diff --git a/tests/Unit/assets/stubs/php.stub b/tests/Unit/assets/stubs/php.stub new file mode 100644 index 0000000..1e63d27 --- /dev/null +++ b/tests/Unit/assets/stubs/php.stub @@ -0,0 +1,15 @@ + # SERVICE: php + php: + build: + context: . + dockerfile: lagoon/php.dockerfile + args: + CLI_IMAGE: *cli-image + labels: + lagoon.type: nginx-php-persistent + lagoon.name: nginx + lagoon.persistent: /app/storage/ + volumes: + - ./:/app:delegated + depends_on: + - mariadb