Skip to content

Commit fcadbab

Browse files
committed
init
0 parents  commit fcadbab

File tree

136 files changed

+35909
-0
lines changed

Some content is hidden

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

136 files changed

+35909
-0
lines changed

.dockerignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/node_modules
2+
*.log
3+
.DS_Store
4+
.env
5+
/.cache
6+
/public/build
7+
/build

.env.example

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
LITEFS_DIR=/litefs/data
2+
DATABASE_PATH="./prisma/data.db"
3+
DATABASE_URL="file:./data.db?connection_limit=1"
4+
SESSION_SECRET="super-duper-s3cret"
5+
ENCRYPTION_SECRET="something-fake"
6+
MAILGUN_DOMAIN="mg.example.com"
7+
MAILGUN_SENDING_KEY="some-api-token-with-dashes"

.eslintrc.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/** @type {import('@types/eslint').Linter.BaseConfig} */
2+
module.exports = {
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+
rules: {
10+
'@typescript-eslint/consistent-type-imports': [
11+
'warn',
12+
{
13+
prefer: 'type-imports',
14+
disallowTypeAnnotations: true,
15+
fixStyle: 'inline-type-imports',
16+
},
17+
],
18+
'testing-library/no-await-sync-events': 'off',
19+
'jest-dom/prefer-in-document': 'off',
20+
'@typescript-eslint/no-duplicate-imports': 'warn',
21+
},
22+
// we're using vitest which has a very similar API to jest
23+
// (so the linting plugins work nicely), but it means we have to explicitly
24+
// set the jest version.
25+
settings: {
26+
jest: {
27+
version: 28,
28+
},
29+
},
30+
}

.github/workflows/deploy.yml

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
name: 🚀 Deploy
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- dev
7+
pull_request: {}
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
permissions:
14+
actions: write
15+
contents: read
16+
17+
jobs:
18+
lint:
19+
name: ⬣ ESLint
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: ⬇️ Checkout repo
23+
uses: actions/checkout@v3
24+
25+
- name: ⎔ Setup node
26+
uses: actions/setup-node@v3
27+
with:
28+
node-version: 18
29+
30+
- name: 📥 Download deps
31+
uses: bahmutov/npm-install@v1
32+
with:
33+
useLockFile: false
34+
35+
- name: 🔬 Lint
36+
run: npm run lint
37+
38+
typecheck:
39+
name: ʦ TypeScript
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: ⬇️ Checkout repo
43+
uses: actions/checkout@v3
44+
45+
- name: ⎔ Setup node
46+
uses: actions/setup-node@v3
47+
with:
48+
node-version: 18
49+
50+
- name: 📥 Download deps
51+
uses: bahmutov/npm-install@v1
52+
with:
53+
useLockFile: false
54+
55+
- name: 🔎 Type check
56+
run: npm run typecheck --if-present
57+
58+
vitest:
59+
name: ⚡ Vitest
60+
runs-on: ubuntu-latest
61+
steps:
62+
- name: ⬇️ Checkout repo
63+
uses: actions/checkout@v3
64+
65+
- name: ⎔ Setup node
66+
uses: actions/setup-node@v3
67+
with:
68+
node-version: 18
69+
70+
- name: 📥 Download deps
71+
uses: bahmutov/npm-install@v1
72+
with:
73+
useLockFile: false
74+
75+
- name: 🏄 Copy test env vars
76+
run: cp .env.example .env
77+
78+
- name: ⚡ Run vitest
79+
run: npm run test -- --coverage
80+
81+
playwright:
82+
name: 🎭 Playwright
83+
runs-on: ubuntu-latest
84+
timeout-minutes: 60
85+
steps:
86+
- name: ⬇️ Checkout repo
87+
uses: actions/checkout@v3
88+
89+
- name: 🏄 Copy test env vars
90+
run: cp .env.example .env
91+
92+
- name: ⎔ Setup node
93+
uses: actions/setup-node@v3
94+
with:
95+
node-version: 18
96+
97+
- name: 📥 Download deps
98+
uses: bahmutov/npm-install@v1
99+
with:
100+
useLockFile: false
101+
102+
- name: 📥 Install Playwright Browsers
103+
run: npx playwright install --with-deps
104+
105+
- name: 🛠 Setup Database
106+
run: npx prisma migrate deploy
107+
108+
- name: 🏦 Cache Database
109+
id: db-cache
110+
uses: actions/cache@v3
111+
with:
112+
path: prisma/sqlite.db
113+
key: db-cache
114+
115+
- name: 🏗 Build
116+
run: npm run build
117+
118+
- name: 🎭 Playwright tests
119+
run: npx playwright test
120+
121+
- name: 📊 Upload report
122+
uses: actions/upload-artifact@v3
123+
if: always()
124+
with:
125+
name: playwright-report
126+
path: playwright-report/
127+
retention-days: 30
128+
129+
deploy:
130+
name: 🚀 Deploy
131+
runs-on: ubuntu-latest
132+
needs: [lint, typecheck, vitest, playwright]
133+
# only build/deploy main branch on pushes
134+
if:
135+
${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev') &&
136+
github.event_name == 'push' }}
137+
138+
steps:
139+
- name: ⬇️ Checkout repo
140+
uses: actions/checkout@v3
141+
142+
- name: 👀 Read app name
143+
uses: SebRollen/[email protected]
144+
id: app_name
145+
with:
146+
file: 'fly.toml'
147+
field: 'app'
148+
149+
- name: 🚀 Deploy Staging
150+
if: ${{ github.ref == 'refs/heads/dev' }}
151+
uses: superfly/[email protected]
152+
with:
153+
args:
154+
'deploy --remote-only --build-arg COMMIT_SHA=${{ github.sha }} --app
155+
${{ steps.app_name.outputs.value }}-staging'
156+
env:
157+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
158+
159+
- name: 🚀 Deploy Production
160+
if: ${{ github.ref == 'refs/heads/main' }}
161+
uses: superfly/[email protected]
162+
with:
163+
args: 'deploy --remote-only --build-arg COMMIT_SHA=${{ github.sha }}'
164+
env:
165+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

