Skip to content

Instantly share code, notes, and snippets.

@smartium
Last active October 7, 2024 05:41
Show Gist options
  • Save smartium/cf5f678bc852058fb65fd421c6b06497 to your computer and use it in GitHub Desktop.
Save smartium/cf5f678bc852058fb65fd421c6b06497 to your computer and use it in GitHub Desktop.

Revisions

  1. SMARTIUM revised this gist Aug 22, 2022. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion THORIUM Builder @ fly.io
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,6 @@ else
    sed -i '' 's/echo \\"Error: no test specified\\" && exit 1/serve .\//g' package.json

    export THORIUM_PROJECT_NAME="$(grep -o '"name": "[^"]*' package.json | grep -o '[^"]*$')" # get project name from packages.json
    export THORIUM_PROJECT_PATH="$HOME/Sites/$THORIUM_PROJECT_NAME"
    export PROJECT="${THORIUM_PROJECT_NAME//[_]/-}" # fly.io only accepts dashes
    cat <<EOT >>fly.toml
    app = "$PROJECT"
  2. SMARTIUM revised this gist Aug 22, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions THORIUM Builder @ fly.io
    Original file line number Diff line number Diff line change
    @@ -70,5 +70,7 @@ EOT
    fi
    echo "DEPLOYING APP..."
    flyctl deploy --now
    echo "OPENING APP ON BROWSER"
    sleep 3
    open "https://$PROJECT.fly.dev"
    fi
  3. SMARTIUM revised this gist Aug 22, 2022. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion THORIUM Builder @ fly.io
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ else
    if [ "$#" -eq "1" ]; then
    if [ "$1" = "create" ]; then
    # CREATE NPM PACKAGE AND LOGIN INTO FLY.IO:
    # flyctl auth login
    flyctl auth login
    npm init -y # new npm package
    npm install --save serve # install server package. Run on port 3000
    sed -i '' 's/"test"/"start"/' package.json
    @@ -70,4 +70,5 @@ EOT
    fi
    echo "DEPLOYING APP..."
    flyctl deploy --now
    open "https://$PROJECT.fly.dev"
    fi
  4. SMARTIUM created this gist Aug 22, 2022.
    73 changes: 73 additions & 0 deletions THORIUM Builder @ fly.io
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,73 @@
    #!/bin/bash

    # ./deploy.sh create --> create fly.io project
    # ./deploy.sh --> only update project

    if ! command -v flyctl &>/dev/null; then
    echo "flyctl isn't installed! Opening fly.io installation instructions..."
    sleep 3
    open https://fly.io/docs/getting-started/installing-flyctl/
    exit
    else
    if [ "$#" -eq "1" ]; then
    if [ "$1" = "create" ]; then
    # CREATE NPM PACKAGE AND LOGIN INTO FLY.IO:
    # flyctl auth login
    npm init -y # new npm package
    npm install --save serve # install server package. Run on port 3000
    sed -i '' 's/"test"/"start"/' package.json
    sed -i '' 's/echo \\"Error: no test specified\\" && exit 1/serve .\//g' package.json

    export THORIUM_PROJECT_NAME="$(grep -o '"name": "[^"]*' package.json | grep -o '[^"]*$')" # get project name from packages.json
    export THORIUM_PROJECT_PATH="$HOME/Sites/$THORIUM_PROJECT_NAME"
    export PROJECT="${THORIUM_PROJECT_NAME//[_]/-}" # fly.io only accepts dashes
    cat <<EOT >>fly.toml
    app = "$PROJECT"
    kill_signal = "SIGINT"
    kill_timeout = 5
    processes = []
    [build]
    builder = "heroku/buildpacks:20"
    [env]
    PORT = "8080"
    [experimental]
    allowed_public_ports = []
    auto_rollback = true
    [[services]]
    http_checks = []
    internal_port = 8080
    processes = ["app"]
    protocol = "tcp"
    script_checks = []
    [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"
    [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80
    [[services.ports]]
    handlers = ["tls", "http"]
    port = 443
    [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"
    EOT
    # fly.io will automatically identify that it is a Node.js application
    echo "GENERATING APP..."
    flyctl launch --copy-config --name $PROJECT --no-deploy
    fi
    fi
    echo "DEPLOYING APP..."
    flyctl deploy --now
    fi