Skip to content

Commit d385f01

Browse files
authored
Merge pull request #245 from onflow/mackenzie/create-runbook
Create RUNBOOK.md
2 parents f9a6cf1 + d540ac5 commit d385f01

File tree

3 files changed

+97
-9
lines changed

3 files changed

+97
-9
lines changed

README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Welcome
1+
# Flow Playground
22

3-
The Flow Playground is the best way to learn and try Cadence. For newcomers to Flow
4-
the [Flow Developer Documentation](https://docs.onflow.org) has a guide on how to use the Playground.
3+
The Flow Playground is the best way to learn and try Cadence. For newcomers to Flow,
4+
the [Flow Developer Documentation](https://docs.onflow.org) includes a guide on how to use the Playground.
55

66
## Philosophy
77

@@ -14,27 +14,28 @@ We built the Flow Playground as a static website or typical "JAM stack" website
1414
- Fast build and deploy cycles
1515
- We want to maximize the amount of potential contributions
1616

17-
### What Is the Playground?
17+
### What is the Playground?
1818

1919
We want the Playground to have features that help you build on Flow. We also want to balance functionality with learning.
20+
2021
The Playground is a learning tool first and an awesome development tool second, although the two go hand-in-hand.
2122

2223
## Contributing
2324

24-
### Read the [Contribution Guidelines](https://github.com/onflow/flow-playground/blob/master/CONTRIBUTING.md)
25+
### Read the [Contribution Guidelines](CONTRIBUTING.md)
2526

26-
### Git workflow:
27+
### Git Workflow
2728

2829
- Use merge squashing, not commit merging [eg. here](https://blog.dnsimple.com/2019/01/two-years-of-squash-merge/). Squash merge is your friend.
29-
- The master branch is the base branch, there is no dedicated development branch
30+
- The `staging` branch is the base branch and contains the code deployed at https://play.staging.onflow.org.
3031

31-
# Developing
32+
## Developing
3233

3334
### Pre-requisites
3435

3536
You'll need to have Docker installed to develop.
3637

37-
## Installation
38+
### Installation
3839

3940
Clone the repo
4041

@@ -89,3 +90,7 @@ If you are using VSCode, you can use this debugging config (works with workspace
8990
]
9091
}
9192
```
93+
94+
## Deployment
95+
96+
The runbook contains details on [how to deploy the Flow Playground web app](RUNBOOK.md).

RUNBOOK.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
## Overview
2+
3+
The Flow Playground is a web-based interactive IDE for running Cadence code.
4+
It also provides an environment for the [Cadence intro tutorials](https://docs.onflow.org/cadence/tutorial/01-first-steps).
5+
6+
The overall project consists of the web app (this) and an [API backend](https://github.com/onflow/flow-playground-api).
7+
8+
The Playground Web App is implemented in React. The major components are as follows:
9+
10+
### GraphQL / Apollo Client
11+
12+
- All HTTP communication with the Playground API is done via `GraphQL` using the `Apollo` client.
13+
- The GraphQL schema is defined by the Playground API in [schemal.graphql](https://github.com/onflow/flow-playground-api/blob/master/schema.graphql)
14+
- This project uses Apollo Client's `localStorage` interface as well.
15+
- You can view the _local_ GraphQL schema in [local.graphql](src/api/apollo/local.graphql).
16+
- CRUD methods (wrapped Apollo client) are implemented in [projectMutator.ts](src/providers/Project/projectMutator.ts).
17+
- TypeScript typings and CRUD methods for Apollo are auto-generated using [GraphQL Code Generator](https://www.graphql-code-generator.com/).
18+
- After making changes to the `schema.local` you will need to run `npm run graphql:codegen` to auto-generate new typings and methods for Apollo Client.
19+
20+
### Monaco Editor
21+
22+
- The editor interface itself is implemented using [Monaco Editor](https://microsoft.github.io/monaco-editor/).
23+
- The editor component can be found here: https://github.com/onflow/flow-playground/tree/master/src/containers/Editor
24+
- The Cadence language definition (for linting and syntax highlighting) for Monaco can be found here: https://github.com/onflow/flow-playground/blob/master/src/util/cadence.ts
25+
26+
### Cadence Language Server
27+
28+
- The Cadence Language Server (used by Monaco) is implemented in Golang and compiled to WASM.
29+
- The WASM bundle is built from [source files in the Cadence repository](https://github.com/onflow/cadence/tree/master/npm-packages/cadence-language-server) and [published on npm](https://www.npmjs.com/package/@onflow/cadence-language-server).
30+
- You can read more about the Cadence Language Server in the [Cadence repository](https://github.com/onflow/cadence/blob/master/languageserver/README.md).
31+
- The Playground integration can be found here:
32+
- Server: https://github.com/onflow/flow-playground/blob/master/src/util/language-server.ts
33+
- Client: https://github.com/onflow/flow-playground/blob/master/src/util/language-client.ts
34+
35+
## Deployment
36+
37+
The Playground Web App is deployed to [Vercel](https://vercel.com). You will see a link to join the Flow Vercel team when you open your first PR. You must be a member of the team to trigger deployments.
38+
39+
### Staging Deployment
40+
41+
URL: https://play.staging.onflow.org
42+
43+
The Playground Web App is deployed to https://play.staging.onflow.org each time a new commit is pushed to the `staging` branch on this repository.
44+
45+
1. Open a new pull request and select `staging` as the base branch. Vercel will trigger a new deployment once the PR is approved and merged.
46+
47+
2. Vercel will then report the deployment status on the `staging` branch:
48+
49+
![vercel-deployment](vercel-deployment.png)
50+
51+
### Production Deployment
52+
53+
URL: https://play.onflow.org
54+
55+
Once a staging deployment has been verified, you can promote the changes to production.
56+
57+
The Playground Web App is deployed to https://play.onflow.org each time a new commit is pushed to the `production` branch on this repository.
58+
59+
1. Open a new pull request and select `production` as the base branch and `staging` as the source branch. Production deployments should always deploy the same code that is already live in staging. Vercel will trigger a new deployment once the PR is approved and merged.
60+
61+
2. Vercel will then report the deployment status on the `production` branch:
62+
63+
![vercel-deployment](vercel-deployment.png)
64+
65+
## Important Gotcha: User Sessions & Project "Forking"
66+
67+
_The Playground will not function in browsers where cookies or localStorage are disabled._
68+
69+
### How It Works
70+
71+
The Playground determines what content to load into the UI based on a url query param named `projectId`.
72+
- When a user first visits the Playground, the `projectId` param is set to `local-project`, indicating that this is a new project and has not been persisted.
73+
- https://github.dev/onflow/flow-playground/blob/2e3323aba9504e6a07fc13d1b2cec0e703edce43/src/util/url.ts#L16-L17
74+
- At this point, a representation of the `Project` _model_ has been boostrapped and persisted to the browser's localStorage using Apollo
75+
- https://github.dev/onflow/flow-playground/blob/2e3323aba9504e6a07fc13d1b2cec0e703edce43/src/providers/Project/projectDefault.ts#L216
76+
- https://github.dev/onflow/flow-playground/blob/2e3323aba9504e6a07fc13d1b2cec0e703edce43/src/providers/Project/projectHooks.ts#L10-L11
77+
- When a user performs some action that updates any field in the project, or clicks the save button, the project is read from localStorage, and sent to the API to be persisted.
78+
- https://github.dev/onflow/flow-playground/blob/2e3323aba9504e6a07fc13d1b2cec0e703edce43/src/providers/Project/projectMutator.ts#L54-L55
79+
- Once the mutation has returned successfully (The project state has been saved to the DB), another local value is set using Apollo/localstorage, to reflect the newly generated project's unique `id` (from the database)
80+
- https://github.dev/onflow/flow-playground/blob/2e3323aba9504e6a07fc13d1b2cec0e703edce43/src/providers/Project/projectMutator.ts#L93-L94
81+
- The server response also sets a cookie **that links the current browser session with the new project ID**
82+
- This is done so that if a user _shares_ a link to their new project (eg. https://play.onflow.org/46c7136f-803c-4166-9d46-25d8e927114c), to someone without the session cookie linking the ID and browser session, the UI will recognise (the save button becomes "fork") that this is the case, and on subsequent saves of the shared project, _will send a mutation to generate a new project based on the existing contents of the editor, preventing users from overwriting eachothers projects!_
83+
- The name of the cookie is `flow-playground`

vercel-deployment.png

58 KB
Loading

0 commit comments

Comments
 (0)