File size: 1,549 Bytes
05f272a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Build (if needed) and run the FinAlly Docker container.
# Requires: PowerShell, Docker Desktop. Tested on Windows.
# Usage: scripts\start.ps1 [-Build]
param(
    [switch]$Build
)

$ErrorActionPreference = "Stop"

$RootDir = Split-Path -Parent $PSScriptRoot
$ImageName = "finally"
$ContainerName = "finally"
$Port = 8001

Set-Location $RootDir

$EnvFile = Join-Path $RootDir ".env"
if (-not (Test-Path $EnvFile)) {
    Write-Error "No .env file found at $EnvFile`nCopy .env.example to .env and fill in your API key first:`n  copy .env.example .env"
    exit 1
}

$DbDir = Join-Path $RootDir "db"
if (-not (Test-Path $DbDir)) {
    New-Item -ItemType Directory -Path $DbDir | Out-Null
}

$imageExists = docker image inspect $ImageName 2>$null
if ($Build -or -not $imageExists) {
    Write-Host "Building Docker image '$ImageName'..."
    docker build -t $ImageName $RootDir
    if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}

$running = docker ps --filter "name=^/$ContainerName`$" --filter "status=running" --format "{{.Names}}"
if ($running -eq $ContainerName) {
    Write-Host "FinAlly is already running at http://localhost:$Port"
    exit 0
}

$existing = docker ps -a --filter "name=^/$ContainerName`$" --format "{{.Names}}"
if ($existing -eq $ContainerName) {
    docker rm $ContainerName | Out-Null
}

docker run -d `
    --name $ContainerName `
    -v "${DbDir}:/app/db" `
    -p "${Port}:8000" `
    --env-file $EnvFile `
    $ImageName

Write-Host "FinAlly is starting at http://localhost:$Port"
Start-Process "http://localhost:$Port"