Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed May 4, 2023
0 parents commit fcadbab
Show file tree
Hide file tree
Showing 136 changed files with 35,909 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/node_modules
*.log
.DS_Store
.env
/.cache
/public/build
/build
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
LITEFS_DIR=/litefs/data
DATABASE_PATH="./prisma/data.db"
DATABASE_URL="file:./data.db?connection_limit=1"
SESSION_SECRET="super-duper-s3cret"
ENCRYPTION_SECRET="something-fake"
MAILGUN_DOMAIN="mg.example.com"
MAILGUN_SENDING_KEY="some-api-token-with-dashes"
30 changes: 30 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/** @type {import('@types/eslint').Linter.BaseConfig} */
module.exports = {
extends: [
'@remix-run/eslint-config',
'@remix-run/eslint-config/node',
'@remix-run/eslint-config/jest-testing-library',
'prettier',
],
rules: {
'@typescript-eslint/consistent-type-imports': [
'warn',
{
prefer: 'type-imports',
disallowTypeAnnotations: true,
fixStyle: 'inline-type-imports',
},
],
'testing-library/no-await-sync-events': 'off',
'jest-dom/prefer-in-document': 'off',
'@typescript-eslint/no-duplicate-imports': 'warn',
},
// we're using vitest which has a very similar API to jest
// (so the linting plugins work nicely), but it means we have to explicitly
// set the jest version.
settings: {
jest: {
version: 28,
},
},
}
165 changes: 165 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
name: 🚀 Deploy
on:
push:
branches:
- main
- dev
pull_request: {}

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
actions: write
contents: read

jobs:
lint:
name: ⬣ ESLint
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v3

- name: ⎔ Setup node
uses: actions/setup-node@v3
with:
node-version: 18

- name: 📥 Download deps
uses: bahmutov/npm-install@v1
with:
useLockFile: false

- name: 🔬 Lint
run: npm run lint

typecheck:
name: ʦ TypeScript
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v3

- name: ⎔ Setup node
uses: actions/setup-node@v3
with:
node-version: 18

- name: 📥 Download deps
uses: bahmutov/npm-install@v1
with:
useLockFile: false

- name: 🔎 Type check
run: npm run typecheck --if-present

vitest:
name: ⚡ Vitest
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v3

- name: ⎔ Setup node
uses: actions/setup-node@v3
with:
node-version: 18

- name: 📥 Download deps
uses: bahmutov/npm-install@v1
with:
useLockFile: false

- name: 🏄 Copy test env vars
run: cp .env.example .env

- name: ⚡ Run vitest
run: npm run test -- --coverage

playwright:
name: 🎭 Playwright
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v3

- name: 🏄 Copy test env vars
run: cp .env.example .env

- name: ⎔ Setup node
uses: actions/setup-node@v3
with:
node-version: 18

- name: 📥 Download deps
uses: bahmutov/npm-install@v1
with:
useLockFile: false

- name: 📥 Install Playwright Browsers
run: npx playwright install --with-deps

- name: 🛠 Setup Database
run: npx prisma migrate deploy

- name: 🏦 Cache Database
id: db-cache
uses: actions/cache@v3
with:
path: prisma/sqlite.db
key: db-cache

- name: 🏗 Build
run: npm run build

- name: 🎭 Playwright tests
run: npx playwright test

- name: 📊 Upload report
uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30

deploy:
name: 🚀 Deploy
runs-on: ubuntu-latest
needs: [lint, typecheck, vitest, playwright]
# only build/deploy main branch on pushes
if:
${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev') &&
github.event_name == 'push' }}

steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v3

- name: 👀 Read app name
uses: SebRollen/[email protected]
id: app_name
with:
file: 'fly.toml'
field: 'app'

- name: 🚀 Deploy Staging
if: ${{ github.ref == 'refs/heads/dev' }}
uses: superfly/[email protected]
with:
args:
'deploy --remote-only --build-arg COMMIT_SHA=${{ github.sha }} --app
${{ steps.app_name.outputs.value }}-staging'
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

- name: 🚀 Deploy Production
if: ${{ github.ref == 'refs/heads/main' }}
uses: superfly/[email protected]
with:
args: 'deploy --remote-only --build-arg COMMIT_SHA=${{ github.sha }}'
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
node_modules

/build
/public/build
.env

/prisma/data.db
/prisma/data.db-journal
/prisma/test

