|
| 1 | +# Fly.io |
| 2 | + |
| 3 | +In this step-by-step guide, we'll guide you how to deploy your VulcanSQL project to [Fly.io](https://fly.io/). |
| 4 | +Fly.io is a developer friendly service to deploy your apps. Besides, it has [free allowances](https://fly.io/docs/about/pricing/#em-free-allowances-em), |
| 5 | +which is a great deployment option for side-projects. |
| 6 | + |
| 7 | +## Step 1: Install Fly.io |
| 8 | + |
| 9 | +Please go to [this website](https://fly.io/docs/hands-on/install-flyctl/) for installing `flyctl`, which is a command-line utility that lets you work with Fly.io. |
| 10 | +You should install the version that's appropriate for your operating system. |
| 11 | + |
| 12 | +After successfully installed `flyctl`, you should see the following message if you type `fly` in the terminal: |
| 13 | + |
| 14 | +``` |
| 15 | +cyyeh@JimmydeMBP vulcan-sql % fly |
| 16 | +This is flyctl, the Fly.io command line interface. |
| 17 | +
|
| 18 | +Here's a few commands to get you started: |
| 19 | + fly launch Launch a new application |
| 20 | + fly apps Create and manage apps |
| 21 | + fly postgres Create and manage Postgres databases |
| 22 | + fly mysql Create and manage PlanetScale MySQL databases |
| 23 | + fly redis Create and manage Upstash Redis databases |
| 24 | + fly machines Create and manage individual Fly.io machines |
| 25 | +
|
| 26 | +If you need help along the way: |
| 27 | + fly help Display a complete list of commands |
| 28 | + fly help <command> Display help for a specific command, e.g. 'fly help launch' |
| 29 | +
|
| 30 | +Visit https://fly.io/docs for additional documentation & guides |
| 31 | +``` |
| 32 | + |
| 33 | +## Step 2: Login to Fly.io |
| 34 | + |
| 35 | +**Signup** |
| 36 | + |
| 37 | +If this is your first time setting up Fly.io, please execute the following command in the terminal: |
| 38 | + |
| 39 | +```bash |
| 40 | +fly auth signup |
| 41 | +``` |
| 42 | + |
| 43 | +After successfully sign up in Fly.io, you should see the following message in the terminal: |
| 44 | + |
| 45 | +``` |
| 46 | +Waiting for session... Done |
| 47 | +successfully logged in as xxxxx@xxx |
| 48 | +``` |
| 49 | + |
| 50 | +For more detailed introduction on how to sign up, you can [read more here](https://fly.io/docs/hands-on/sign-up/). |
| 51 | + |
| 52 | +**Login** |
| 53 | + |
| 54 | +If you already have a Fly.io account, please execute the following command in the terminal: |
| 55 | + |
| 56 | +```bash |
| 57 | +fly auth login |
| 58 | +``` |
| 59 | + |
| 60 | +After successfully login in Fly.io, you should see the following message in the terminal: |
| 61 | + |
| 62 | +``` |
| 63 | +Waiting for session... Done |
| 64 | +successfully logged in as xxxxx@xxx |
| 65 | +``` |
| 66 | + |
| 67 | +For more detailed introduction on how to sign in, you can [read more here](https://fly.io/docs/hands-on/sign-in/). |
| 68 | + |
| 69 | +## Step 3: Packaging your VulcanSQL project |
| 70 | + |
| 71 | +In this guide, we'll deploy the Docker version of your VulcanSQL project. So please execute the following command in the terminal: |
| 72 | + |
| 73 | +```bash |
| 74 | +vulcan package --output docker |
| 75 | +``` |
| 76 | + |
| 77 | +After executing the command, you'll see a message shown like below and a new directory `dist` in the project directory. |
| 78 | + |
| 79 | +```bash |
| 80 | +2023-08-07 08:47:26.246 INFO [CORE] Package successfully, you can go to "dist" folder and run "docker build ." to build the image. |
| 81 | +✔ Package successfully. |
| 82 | +``` |
| 83 | + |
| 84 | +The directory structure of `dist` is as following: |
| 85 | + |
| 86 | +``` |
| 87 | +dist |
| 88 | +├── Dockerfile |
| 89 | +├── config.json |
| 90 | +├── index.js |
| 91 | +├── package.json |
| 92 | +└── result.json |
| 93 | +``` |
| 94 | + |
| 95 | +:::caution |
| 96 | +External resources and configurations, such as `profiles.yaml`, are not copied to the `dist` folder. |
| 97 | +You'll need to copy them manually. We strongly recommend using a separate profile instead of the one used for development. |
| 98 | + |
| 99 | +After copying `profiles.yaml` into the `dist` folder, you should also add one line in `Dockerfile` as following: |
| 100 | + |
| 101 | +```shell |
| 102 | +. |
| 103 | +. |
| 104 | +. |
| 105 | +FROM node:16-bullseye-slim |
| 106 | +WORKDIR /usr/app |
| 107 | +COPY --from=build /usr/app /usr/app |
| 108 | +COPY config.json . |
| 109 | +COPY index.js . |
| 110 | +COPY result.json . |
| 111 | +# add the line below |
| 112 | +COPY profiles.yaml . |
| 113 | +ENV NODE_ENV production |
| 114 | + |
| 115 | +CMD [ "node", "index.js" ] |
| 116 | +``` |
| 117 | + |
| 118 | +**Notes: if you have [multiple profiles](../references/data-source-profile#define-profile-in-independent-yaml-files), you should copy them into the dist folder and add them all in the Dockerfile.** |
| 119 | +::: |
| 120 | + |
| 121 | +## Step 4: Setup Fly.io deployment config |
| 122 | + |
| 123 | +Please execute the following command in the terminal in order to generate a Fly.io deployment config `fly.toml`: |
| 124 | + |
| 125 | +```shell |
| 126 | +fly launch |
| 127 | +``` |
| 128 | + |
| 129 | +After executing the command, Fly.io would ask you several questions such as: |
| 130 | +1. Chooese an app name |
| 131 | +2. Select organization |
| 132 | +3. Choose a region for deployment |
| 133 | +4. Would you like to set up a Postgresql database now? |
| 134 | +5. Would you like to set up an Upstash Redis database now? |
| 135 | +6. Would you like to deploy now? |
| 136 | + |
| 137 | +After answering these questions, you will see `fly.toml` in the `dist` folder and the content is similar to this: |
| 138 | + |
| 139 | +```toml |
| 140 | +# fly.toml app configuration file generated for xxxxx on 2023-07-13T22:40:54+08:00 |
| 141 | +# |
| 142 | +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. |
| 143 | +# |
| 144 | + |
| 145 | +app = "xxxxx" |
| 146 | +primary_region = "bos" |
| 147 | + |
| 148 | +[http_service] |
| 149 | + internal_port = 3000 |
| 150 | + force_https = true |
| 151 | + auto_stop_machines = false |
| 152 | + auto_start_machines = false |
| 153 | + min_machines_running = 1 |
| 154 | + processes = ["app"] |
| 155 | +``` |
| 156 | + |
| 157 | +:::info |
| 158 | +You can make `auto_stop_machines` to be false, so that you don't need to worry if the machine will hibernate if no one accesses it for a while. |
| 159 | +::: |
| 160 | + |
| 161 | +For more detailed introduction on how to launch your app, you can [read more here](https://fly.io/docs/hands-on/launch-app/). |
| 162 | + |
| 163 | +## Step 5: Deploy to Fly.io |
| 164 | + |
| 165 | +Finally, you can execute the following command in the terminal to deploy your VulcanSQL project and share it with the world! |
| 166 | + |
| 167 | +```shell |
| 168 | +fly deploy |
| 169 | +``` |
| 170 | + |
| 171 | +After successfully deploying the app, you should see the following message in the terminal: |
| 172 | + |
| 173 | +```shell |
| 174 | +Watch your app at https://fly.io/apps/xxxx/monitoring |
| 175 | + |
| 176 | +Visit your newly deployed app at https://xxxxx/ |
| 177 | +``` |
| 178 | + |
| 179 | +Congratulations! Now your VulcanSQL app is on the cloud and is ready to be shared to the world! |
0 commit comments