|
| 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 | +% 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: Package your VulcanSQL API Server |
| 70 | + |
| 71 | +In this guide, we'll deploy the Docker version of your VulcanSQL API Server. So please execute the following command in the terminal: |
| 72 | + |
| 73 | +```bash |
| 74 | +vulcan package -o 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), |
| 119 | +you should copy them into the dist folder and add them all in the Dockerfile.** |
| 120 | +::: |
| 121 | + |
| 122 | +## Step 4: Setup Fly.io deployment config |
| 123 | + |
| 124 | +Please execute the following command in the terminal in order to generate a Fly.io deployment config `fly.toml`: |
| 125 | + |
| 126 | +```shell |
| 127 | +fly launch |
| 128 | +``` |
| 129 | + |
| 130 | +After executing the command, Fly.io would ask you several questions such as: |
| 131 | +1. Chooese an app name |
| 132 | +2. Select organization |
| 133 | +3. Choose a region for deployment |
| 134 | +4. Would you like to set up a Postgresql database now? |
| 135 | +5. Would you like to set up an Upstash Redis database now? |
| 136 | +6. Would you like to deploy now? |
| 137 | + |
| 138 | +After answering these questions, you will see `fly.toml` in the `dist` folder and the content is similar to this: |
| 139 | + |
| 140 | +```toml |
| 141 | +# fly.toml app configuration file generated for xxxxx on 2023-07-13T22:40:54+08:00 |
| 142 | +# |
| 143 | +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. |
| 144 | +# |
| 145 | + |
| 146 | +app = "xxxxx" |
| 147 | +primary_region = "bos" |
| 148 | + |
| 149 | +[http_service] |
| 150 | + internal_port = 3000 |
| 151 | + force_https = true |
| 152 | + auto_stop_machines = false |
| 153 | + auto_start_machines = false |
| 154 | + min_machines_running = 1 |
| 155 | + processes = ["app"] |
| 156 | +``` |
| 157 | + |
| 158 | +:::info |
| 159 | +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. |
| 160 | +::: |
| 161 | + |
| 162 | +For more detailed introduction on how to launch your app, you can [read more here](https://fly.io/docs/hands-on/launch-app/). |
| 163 | + |
| 164 | +## Step 5: Deploy to Fly.io |
| 165 | + |
| 166 | +Finally, you can execute the following command in the terminal to deploy your VulcanSQL API Server and share it with the world! |
| 167 | + |
| 168 | +```shell |
| 169 | +fly deploy |
| 170 | +``` |
| 171 | + |
| 172 | +After successfully deploying the app, you should see the following message in the terminal: |
| 173 | + |
| 174 | +```shell |
| 175 | +Watch your app at https://fly.io/apps/xxxx/monitoring |
| 176 | + |
| 177 | +Visit your newly deployed app at https://xxxxx/ |
| 178 | +``` |
| 179 | + |
| 180 | +:::info |
| 181 | +You can read more here regarding to [deployment via Dockerfile](https://fly.io/docs/languages-and-frameworks/dockerfile/). |
| 182 | +::: |
| 183 | + |
| 184 | +Congratulations! Now your VulcanSQL app is on the cloud and is ready to be shared to the world! |
| 185 | + |
| 186 | +:::info |
| 187 | +If you need to clean up the resources on Fly.io, you can [read the documentation here](https://fly.io/docs/flyctl/destroy/). |
| 188 | +::: |
| 189 | + |
| 190 | +## Step 6: (Optional) Deploy your VulcanSQL API Catalog Server |
| 191 | + |
| 192 | +If you need to deploy API Catalog Server, you should execute the following command in the terminal: |
| 193 | + |
| 194 | +```shell |
| 195 | +vulcan package -t catalog-server -o docker |
| 196 | +``` |
| 197 | + |
| 198 | +:::caution |
| 199 | +The folder generated by the command is also called `dist`, so if you had executed the command of packaging |
| 200 | +API server, you should rename the `dist` folder generated previously to prevent from being overwritten. |
| 201 | +::: |
| 202 | + |
| 203 | +Then, you should modify `API_BASE_URL` to the URL of your VulcanSQL API Server you just deployed in Dockerfile: |
| 204 | + |
| 205 | +```dockerfile |
| 206 | +ENV API_BASE_URL [URL of VulcanSQL API Server] |
| 207 | +``` |
| 208 | + |
| 209 | +Finally, you execute the same Fly.io commands used in the step 4 and step 5 in the terminal, and change any configurations if you need: |
| 210 | + |
| 211 | +``` |
| 212 | +fly launch |
| 213 | +fly deploy |
| 214 | +``` |
0 commit comments