Skip to content

Commit

Permalink
Update some fly instructions & commands (AllYourBot#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
krschacht authored Nov 5, 2024
1 parent 7f2e4fc commit edbbffd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ GEM
net-smtp (0.5.0)
net-protocol
nio4r (2.7.3)
nokogiri (1.16.7-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4)
oauth2 (2.0.9)
Expand Down Expand Up @@ -398,9 +400,12 @@ GEM
railties (>= 6.0.0)
stringio (3.1.1)
sync (0.5.0)
tailwindcss-rails (2.7.2-arm64-darwin)
railties (>= 7.0.0)
tailwindcss-rails (2.7.2-x86_64-linux)
railties (>= 7.0.0)
thor (1.3.2)
tiktoken_ruby (0.0.9-arm64-darwin)
tiktoken_ruby (0.0.9-x86_64-linux)
timecop (0.9.8)
timeout (0.4.1)
Expand Down Expand Up @@ -431,6 +436,7 @@ GEM
zeitwerk (2.7.1)

PLATFORMS
arm64-darwin-23
x86_64-linux

DEPENDENCIES
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,19 @@ If you encountered an error while waiting for the services to be deployed on Ren

Deploying to Fly.io is another great option. It's not quite one-click like Render and it's not 100% free. But we've made the configuration really easy for you and the cost should be about $2 per month, and Render costs $7 per month after 90 days of free service so Fly is actually less expensive over the long term.

1. Click Fork > Create New Fork at the top of this repository. Pull your forked repository down to your computer (the usual git clone ...).
1. Click Fork > Create New Fork at the top of this repository. **Pull your forked repository down to your computer (the usual git clone ...)**.
1. Go into the directory you just created with your git clone and run `bundle`
1. Install the Fly command-line tool on Mac with `brew install flyctl` otherwise `curl -L https://fly.io/install.sh | sh` ([view instructions](https://fly.io/docs/hands-on/install-flyctl/))
1. Think of an internal Fly name for your app, it has to be unique to all of Fly, and then in the root directory of the repository you pulled down, run `fly launch --build-only --copy-config --name=APP_NAME_YOU_CHOSE`
1. Think of an internal Fly name for your app, it has to be unique to all of Fly. You'll use this **APP_NAME** three times in the steps below. First, in the root directory of the repository you pulled down, run `fly launch --build-only --copy-config --name=APP_NAME`

- Say "Yes" when it asks if you want to tweak these settings

1. When it opens your browser, change the Database to `Fly Postgres` with a unique name such as `[APP_NAME]-db` and you can set the configuration to `Development`.
1. When it opens your browser, (i) change the Database to `Fly Automated Postgres`, (ii) set the name to be `[APP_NAME]-db`, (iii) and you can set the configuration to `Development`.
1. Click `Confirm Settings` at the bottom of the page and close the browser.
1. The app will do a bunch of build steps and then return to the command line. Scroll through the output and save the Postgres username & password somewhere as you'll never be able to see those again.
1. Next run `bin/rails db:setup_encryption[true]`. This will initialize some private keys for your app and send them to Fly.
1. The app will do a bunch of build steps and then return to the command line. Scroll through the output and **save the Postgres username & password somewhere as you'll never be able to see those again**.
1. Next run `bin/rails db:setup_encryption[true]`. This will initialize some private keys for your app and send them to Fly. (If you get an error you may have forgotten to run `bundle`).
1. Run `fly deploy --ha=false`
1. Assuming you chose `Development` as the DB size in the step above, now you should run `bin/rails db:fly[APP_NAME_FROM_EARLIER,swap,512]` This will increase the swap on your database machine so that it doesn't crash.
1. Assuming you chose `Development` as the DB size in the step above, now you should run `bin/rails db:fly[APP_NAME,swap,512]` This will increase the swap on your database machine so that it doesn't crash since the Development database has less ram.

You may want to read about [configuring optional features](#configure-optional-features).

Expand Down Expand Up @@ -303,7 +304,7 @@ HostedGPT requires these services to be running:
1. `cd` into your local repository clone
1. `rbenv install` to install the correct ruby version (it reads the .ruby-version in the repo)
1. Do NOT run db:setup as it will not configure encryption properly. Proceed to the next step and it will automatically configure the database.
1. `bin/dev` starts up all the services, installs gems, and handles db. Note: The app should automatically configure a database, but if you get any database errors or want to change the default configuration, set the environment variable `DATABASE_URL=postgres://username:password@localhost:5432/hostedgpt_development` (replacing `username`, `password`, `hostedgpt_development` with your database name, and 5432 with your database port number).
1. `bin/dev` starts up all the services, installs gems, and handles db. Note: The app should automatically configure a database, but if you get any database errors or want to change the default configuration, set the environment variable DATABASE_URL=postgres://username:password@localhost:5432/hostedgpt_development (replacing username, password, hostedgpt_development with your database name, and 5432 with your database port number).
1. Open [http://localhost:3000](http://localhost:3000) and register as a new user.
1. `bin/rails test` and `bin/rails test:system` to run the comprehensive tests
1. The project root has an `.editorconfig` file to help eliminate whitespace differences in pull requests. It's nice if you install an extension in your IDE to utilize this (e.g. VS Code has "EditorConfig for VS Code").
Expand Down
8 changes: 5 additions & 3 deletions app/services/fly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ def change_db_swap(app:, swap:)
end
swap = swap.to_i

app_id = get_apps.find { |m| m.name == app_name }&.id
apps = get_apps
app_id = apps.find { |m| m.name == app_name }&.id
if app_id.nil?
puts "Could not find the app named #{app_name}. Aborting."
puts "These are all the app names on your Fly account: #{apps.map(&:name).join(", ")}"
return
end

Expand Down Expand Up @@ -38,13 +40,13 @@ def get_machines(app_name)
end

def patch_machine(app_name, id, config)
patch("https://api.machines.dev/v1/apps/#{app_name}/machines/#{id}").param(config: config)
post("https://api.machines.dev/v1/apps/#{app_name}/machines/#{id}").param(config: config)
end

private

def bearer_token
`fly auth token`.chop
@bearer_token ||= `fly auth token`.chop.split.last
end

def header
Expand Down
2 changes: 1 addition & 1 deletion fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ console_command = '/rails/bin/rails console'
[http_service]
internal_port = 3000
force_https = true
auto_stop_machines = false
auto_stop_machines = 'off'
auto_start_machines = true
min_machines_running = 1
processes = ['app']
Expand Down

0 comments on commit edbbffd

Please sign in to comment.