.gitignore

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
node_modules
2+
3+
/build
4+
/public/build
5+
.env
6+
7+
/prisma/data.db
8+
/prisma/data.db-journal
9+
/prisma/test
10+
11+
*.local.*
12+
/test-results/
13+
/playwright-report/
14+
/playwright/.cache/
15+
/mocks/fixtures/email/*.json
16+
/coverage
17+
/prisma/data.db.bkp
18+
19+
prisma/test
20+
other/image.db
21+
22+
server-build

.npmrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
legacy-peer-deps=true
2+
registry=https://registry.npmjs.org/

.prettierignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules
2+
3+
/build
4+
/public/build
5+
.env
6+
7+
/app/styles/tailwind.css
8+
package.json

CONTRIBUTING.md

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Contributing
2+
3+
Thanks for your willingness to contribute! Please make sure to check with me
4+
before doing a bunch of work on something.
5+
6+
## Project setup
7+
8+
If you do need to set the project up locally yourself, feel free to follow these
9+
instructions:
10+
11+
### System Requirements
12+
13+
- [Node.js](https://nodejs.org/) >= 18.0.0
14+
- [npm](https://npmjs.com/) >= 8.18.0
15+
- [git](https://git-scm.com/) >= 2.38.0
16+
17+
### Setup steps
18+
19+
1. Fork and clone the repo
20+
2. Copy `.env.example` into `.env`
21+
3. Run `npm run setup -s` to install dependencies and run validation
22+
4. Create a branch for your PR with `git checkout -b pr/your-branch-name`
23+
24+
> Tip: Keep your `main` branch pointing at the original repository and make pull
25+
> requests from branches on your fork. To do this, run:
26+
>
27+
> ```
28+
> git remote add upstream https://github.com/epicweb-dev/rocket-rental.git
29+
> git fetch upstream
30+
> git branch --set-upstream-to=upstream/main main
31+
> ```
32+
>
33+
> This will add the original repository as a "remote" called "upstream," Then
34+
> fetch the git information from that remote, then set your local `main` branch
35+
> to use the upstream main branch whenever you run `git pull`. Then you can make
36+
> all of your pull request branches based on this `main` branch. Whenever you
37+
> want to update your version of `main`, do a regular `git pull`.
38+
39+
If the setup script doesn't work, you can try to run the commands manually:
40+
41+
```sh
42+
git clone <your-fork>
43+
cd ./rocket-rental
44+
45+
# copy the .env.example to .env
46+
# everything's mocked out during development so you shouldn't need to
47+
# change any of these values unless you want to hit real environments.
48+
cp .env.example .env
49+
50+
# Install deps
51+
npm install
52+
53+
# setup database
54+
prisma migrate reset --force
55+
56+
# Install playwright browsers
57+
npm run test:e2e:install
58+
59+
# run build, typecheck, linting
60+
npm run validate
61+
```
62+
63+
If that all worked without trouble, you should be able to start development
64+
with:
65+
66+
```sh
67+
npm run dev
68+
```
69+
70+
And open up `http://localhost:3000` and rock!

Dockerfile

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# base node image
2+
FROM node:16-bullseye-slim as base
3+
4+
# set for base and all layer that inherit from it
5+
ENV NODE_ENV production
6+
7+
# Install openssl for Prisma
8+
RUN apt-get update && apt-get install -y fuse3 openssl sqlite3 ca-certificates
9+
10+
# Install all node_modules, including dev dependencies
11+
FROM base as deps
12+
13+
WORKDIR /myapp
14+
15+
ADD package.json package-lock.json .npmrc ./
16+
RUN npm install --production=false
17+
18+
# Setup production node_modules
19+
FROM base as production-deps
20+
21+
WORKDIR /myapp
22+
23+
COPY --from=deps /myapp/node_modules /myapp/node_modules
24+
ADD package.json package-lock.json .npmrc ./
25+
RUN npm prune --production
26+
27+
# Build the app
28+
FROM base as build
29+
30+
WORKDIR /myapp
31+
32+
COPY --from=deps /myapp/node_modules /myapp/node_modules
33+
34+
ADD prisma .
35+
RUN npx prisma generate
36+
37+
ADD . .
38+
RUN npm run build
39+
40+
# Finally, build the production image with minimal footprint
41+
FROM base
42+
43+
ENV FLY="true"
44+
ENV LITEFS_DIR="/litefs/data"
45+
ENV DATABASE_FILENAME="sqlite.db"
46+
ENV DATABASE_PATH="$LITEFS_DIR/$DATABASE_FILENAME"
47+
ENV DATABASE_URL="file:$DATABASE_PATH"
48+
ENV INTERNAL_PORT="8080"
49+
ENV PORT="8081"
50+
ENV NODE_ENV="production"
51+
52+
# add shortcut for connecting to database CLI
53+
RUN echo "#!/bin/sh\nset -x\nsqlite3 \$DATABASE_URL" > /usr/local/bin/database-cli && chmod +x /usr/local/bin/database-cli
54+
55+
WORKDIR /myapp
56+
57+
COPY --from=production-deps /myapp/node_modules /myapp/node_modules
58+
COPY --from=build /myapp/node_modules/.prisma /myapp/node_modules/.prisma
59+
60+
COPY --from=build /myapp/server-build /myapp/server-build
61+
COPY --from=build /myapp/build /myapp/build
62+
COPY --from=build /myapp/public /myapp/public
63+
COPY --from=build /myapp/package.json /myapp/package.json
64+
COPY --from=build /myapp/other/start.js /myapp/other/start.js
65+
COPY --from=build /myapp/prisma /myapp/prisma
66+
67+
# prepare for litefs
68+
COPY --from=flyio/litefs:0.4.0 /usr/local/bin/litefs /usr/local/bin/litefs
69+
ADD other/litefs.yml /etc/litefs.yml
70+
RUN mkdir -p /data ${LITEFS_DIR}
71+
72+
ADD . .
73+
74+
CMD ["litefs", "mount", "--", "node", "./other/start.js"]

0 commit comments

Comments
 (0)