GithubHelp home page GithubHelp logo

remix's Introduction

Hyperpop — The EdgeDB Remix Stack

The Hyperpop Remix Stack

Learn more about Remix Stacks.

What's in the stack

Other EdgeDB + Remix stacks

Not a fan of bits of the stack? Fork it and make it your own! Or use one of these other community-maintained stacks that combine the gloriousness of EdgeDB and Remix:

Development

View the live application: https://edgedb-remix.fly.dev

1. Scaffold your project

npx create-remix --template edgedb/remix

2. Initialize an EdgeDB project

If you haven't already, install the edgedb CLI: edgedb.com/install. Then run the following command from inside your project directory.

edgedb project init

This will install the latest version of EdgeDB, spin up an instance, and apply all migrations from dbschema/migrations.

3. Seed the database

npm run seed

This creates some sample notes and an initial user with the following credentials:

4. Create .env

This project uses cookie-based authentication that relies on a secret token. It isn't secure to hard-code this value directly into your source code, so we'll use an environment variables called SESSION_STATE. To set this variable in development, create a .env file and add the following line. Remix automatically loads environment variables from this file when running in development mode.

SESSION_SECRET="super-duper-s3cret"

In the Deployment section, we'll describe how to set a value for SESSION_SECRET in production. We also set this variable in deploy.yml so it's available when running end-to-end tests in GitHub Actions.

5. Start the server

This starts your app in development mode, rebuilding assets on file changes.

npm run dev

Go to localhost:3000, click "Sign up" to create a new account, and explore the application.

Deployment

This Remix Stack comes with two GitHub Actions that handle automatically deploying your app to production and staging environments.

Prior to your first deployment, you'll need to do a few things:

1. Install the Fly CLI and signup/login

fly auth signup     # sign up
fly auth login      # login

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.

2. Create a Fly app for your application

Run fly launch --no-deploy to create a new Fly app. You'll be prompted for an app name; if you leave this blank, a name will be generated for you.

$ fly launch --no-deploy
An existing fly.toml file was found for app "edgedb-remix"
? Would you like to copy its configuration to the new app? Yes
Creating app in /path/to/project
Scanning source code
Detected a Dockerfile app
? App Name (leave blank to use an auto-generated name):
Automatically selected personal organization
? Select region: sea (Seattle, Washington (US))
Created app <random name> in organization personal
Wrote config file fly.toml
Your app is ready. Deploy with `flyctl deploy`

Once the app has been created the existing fly.toml file will be overwritten with the newly created app's information (this is intentional).

3. Deploy an EdgeDB instance to Fly

Follow EdgeDB's Fly.io deployment guide for step-by-step instructions. At the end of this process, you will have a DSN which can be used to connect to the instance. It should have the following form:

edgedb://<user>:<password>@<hostname>:<port>

Add this value to your application as a Fly secret called EDGEDB_DSN.

fly secrets set EDGEDB_DSN=<paste DSN here>

4. Add a SESSION_SECRET to your Fly app secrets

To do this you can run the following commands:

fly secrets set SESSION_SECRET=$(openssl rand -hex 32)

If you don't have openssl installed, feel free to use any tool that will generate a random string, like a password manager or online tool.

5. Initialize a Git repo

Create a new GitHub Repository and Copy the provided [email protected]:<reponame>.git URL. Then execute the following commands. Don't git push yet—we have a bit more configuration to do first.

git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin <paste git url here>

6. Add a FLY_API_TOKEN to your GitHub repo

To do this, generate a token via the Fly dashboard, copy it, and add it to to your repo via Settings > Secrets > Actions. Click "New repository secret", name it FLY_API_TOKEN, and paste the generated token.

7. Push to GitHub

Now we're ready to push this to GitHub. This will start the deployment process via GitHub Actions.

git push -u origin main

Every commit to your main branch will trigger a re-deployment to your production environment.

8. View the final deployment

Once the GitHub Actions have completed, your application should be live on the internet! Fly automatically provides a public-facing URL for your application: <appname>.fly.dev. Visit this URL for a fully-functional cloud hosted version of the application.

Check your fly.toml file for your app name, or go to the Fly dashboard to see more information about the application.

Getting Help with Deployment

