Skip to content

Commit

Permalink
Changed __DIR__ to getcwd() to enable using the .phar build
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Werbrouck authored and Johannes Werbrouck committed Aug 21, 2023
1 parent 6397c7d commit cae63de
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ These commands will help you set up apps on Fly.io. **Remember that running thes

## Installation

Run `composer require fly-apps/fly-laravel` to install the latest version.
Run `composer require fly-apps/fly-laravel` to install the latest version.

By default, commands are invoked using the `vendor/bin/fly-laravel` script. To avoid have to type all that for ecery command, you may configure a shell alias:

```shell
alias fly-laravel='vendor/bin/fly-laravel'
```

To make sure this is always available, you may add this to your shell configuration file in your home directory, such as `~/.zshrc` or `~/.bashrc`, and then restart your shell.

## Usage

Expand Down Expand Up @@ -57,7 +65,7 @@ Run `fly-laravel launch:mysql` to create a new MySQL application. You will be ab
- **Volume Name**: For data persistence, a volume will be needed for database applications. If there's a volume with this name available, we'll use that. If no volume with this name can be found, a 1GB volume will be created on deploy. More about volumes here: [Volume Documentation](https://fly.io/docs/reference/volumes/).

Some notes when launching a MySQL database:
- During the launch, some Laravel environment variables will be updated in its `fly.toml` configuration. Redeploying the Laravel app will be necessary to reflect these changes.
- During the launch, some environment variables will be updated in the `fly.toml` configuration of the Laravel app. Redeploying the Laravel app will be necessary to reflect these changes.
- The `DB_CONNECTION` env var in `fly.toml` will be set to 'mysql'
- On deploy, a small scale machine will be provisioned with a 1x shared CPU and 256Mb of memory. Consider scaling up the database for better performance.
- By default, the `innodb buffer pool size` will be set to 64MB. Consider optimizing this based on your performance requirements. You can find this in `.fly/mysql/fly.toml`, in the `[processes]` section.
Expand Down
33 changes: 22 additions & 11 deletions app/Commands/LaunchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use GuzzleHttp\Exception\RequestException;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Process\Exceptions\ProcessFailedException;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Process;
use LaravelZero\Framework\Commands\Command;
use Symfony\Component\Console\Command\Command as CommandAlias;
Expand Down Expand Up @@ -35,7 +36,7 @@ class LaunchCommand extends Command
* @return mixed
*/
public function handle(FlyIoService $flyIoService)
{
{
try
{
// First, check if a fly.toml is already present. If so, suggest to use the deployCommand instead.
Expand Down Expand Up @@ -108,7 +109,7 @@ private function inputLaravel(array &$userInput, FlyIoService $flyIoService)
->throw()
->collect("data.organizations.nodes")
->toArray();

$userInput['organization'] = $flyIoService->askOrganizationName($organizations, $this);

$regionsJson = $regionsProcess->wait()
Expand Down Expand Up @@ -218,20 +219,30 @@ private function generateFlyToml(array $userInput, TomlGenerator $generator)

private function copyFiles()
{
Process::run("cp -r " . __DIR__ . "/../../resources/templates/.fly/ ./")
->throw();
/**
* __DIR__ = app/commands folder (! this starts with phar://)
* getcwd() = root of application where package is installed
* base_path() = location of executable (! this starts with phar://)
*
* Because __DIR__ and base_path start with phar://, only getcwd() can be used reliably.
*/

$templatesPath = getcwd() . '/vendor/fly-apps/fly-laravel/resources/templates';

Process::run("cp -r " . __DIR__ . "/../../resources/templates/.dockerignore .dockerignore")
->throw();
// copy .fly directory
File::copyDirectory($templatesPath . '/.fly', getcwd() . '/.fly');

// The dockerfile is hardcoded and copied over from resources/templates/Dockerfile
if (file_exists('Dockerfile'))
// copy .dockerignore
File::copy($templatesPath . '/.dockerignore', getcwd() . '/.dockerignore');

// copy Dockerfile
if (file_exists(getcwd() . '/Dockerfile'))
{
$this->line("Existing Dockerfile found, using that instead of the default Dockerfile.");
} else
}
else
{
Process::run("cp " . __DIR__ . '/../../resources/templates/Dockerfile Dockerfile')
->throw();
File::copy($templatesPath . '/Dockerfile', getcwd() . '/Dockerfile');
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/Commands/LaunchMySQLCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function handle(FlyIoService $flyIoService)

// finalize
$this->info("MySQL app '" . $userInput['app_name'] . "' is ready to go! Run 'fly-laravel deploy:mysql' to deploy it.");
$this->line("Also, don't forget to run the migrations in your Laravel app 😉");
$this->line("Also, don't forget to redeploy your laravel app and run the migrations 😉");
return CommandAlias::SUCCESS;
}

Expand Down
Binary file modified builds/fly-laravel
Binary file not shown.
1 change: 0 additions & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
*/

'providers' => [
App\Providers\AppServiceProvider::class,
],

];

0 comments on commit cae63de

Please sign in to comment.