33 lines
2.1 KiB
PowerShell
33 lines
2.1 KiB
PowerShell
$ErrorActionPreference = 'Stop'
|
|
Get-Command docker -ErrorAction Stop | Out-Null
|
|
$workspace = (Resolve-Path (Join-Path $PSScriptRoot '../..')).Path
|
|
$settings = Join-Path $PSScriptRoot '.env.local'
|
|
if (-not (Test-Path -LiteralPath $settings)) {
|
|
$keyBytes = New-Object byte[] 32
|
|
$passwordBytes = New-Object byte[] 32
|
|
$generator = [System.Security.Cryptography.RandomNumberGenerator]::Create()
|
|
$generator.GetBytes($keyBytes)
|
|
$generator.GetBytes($passwordBytes)
|
|
$generator.Dispose()
|
|
$contents = "APP_KEY=base64:$([Convert]::ToBase64String($keyBytes))`nDB_PASSWORD=$([Convert]::ToBase64String($passwordBytes))`nPORTAL_PORT=8088`n"
|
|
[IO.File]::WriteAllText($settings, $contents, (New-Object Text.UTF8Encoding($false)))
|
|
}
|
|
if (-not (Test-Path -LiteralPath (Join-Path $workspace 'vendor/laravel/sail/runtimes/8.5/Dockerfile'))) {
|
|
throw 'Run composer install using composer.lock before starting the existing Sail runtime.'
|
|
}
|
|
$compose = @('compose', '--env-file', $settings, '-f', (Join-Path $PSScriptRoot 'compose.yaml'))
|
|
function Invoke-Compose([string[]] $ComposeArguments) {
|
|
& docker @compose @ComposeArguments
|
|
if ($LASTEXITCODE -ne 0) { throw "Docker Compose failed with exit code $LASTEXITCODE" }
|
|
}
|
|
Invoke-Compose -ComposeArguments @('config', '--quiet')
|
|
Invoke-Compose -ComposeArguments @('build', 'app')
|
|
Invoke-Compose -ComposeArguments @('up', '-d', 'postgres')
|
|
Invoke-Compose -ComposeArguments @('run', '--rm', 'app', 'sh', '-lc', 'mkdir -p storage/framework/cache/data storage/framework/sessions storage/framework/views storage/logs bootstrap/cache && chown -R sail:sail storage bootstrap/cache')
|
|
Invoke-Compose -ComposeArguments @('run', '--rm', 'app', 'php', 'artisan', 'config:clear')
|
|
Invoke-Compose -ComposeArguments @('run', '--rm', 'app', 'php', 'artisan', 'migrate', '--force')
|
|
Invoke-Compose -ComposeArguments @('run', '--rm', 'app', 'npm', 'ci')
|
|
Invoke-Compose -ComposeArguments @('run', '--rm', 'app', 'npm', 'run', 'build')
|
|
Invoke-Compose -ComposeArguments @('up', '-d', 'app', 'web', 'queue')
|
|
Write-Output 'Local development: http://localhost:8088. Inspect docker compose ps and /up before use.'
|