If you run into any issues deploying to Fly, make sure you've followed all of the steps above carefully. Go to the Fly dashboard and view the deployment logs; this will often be helpful for debugging. If you're still having issues open an issue on the edgedb/remix repo.

GitHub Actions

We use GitHub Actions for continuous integration and deployment. Anything that gets into the main branch will be deployed to production after running tests/build/etc. Anything in the dev branch will be deployed to staging.

Project structure

This is a pretty simple note-taking app, but it's a good example of how you can build a full stack app with EdgeDB and Remix. The main functionality is creating users, logging in and out, and creating and deleting notes.

Cypress

We use Cypress for our End-to-End tests in this project. You'll find those in the cypress directory. As you make changes, add to an existing file or create a new file in the cypress/e2e directory to test your changes.

We use @testing-library/cypress for selecting elements on the page semantically.

To run these tests in development, run npm run test:e2e:dev which will start the dev server for the app as well as the Cypress client. Make sure the database is running in docker as described above.

We have a utility for testing authenticated features without having to go through the login flow:

cy.login();
// you are now logged in as a new user

We also have a utility to auto-delete the user at the end of your test. Just make sure to add this in each test file:

afterEach(() => {
  cy.cleanupUser();
});

That way, we can keep your local db clean and keep your tests isolated from one another.

Vitest

For lower level tests of utilities and individual components, we use vitest. We have DOM-specific assertion helpers via @testing-library/jest-dom.

Type Checking

This project uses TypeScript. It's recommended to get TypeScript set up for your editor to get a really great in-editor experience with type checking and auto-complete. To run type checking across the whole project, run npm run typecheck.

Linting

This project uses ESLint for linting. That is configured in .eslintrc.js.

Formatting

We use Prettier for auto-formatting in this project. It's recommended to install an editor plugin (like the VSCode Prettier plugin) to get auto-formatting on save. There's also a npm run format script you can run to format all files in the project.

remix's People

Contributors

colinhacks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

remix's Issues

Error occuring during Deployment, failing during the start.sh script

Issue:
During the deployment process for the Remix application on Fly.io, an error is occurring during the sh start.sh. Here is the error I'm seeing from the logs.

 2022-11-23T19:22:59.403 runner[4091cd47] sea [info] Starting instance

2022-11-23T19:23:00.321 runner[4091cd47] sea [info] Configuring virtual machine

2022-11-23T19:23:00.322 runner[4091cd47] sea [info] Pulling container image

2022-11-23T19:23:00.735 runner[4091cd47] sea [info] Unpacking image

2022-11-23T19:23:00.751 runner[4091cd47] sea [info] Preparing kernel init

2022-11-23T19:23:01.066 runner[4091cd47] sea [info] Configuring firecracker

2022-11-23T19:23:01.252 runner[4091cd47] sea [info] Starting virtual machine

2022-11-23T19:23:01.479 app[4091cd47] sea [info] Starting init (commit: 81d5330)...

2022-11-23T19:23:01.523 app[4091cd47] sea [info] Preparing to run: `sh start.sh` as root

2022-11-23T19:23:01.562 app[4091cd47] sea [info] 2022/11/23 19:23:01 listening on [fdaa:0:e601:a7b:2c60:4091:cd47:2]:22 (DNS: [fdaa::3]:53)

2022-11-23T19:23:01.575 app[4091cd47] sea [info] + edgedb migrate

2022-11-23T19:23:03.750 app[4091cd47] sea [info] [2022-11-23T19:23:03Z WARN edgedb::version_check] Cannot check for updates: failed to fetch JSON at URL: https://packages.edgedb.com/archive/.jsonindexes/x86_64-unknown-linux-musl.json: error sending request for url (https://packages.edgedb.com/archive/.jsonindexes/x86_64-unknown-linux-musl.json): error trying to connect: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:1921: (unable to get local issuer certificate): error trying to connect: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:1921: (unable to get local issuer certificate): error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:1921: (unable to get local issuer certificate): error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:1921:

2022-11-23T19:23:04.755 app[4091cd47] sea [info] Connecting to an EdgeDB instance at newworldmerchanttool-edgedb.internal:8080...

