Skip to content

Commit fc673a0

Browse files
feat(_official-blog-tutorial): update to latest indie-stack (#198)
1 parent 2df8290 commit fc673a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+376
-259
lines changed

_official-blog-tutorial/.eslintrc.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
11
/** @type {import('eslint').Linter.Config} */
22
module.exports = {
3-
extends: ["@remix-run/eslint-config", "@remix-run/eslint-config/node"],
3+
extends: [
4+
"@remix-run/eslint-config",
5+
"@remix-run/eslint-config/node",
6+
"@remix-run/eslint-config/jest-testing-library",
7+
"prettier",
8+
],
9+
env: {
10+
"cypress/globals": true,
11+
},
12+
plugins: ["cypress"],
13+
// we're using vitest which has a very similar API to jest
14+
// (so the linting plugins work nicely), but it means we have to explicitly
15+
// set the jest version.
16+
settings: {
17+
jest: {
18+
version: 28,
19+
},
20+
},
421
};

_official-blog-tutorial/.github/workflows/deploy.yml

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ on:
66
- dev
77
pull_request: {}
88

9+
permissions:
10+
actions: write
11+
contents: read
12+
913
jobs:
1014
lint:
1115
name: ⬣ ESLint
1216
runs-on: ubuntu-latest
1317
steps:
1418
- name: 🛑 Cancel Previous Runs
15-
uses: styfle/cancel-workflow-action@0.9.1
19+
uses: styfle/cancel-workflow-action@0.11.0
1620

1721
- name: ⬇️ Checkout repo
1822
uses: actions/checkout@v3
@@ -24,6 +28,8 @@ jobs:
2428

2529
- name: 📥 Download deps
2630
uses: bahmutov/npm-install@v1
31+
with:
32+
useLockFile: false
2733

2834
- name: 🔬 Lint
2935
run: npm run lint
@@ -33,7 +39,7 @@ jobs:
3339
runs-on: ubuntu-latest
3440
steps:
3541
- name: 🛑 Cancel Previous Runs
36-
uses: styfle/cancel-workflow-action@0.9.1
42+
uses: styfle/cancel-workflow-action@0.11.0
3743

3844
- name: ⬇️ Checkout repo
3945
uses: actions/checkout@v3
@@ -45,6 +51,8 @@ jobs:
4551

4652
- name: 📥 Download deps
4753
uses: bahmutov/npm-install@v1
54+
with:
55+
useLockFile: false
4856

4957
- name: 🔎 Type check
5058
run: npm run typecheck --if-present
@@ -54,7 +62,7 @@ jobs:
5462
runs-on: ubuntu-latest
5563
steps:
5664
- name: 🛑 Cancel Previous Runs
57-
uses: styfle/cancel-workflow-action@0.9.1
65+
uses: styfle/cancel-workflow-action@0.11.0
5866

5967
- name: ⬇️ Checkout repo
6068
uses: actions/checkout@v3
@@ -66,6 +74,8 @@ jobs:
6674

6775
- name: 📥 Download deps
6876
uses: bahmutov/npm-install@v1
77+
with:
78+
useLockFile: false
6979

7080
- name: ⚡ Run vitest
7181
run: npm run test -- --coverage
@@ -75,7 +85,7 @@ jobs:
7585
runs-on: ubuntu-latest
7686
steps:
7787
- name: 🛑 Cancel Previous Runs
78-
uses: styfle/cancel-workflow-action@0.9.1
88+
uses: styfle/cancel-workflow-action@0.11.0
7989

8090
- name: ⬇️ Checkout repo
8191
uses: actions/checkout@v3
@@ -90,6 +100,8 @@ jobs:
90100

91101
- name: 📥 Download deps
92102
uses: bahmutov/npm-install@v1
103+
with:
104+
useLockFile: false
93105

94106
- name: 🛠 Setup Database
95107
run: npx prisma migrate reset --force
@@ -98,7 +110,7 @@ jobs:
98110
run: npm run build
99111

100112
- name: 🌳 Cypress run
101-
uses: cypress-io/github-action@v3
113+
uses: cypress-io/github-action@v5
102114
with:
103115
start: npm run start:mocks
104116
wait-on: "http://localhost:8811"
@@ -112,39 +124,39 @@ jobs:
112124
runs-on: ubuntu-latest
113125
steps:
114126
- name: 🛑 Cancel Previous Runs
115-
uses: styfle/cancel-workflow-action@0.9.1
127+
uses: styfle/cancel-workflow-action@0.11.0
116128

117129
- name: ⬇️ Checkout repo
118130
uses: actions/checkout@v3
119131

120132
- name: 👀 Read app name
121-
uses: SebRollen/[email protected].0
133+
uses: SebRollen/[email protected].2
122134
id: app_name
123135
with:
124136
file: "fly.toml"
125137
field: "app"
126138

127139
- name: 🐳 Set up Docker Buildx
128-
uses: docker/setup-buildx-action@v1
140+
uses: docker/setup-buildx-action@v2
129141

130142
# Setup cache
131143
- name: ⚡️ Cache Docker layers
132-
uses: actions/cache@v2
144+
uses: actions/cache@v3
133145
with:
134146
path: /tmp/.buildx-cache
135147
key: ${{ runner.os }}-buildx-${{ github.sha }}
136148
restore-keys: |
137149
${{ runner.os }}-buildx-
138150
139151
- name: 🔑 Fly Registry Auth
140-
uses: docker/login-action@v1
152+
uses: docker/login-action@v2
141153
with:
142154
registry: registry.fly.io
143155
username: x
144156
password: ${{ secrets.FLY_API_TOKEN }}
145157

146158
- name: 🐳 Docker build
147-
uses: docker/build-push-action@v2
159+
uses: docker/build-push-action@v4
148160
with:
149161
context: .
150162
push: true
@@ -173,13 +185,13 @@ jobs:
173185

174186
steps:
175187
- name: 🛑 Cancel Previous Runs
176-
uses: styfle/cancel-workflow-action@0.9.1
188+
uses: styfle/cancel-workflow-action@0.11.0
177189

178190
- name: ⬇️ Checkout repo
179191
uses: actions/checkout@v3
180192

181193
- name: 👀 Read app name
182-
uses: SebRollen/[email protected].0
194+
uses: SebRollen/[email protected].2
183195
id: app_name
184196
with:
185197
file: "fly.toml"

_official-blog-tutorial/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
legacy-peer-deps=true

_official-blog-tutorial/Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ FROM base as deps
1212

1313
WORKDIR /myapp
1414

15-
ADD package.json package-lock.json ./
15+
ADD package.json .npmrc ./
1616
RUN npm install --production=false
1717

1818
# Setup production node_modules
@@ -21,7 +21,7 @@ FROM base as production-deps
2121
WORKDIR /myapp
2222

2323
COPY --from=deps /myapp/node_modules /myapp/node_modules
24-
ADD package.json package-lock.json ./
24+
ADD package.json .npmrc ./
2525
RUN npm prune --production
2626

2727
# Build the app
@@ -54,6 +54,8 @@ COPY --from=build /myapp/node_modules/.prisma /myapp/node_modules/.prisma
5454

5555
COPY --from=build /myapp/build /myapp/build
5656
COPY --from=build /myapp/public /myapp/public
57-
ADD . .
57+
COPY --from=build /myapp/package.json /myapp/package.json
58+
COPY --from=build /myapp/start.sh /myapp/start.sh
59+
COPY --from=build /myapp/prisma /myapp/prisma
5860

59-
CMD ["npm", "start"]
61+
ENTRYPOINT [ "./start.sh" ]

_official-blog-tutorial/README.md

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Learn more about [Remix Stacks](https://remix.run/stacks).
66

77
```sh
8-
npx create-remix --template remix-run/indie-stack
8+
npx create-remix@latest --template remix-run/indie-stack
99
```
1010

1111
## What's in the stack
@@ -30,20 +30,20 @@ Not a fan of bits of the stack? Fork it, change it, and use `npx create-remix --
3030

3131
Click this button to create a [Gitpod](https://gitpod.io) workspace with the project set up and Fly pre-installed
3232

33-
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/from-referrer/)
33+
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/remix-run/indie-stack/tree/main)
3434

3535
## Development
3636

37-
- Initial setup: _If you just generated this project, this step has been done for you._
37+
- This step only applies if you've opted out of having the CLI install dependencies for you:
3838

3939
```sh
40-
npm run setup
40+
npx remix init
4141
```
4242

43-
- Validate the app has been set up properly (optional):
43+
- Initial setup: _If you just generated this project, this step has been done for you._
4444

4545
```sh
46-
npm run validate
46+
npm run setup
4747
```
4848

4949
- Start dev server:
@@ -57,7 +57,7 @@ This starts your app in development mode, rebuilding assets on file changes.
5757
The database seed script creates a new user with some data you can use to get started:
5858

5959
60-
- Password: `rachelrox`
60+
- Password: `racheliscool`
6161

6262
### Relevant code:
6363

@@ -81,14 +81,28 @@ Prior to your first deployment, you'll need to do a few things:
8181
fly auth signup
8282
```
8383

84+
> **Note:** If you have more than one Fly account, ensure that you are signed into the same account in the Fly CLI as you are in the browser. In your terminal, run `fly auth whoami` and ensure the email matches the Fly account signed into the browser.
85+
8486
- Create two apps on Fly, one for staging and one for production:
8587

8688
```sh
87-
fly create blog-tutorial-ffb5
88-
fly create blog-tutorial-ffb5-staging
89+
fly apps create blog-tutorial-ffb5
90+
fly apps create blog-tutorial-ffb5-staging
8991
```
9092

91-
- Create a new [GitHub Repository](https://repo.new)
93+
> **Note:** Make sure this name matches the `app` set in your `fly.toml` file. Otherwise, you will not be able to deploy.
94+
95+
- Initialize Git.
96+
97+
```sh
98+
git init
99+
```
100+
101+
- Create a new [GitHub Repository](https://repo.new), and then add it as the remote for your project. **Do not push your app yet!**
102+
103+
```sh
104+
git remote add origin <ORIGIN_URL>
105+
```
92106

93107
- Add a `FLY_API_TOKEN` 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`.
94108

@@ -99,7 +113,7 @@ Prior to your first deployment, you'll need to do a few things:
99113
fly secrets set SESSION_SECRET=$(openssl rand -hex 32) --app blog-tutorial-ffb5-staging
100114
```
101115

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

104118
- Create a persistent volume for the sqlite database for both your staging and production environments. Run the following:
105119

@@ -108,7 +122,15 @@ Prior to your first deployment, you'll need to do a few things:
108122
fly volumes create data --size 1 --app blog-tutorial-ffb5-staging
109123
```
110124

111-
Now that everything is set up, you can commit and push your changes to your repo. Every commit to your `main` branch will trigger a deployment to your production environment, and every commit to your `dev` branch will trigger a deployment to your staging environment.
125+
Now that everything is set up you can commit and push your changes to your repo. Every commit to your `main` branch will trigger a deployment to your production environment, and every commit to your `dev` branch will trigger a deployment to your staging environment.
126+
127+
### Connecting to your database
128+
129+
The sqlite database lives at `/data/sqlite.db` in your deployed application. You can connect to the live database by running `fly ssh console -C database-cli`.
130+
131+
### Getting Help with Deployment
132+
133+
If you run into any issues deploying to Fly, make sure you've followed all of the steps above and if you have, then post as many details about your deployment (including your app name) to [the Fly support community](https://community.fly.io). They're normally pretty responsive over there and hopefully can help resolve any of your deployment issues and questions.
112134

113135
## GitHub Actions
114136

_official-blog-tutorial/app/db.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if (process.env.NODE_ENV === "production") {
1717
global.__db__ = new PrismaClient();
1818
}
1919
prisma = global.__db__;
20+
prisma.$connect();
2021
}
2122

2223
export { prisma };

_official-blog-tutorial/app/models/note.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export function getNote({
99
userId: User["id"];
1010
}) {
1111
return prisma.note.findFirst({
12+
select: { id: true, body: true, title: true },
1213
where: { id, userId },
1314
});
1415
}

_official-blog-tutorial/app/models/user.server.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import bcrypt from "@node-rs/bcrypt";
21
import type { Password, User } from "@prisma/client";
2+
import bcrypt from "bcryptjs";
33

44
import { prisma } from "~/db.server";
55

@@ -47,7 +47,10 @@ export async function verifyLogin(
4747
return null;
4848
}
4949

50-
const isValid = await bcrypt.verify(password, userWithPassword.password.hash);
50+
const isValid = await bcrypt.compare(
51+
password,
52+
userWithPassword.password.hash
53+
);
5154

5255
if (!isValid) {
5356
return null;

_official-blog-tutorial/app/root.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { LinksFunction, LoaderArgs, MetaFunction } from "@remix-run/node";
1+
import type { LinksFunction, LoaderArgs } from "@remix-run/node";
22
import { json } from "@remix-run/node";
33
import {
44
Links,
@@ -9,18 +9,12 @@ import {
99
ScrollRestoration,
1010
} from "@remix-run/react";
1111

12-
import { getUser } from "./session.server";
13-
import tailwindStylesheetUrl from "./styles/tailwind.css";
12+
import { getUser } from "~/session.server";
13+
import tailwindStylesheetUrl from "~/styles/tailwind.css";
1414

15-
export const links: LinksFunction = () => {
16-
return [{ rel: "stylesheet", href: tailwindStylesheetUrl }];
17-
};
18-
19-
export const meta: MetaFunction = () => ({
20-
charset: "utf-8",
21-
title: "Remix Notes",
22-
viewport: "width=device-width,initial-scale=1",
23-
});
15+
export const links: LinksFunction = () => [
16+
{ rel: "stylesheet", href: tailwindStylesheetUrl },
17+
];
2418

2519
export const loader = async ({ request }: LoaderArgs) => {
2620
return json({ user: await getUser(request) });
@@ -30,6 +24,8 @@ export default function App() {
3024
return (
3125
<html lang="en" className="h-full">
3226
<head>
27+
<meta charSet="utf-8" />
28+
<meta name="viewport" content="width=device-width,initial-scale=1" />
3329
<Meta />
3430
<Links />
3531
</head>

0 commit comments

Comments
 (0)