*.local.*
/test-results/
/playwright-report/
/playwright/.cache/
/mocks/fixtures/email/*.json
/coverage
/prisma/data.db.bkp

prisma/test
other/image.db

server-build
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
legacy-peer-deps=true
registry=https://registry.npmjs.org/
8 changes: 8 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules

/build
/public/build
.env

/app/styles/tailwind.css
package.json
70 changes: 70 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Contributing

Thanks for your willingness to contribute! Please make sure to check with me
before doing a bunch of work on something.

## Project setup

If you do need to set the project up locally yourself, feel free to follow these
instructions:

### System Requirements

- [Node.js](https://nodejs.org/) >= 18.0.0
- [npm](https://npmjs.com/) >= 8.18.0
- [git](https://git-scm.com/) >= 2.38.0

### Setup steps

1. Fork and clone the repo
2. Copy `.env.example` into `.env`
3. Run `npm run setup -s` to install dependencies and run validation
4. Create a branch for your PR with `git checkout -b pr/your-branch-name`

> Tip: Keep your `main` branch pointing at the original repository and make pull
> requests from branches on your fork. To do this, run:
>
> ```
> git remote add upstream https://github.com/epicweb-dev/rocket-rental.git
> git fetch upstream
> git branch --set-upstream-to=upstream/main main
> ```
>
> This will add the original repository as a "remote" called "upstream," Then
> fetch the git information from that remote, then set your local `main` branch
> to use the upstream main branch whenever you run `git pull`. Then you can make
> all of your pull request branches based on this `main` branch. Whenever you
> want to update your version of `main`, do a regular `git pull`.
If the setup script doesn't work, you can try to run the commands manually:
```sh
git clone <your-fork>
cd ./rocket-rental
# copy the .env.example to .env
# everything's mocked out during development so you shouldn't need to
# change any of these values unless you want to hit real environments.
cp .env.example .env
# Install deps
npm install
# setup database
prisma migrate reset --force
# Install playwright browsers
npm run test:e2e:install
# run build, typecheck, linting
npm run validate
```
If that all worked without trouble, you should be able to start development
with:

```sh
npm run dev
```

And open up `http://localhost:3000` and rock!
74 changes: 74 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# base node image
FROM node:16-bullseye-slim as base

# set for base and all layer that inherit from it
ENV NODE_ENV production

# Install openssl for Prisma
RUN apt-get update && apt-get install -y fuse3 openssl sqlite3 ca-certificates

# Install all node_modules, including dev dependencies
FROM base as deps

WORKDIR /myapp

ADD package.json package-lock.json .npmrc ./
RUN npm install --production=false

# Setup production node_modules
FROM base as production-deps

WORKDIR /myapp

COPY --from=deps /myapp/node_modules /myapp/node_modules
ADD package.json package-lock.json .npmrc ./
RUN npm prune --production

# Build the app
FROM base as build

WORKDIR /myapp

COPY --from=deps /myapp/node_modules /myapp/node_modules

ADD prisma .
RUN npx prisma generate

ADD . .
RUN npm run build

# Finally, build the production image with minimal footprint
FROM base

ENV FLY="true"
ENV LITEFS_DIR="/litefs/data"
ENV DATABASE_FILENAME="sqlite.db"
ENV DATABASE_PATH="$LITEFS_DIR/$DATABASE_FILENAME"
ENV DATABASE_URL="file:$DATABASE_PATH"
ENV INTERNAL_PORT="8080"
ENV PORT="8081"
ENV NODE_ENV="production"

# add shortcut for connecting to database CLI
RUN echo "#!/bin/sh\nset -x\nsqlite3 \$DATABASE_URL" > /usr/local/bin/database-cli && chmod +x /usr/local/bin/database-cli

WORKDIR /myapp

COPY --from=production-deps /myapp/node_modules /myapp/node_modules
COPY --from=build /myapp/node_modules/.prisma /myapp/node_modules/.prisma

COPY --from=build /myapp/server-build /myapp/server-build
COPY --from=build /myapp/build /myapp/build
COPY --from=build /myapp/public /myapp/public
COPY --from=build /myapp/package.json /myapp/package.json
COPY --from=build /myapp/other/start.js /myapp/other/start.js
COPY --from=build /myapp/prisma /myapp/prisma

# prepare for litefs
COPY --from=flyio/litefs:0.4.0 /usr/local/bin/litefs /usr/local/bin/litefs
ADD other/litefs.yml /etc/litefs.yml
RUN mkdir -p /data ${LITEFS_DIR}

ADD . .

CMD ["litefs", "mount", "--", "node", "./other/start.js"]
Loading

0 comments on commit fcadbab

Please sign in to comment.