2022-11-23T19:23:06.704 app[4091cd47] sea [info] edgedb error: InternalServerError:

2022-11-23T19:23:06.704 app[4091cd47] sea [info] Hint: This is most likely a bug in EdgeDB. Please consider opening an issue ticket at https://github.com/edgedb/edgedb/issues/new?template=bug_report.md

2022-11-23T19:23:06.704 app[4091cd47] sea [info] Server traceback:

2022-11-23T19:23:06.707 app[4091cd47] sea [info] Traceback (most recent call last):

2022-11-23T19:23:06.707 app[4091cd47] sea [info] File "edb/server/pgcon/pgcon.pyx", line 2162, in wait_for_message

2022-11-23T19:23:06.707 app[4091cd47] sea [info] ConnectionAbortedError

2022-11-23T19:23:06.707 app[4091cd47] sea [info] During handling of the above exception, another exception occurred:

2022-11-23T19:23:06.707 app[4091cd47] sea [info] Traceback (most recent call last):

2022-11-23T19:23:06.707 app[4091cd47] sea [info] File "edb/server/protocol/binary.pyx", line 1304, in edb.server.protocol.binary.EdgeConnection.main

2022-11-23T19:23:06.707 app[4091cd47] sea [info] File "edb/server/protocol/binary.pyx", line 474, in auth

2022-11-23T19:23:06.707 app[4091cd47] sea [info] File "edb/server/protocol/binary.pyx", line 586, in _start_connection

2022-11-23T19:23:06.707 app[4091cd47] sea [info] File "/usr/lib/x86_64-linux-gnu/edgedb-server-2/lib/python3.10/site-packages/edb/server/server.py", line 544, in new_dbview

2022-11-23T19:23:06.707 app[4091cd47] sea [info] await db.introspection()

2022-11-23T19:23:06.707 app[4091cd47] sea [info] File "edb/server/dbview/dbview.pyx", line 261, in introspection

2022-11-23T19:23:06.707 app[4091cd47] sea [info] File "edb/server/dbview/dbview.pyx", line 263, in edb.server.dbview.dbview.Database.introspection

2022-11-23T19:23:06.707 app[4091cd47] sea [info] File "/usr/lib/x86_64-linux-gnu/edgedb-server-2/lib/python3.10/site-packages/edb/server/server.py", line 711, in introspect_db

2022-11-23T19:23:06.707 app[4091cd47] sea [info] user_schema = await self.introspect_user_schema(conn)

2022-11-23T19:23:06.707 app[4091cd47] sea [info] File "/usr/lib/x86_64-linux-gnu/edgedb-server-2/lib/python3.10/site-packages/edb/server/server.py", line 657, in introspect_user_schema

2022-11-23T19:23:06.707 app[4091cd47] sea [info] json_data = await conn.sql_fetch_val(self._local_intro_query)

2022-11-23T19:23:06.707 app[4091cd47] sea [info] File "edb/server/pgcon/pgcon.pyx", line 1152, in sql_fetch_val

2022-11-23T19:23:06.707 app[4091cd47] sea [info] File "edb/server/pgcon/pgcon.pyx", line 1137, in sql_fetch

2022-11-23T19:23:06.707 app[4091cd47] sea [info] File "edb/server/pgcon/pgcon.pyx", line 1076, in parse_execute

2022-11-23T19:23:06.707 app[4091cd47] sea [info] File "edb/server/pgcon/pgcon.pyx", line 1059, in _parse_execute

2022-11-23T19:23:06.707 app[4091cd47] sea [info] File "edb/server/pgcon/pgcon.pyx", line 586, in wait_for_sync

2022-11-23T19:23:06.707 app[4091cd47] sea [info] File "edb/server/pgcon/pgcon.pyx", line 2160, in wait_for_message

2022-11-23T19:23:06.707 app[4091cd47] sea [info] ConnectionAbortedError

2022-11-23T19:23:07.541 app[4091cd47] sea [info] Starting clean up. 

Trouble shooting I've tried so far:

  • I've doubled checked the EDGEDB_DSN variable
  • I've made sure to persist the generated TLS certificate
  • Double checked the EDGEDB_CLIENT_TLS_SECURITY setting is set to insecure

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.