Skip to content

Commit

Permalink
improve things a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed Mar 3, 2022
1 parent 353216a commit 0e71c53
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ jobs:
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
- name: 🚚 Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
Expand Down
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,20 @@ npx prisma migrate deploy

When this finishes successfully, it will say:

> "All migrations have been successfully applied."
> All migrations have been successfully applied.
If you'd prefer not to use Docker, you can also use Fly's Wireguard VPN to connect to a development database (or even your production database). You can find the instructions to set up Wireguard [here](https://fly.io/docs/reference/private-networking/#install-your-wireguard-app), and the instructions for creating a development database [here](https://fly.io/docs/reference/postgres/).

## Build

To run the production build for the app, run the following script:

```sh
npm run build
```

This should take less than a second ⚡

## Development

With your postgres database up and running in one tab and setup with tables for your data model via prisma, you're ready to start the dev server. Run this in a new tab in your terminal:
Expand Down Expand Up @@ -82,22 +92,20 @@ Prior to your first deployment, you'll need to do a few thing:
- Make sure you have a `FLY_API_TOKEN` added to your GitHub repo, to do this, go to your user settings on Fly and create a new [token](https://web.fly.io/user/personal_access_tokens/new), then add it to [your repo secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets) with the name `FLY_API_TOKEN`. Finally you'll need to add a `SESSION_SECRET` to your fly app secrets, to do this you can run the following commands:

```sh
fly secrets set SESSION_SECRET=$(openssl rand -hex 32) -c fly.staging.toml
fly secrets set SESSION_SECRET=$(openssl rand -hex 32) -c fly.production.toml
fly secrets set SESSION_SECRET=$(openssl rand -hex 32) --app fly-stack-template-app-name-staging
fly secrets set SESSION_SECRET=$(openssl rand -hex 32) --app fly-stack-template-app-name
```

If you don't have openssl installed, you can also use [1password](https://1password.com/generate-password) to generate a random secret, just replace `$(openssl rand -hex 32)` with the generated secret.

- Create a database for both your staging and production environments. Run the following for both of your environments and follow the prompts (your App name is "fly-stack-template-app-name-db"):

```sh
fly postgres create
```

afterwards, you'll need to connect your database to each of your apps
- Create a database for both your staging and production environments. Run the following:

```sh
fly postgres create --name fly-stack-template-app-name-db
fly postgres attach --postgres-app fly-stack-template-app-name-db --app fly-stack-template-app-name

fly postgres create --name fly-stack-template-app-name-staging-db
fly postgres attach --postgres-app fly-stack-template-app-name-staging-db --app fly-stack-template-app-name-staging
```

Fly will take care of setting the DATABASE_URL secret for you.
Expand All @@ -108,7 +116,7 @@ Now that every is set up you can commit and push your changes to your repo. Ever

Once you have your site and database running in a single region, you can add more regions by following [Fly's Scaling](https://fly.io/docs/reference/scaling/) and [Multi-region PostgreSQL](https://fly.io/docs/getting-started/multi-region-databases/) docs.

Make certain to set a `PRIMARY_REGION` environment variable for your app. You can use `[env]` config in the `fly.production.toml` to set that to the region you want to use as the primary region for both your app and database.
Make certain to set a `PRIMARY_REGION` environment variable for your app. You can use `[env]` config in the `fly.toml` to set that to the region you want to use as the primary region for both your app and database.

#### Testing your app in other regions

Expand Down
10 changes: 5 additions & 5 deletions remix.init/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ function getRandomString(length) {
}

async function main() {
const README_PATH = path.join(__dirname, "README.md");
const FLY_TOML_PATH = path.join(__dirname, "fly.toml");
const EXAMPLE_ENV_PATH = path.join(__dirname, ".env.example");
const ENV_PATH = path.join(__dirname, ".env");
const README_PATH = path.join(__dirname, "../README.md");
const FLY_TOML_PATH = path.join(__dirname, "../fly.toml");
const EXAMPLE_ENV_PATH = path.join(__dirname, "../.env.example");
const ENV_PATH = path.join(__dirname, "../.env");

const REPLACER = "fly-stack-template-app-name";

const DIR_NAME = path.basename(path.resolve(__dirname));
const DIR_NAME = path.basename(path.resolve(__dirname, ".."));
const SUFFIX = getRandomString(2);
const APP_NAME = DIR_NAME + "-" + SUFFIX;

Expand Down
2 changes: 1 addition & 1 deletion server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ app.all(
const port = process.env.PORT || 3000;

app.listen(port, () => {
console.log(`Express server listening on port ${port}`);
console.log(`App ready: http://localhost:${port}`);
});

0 comments on commit 0e71c53

Please sign in to comment.