Skip to content

Commit 8166dda

Browse files
committed
Update to Next (#74)
* improve styling for general purpose blog * remove relay generated files from repo * put generated files in gitignore * update netlify build to build relay files * move image-proxy to cloud function * add image proxy to netlify paths * make imageProxy work with Netlify * hack to make image proxy work with netlify * remove unnecessary logging * put .env in .env.example * ignore .env * add missing imageProxy file * cleanup * remove netlify state * add missing file * base64 encode (with url-safe encoding) images * handle emoji names between colons, improve startup * improvements for firebase deploy * handle title * fix flow errors * update .nvmrc * fix netlify.toml redirects * share auth with server * Add issue template * Update issue templates * cleanup * fix Blog title * cleanup * use URL env var if RAZZLE_SITE_HOSTNAME is missing * Better embeds * fix twitter embed on mobile * better routing handling * allow paragraphs in lis * better handling for expired auth * simplify layout * better cache invalidation on login/logout * move cache option to directive * idx -> optional chaining * login/logout in header * fix title * stepan feedback * better handling for avatar query * more margin for reaction smiley * stepan's feedback on button styles * stepan's feedback on button styles * add edit post to options for admins * update deps * update relay to v8 * relay with hooks * Show helpful error message on CORs errors * fix gif handling * don't memoize route to allow refetch on login * add redirects for medium * update netlify redirects to handle medium redirects * reduce header level * fix title and description for rss feed * Slim the build by not including now and firebase deps by default * disable gc * add note about node engine for firebase config * add alias for reason * setup next.js * fixup deploy to netlify * add attribution * add attribution and cleanup flow/eslint * cleanup * better medium redirect * scroll position improvements, comments link, tippy update * cleanup * cleanup scroll handler and meta tags * update onegraph auth for better auth redirects, flow/lint fixes, better reactions on mobile * slightly better scrolling on reactions * better handling of cors error, better link in attribution * google analtyics * update schema * improve head and author * sitemap and robots.txt * better handling of vercel url * add client-only fields * add welcome page * update welcome * update readme * some welcome page improvements * work in progress on vercel deploy button * some improvements for the deploy button * update readme * ensure the repo has a publish label * use sourcecodeshots to build opengraph images * better source code highlighting * simplify highlighting * default to dark-plus, match og:image theme * don't bother with highlighting in rss feeds * fix fallback and twitterUsername lookup * add basepath support * markdown cleanup * prettier * flow/lint fixes, basePath fixes * better description * cleanup description * highlighting for inline code * update with staging deploy * prepare changelog * check in env.local with public env vars * set up full deploy pipeline * fixup cloudbuild yaml * commit changes * try cache-from * cache-from is too complicated for multi-stage builds
1 parent 9c2cfcc commit 8166dda

30 files changed

+9806
-568
lines changed

.circleci/config.yml

Lines changed: 0 additions & 77 deletions
This file was deleted.

.env.local

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
NEXT_PUBLIC_ONEGRAPH_APP_ID="570a3d6b-6ff3-4b7a-9b0d-fe4cf6384388"
2+
NEXT_PUBLIC_GITHUB_REPO_OWNER="onegraph"
3+
NEXT_PUBLIC_GITHUB_REPO_NAME="onegraph-changelog"
4+
NEXT_PUBLIC_TITLE="OneGraph Product Updates"
5+
NEXT_PUBLIC_DESCRIPTION="Follow along with OneGraph as we take over the world with GraphQL."
6+
NEXT_PUBLIC_SITE_HOSTNAME="https://onegraph.com"
7+
NEXT_PUBLIC_GOOGLE_ANALYTICS_TRACKING_ID="UA-122815795-1"

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010

1111
# production
1212
/build
13-
src/__generated__
1413

1514
# misc
1615
.DS_Store
1716
.env
18-
.env.local
1917
.env.development.local
2018
.env.test.local
2119
.env.production.local

README.md

Lines changed: 7 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,13 @@
1-
# Build a blog powered by GitHub issues
1+
This repo powers the [OneGraph changelog](https://onegraph.com/changelog). All of the entries in the changelog are issues in this repo.
22

3-
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2FOneGraph%2Foneblog%2Ftree%2Fnext&env=NEXT_PUBLIC_ONEGRAPH_APP_ID,NEXT_PUBLIC_TITLE,OG_GITHUB_TOKEN,OG_DASHBOARD_ACCESS_TOKEN,VERCEL_URL,VERCEL_GITHUB_ORG,VERCEL_GITHUB_REPO&envDescription=Variables%20needed%20to%20build%20your%20OneBlog&envLink=https%3A%2F%2Fgithub.com%2FOneGraph%2Foneblog%2Ftree%2Fnext%23environment-variables&project-name=oneblog&repo-name=oneblog)
3+
See the [https://onegraph.com/oneblog](https://onegraph.com/oneblog) for how to deploy your own changelog backed by GitHub issues.
44

5-
This repo allows you to generate a blog from GitHub issues on a repo. It powers the [OneGraph Product Updates blog](https://www.onegraph.com/changelog), [Stepan Parunashvili's blog](https://stopa.io/), [bdougie.live](https://www.bdougie.live/), and more.
5+
### Developing on this repo
66

7-
All of the posts are stored as issues on the repo (e.g. [OneGraph/onegraph-changelog](https://github.com/OneGraph/onegraph-changelog/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3Apublish+)).
7+
What follows are implementation details specific to this repo. For setting up a general oneblog, see [https://github.com/oneblog](https://github.com/oneblog).
88

9-
When you visit the page at [onegraph.com/changelog](https://www.onegraph.com/changelog), a GraphQL query fetches the issues from GitHub via OneGraph's persisted queries and renders them as blog posts.
9+
Staging triggers a build on [staging cloudbuild](https://console.cloud.google.com/cloud-build/builds?project=sourcecodeshots) on every push to non-master and deploys to staging firebase hosting/cloud run.
1010

11-
The persisted queries are stored with authentication credentials for GitHub that allows them to make authenticated requests. Persisting the queries locks them down so that they can't be made to send arbitrary requests to GitHub.
11+
Production triggers a build on (https://console.cloud.google.com/cloud-build/builds?project=onegraph-prod) on pushes to master and deploys to prod firebase hosting/cloud run.
1212

13-
You can learn more about [persisted queries in the docs](https://www.onegraph.com/docs/persisted_queries.html).
14-
15-
## Setup
16-
17-
Use an existing OneGraph app or sign up sign up at [OneGraph](https://www.onegraph.com) to create a new app.
18-
19-
Copy `/.env.example` to `/.env` and set the following environment variables.
20-
21-
### Environment variables
22-
23-
| Environment Variable | Description |
24-
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
25-
| `OG_GITHUB_TOKEN` | A server-side access token created on OneGraph, used as the default auth for the persisted queries that will fetch the issues. To create a new one, go the "Server-side Auth" tab in the [OneGraph dashboard](https://www.onegraph.com/dashboard) for your app, click the "Create Token" button, and add GitHub to the services. Keep this token safe, because it has access to your GitHub data. |
26-
| `OG_DASHBOARD_ACCESS_TOKEN` | An API token that allows you to create persisted queries on OneGraph. Go to the "Persisted queries" tab on the OneGraph dashboard, scroll down, and click "Create token". This will create a scoped token for your app that can create persisted queries on your behalf. |
27-
| `NEXT_PUBLIC_ONEGRAPH_APP_ID` | The id of your OneGraph app. You can get this from the [OneGraph dashboard](https://www.onegraph.com/dashboard) |
28-
| `NEXT_PUBLIC_TITLE` | The title of your site |
29-
| `NEXT_PUBLIC_DESCRIPTION` | A short description of your site. |
30-
| `NEXT_PUBLIC_GITHUB_REPO_OWNER` | The owner of the repo that we should pull issues from (e.g. linus in linus/oneblog). If you're using the Vercel deploy button, you don't need to provide this. |
31-
| `NEXT_PUBLIC_GITHUB_REPO_NAME` | The name of the repo that we should pull issues from (e.g. oneblog in linus/oneblog). If you're using the Vercel deploy button, you don't need to provide this. |
32-
33-
### Setup relay
34-
35-
Remove the generated files (they're tied to the OneGraph app they were generated with):
36-
37-
```
38-
yarn relay:clean
39-
# which runs rm -r src/__generated__
40-
```
41-
42-
(Note: any time you change the variables in `.env`, it's a good idea to stop the relay compiler, remove the files in `src/__generated__`, and restart the compiler)
43-
44-
Install dependencies
45-
46-
```
47-
yarn install
48-
```
49-
50-
### Run the Relay compiler
51-
52-
This project uses Relay as its GraphQL client because of its high-quality compiler and great support for persisted queries.
53-
54-
In another terminal window, start the relay compiler
55-
56-
```
57-
yarn relay --watch
58-
```
59-
60-
You may need to install [watchman](https://facebook.github.io/watchman/), a file watching service. On mac, do `brew install watchman`. On Windows or Linux, follow the instructions at [https://facebook.github.io/watchman/docs/install.html](https://facebook.github.io/watchman/docs/install.html).
61-
62-
### Start the server
63-
64-
Now that we've generated the relay files, we can start the server.
65-
66-
```
67-
yarn start
68-
```
69-
70-
The project will load at [http://localhost:3000](http://localhost:3000).
71-
72-
## Deploying
73-
74-
The project comes with setups for deploying to Google's Firebase, Zeit's Now, Netlify, and Fly.io.
75-
76-
For each of these, you'll have to add the site that you're deploying to on the CORS origins on the OneGraph dashboard.
77-
78-
### Deploy with Vercel
79-
80-
Use the deploy button to set up a new repo:
81-
82-
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2FOneGraph%2Foneblog%2Ftree%2Fnext&env=NEXT_PUBLIC_ONEGRAPH_APP_ID,NEXT_PUBLIC_TITLE,OG_GITHUB_TOKEN,OG_DASHBOARD_ACCESS_TOKEN,VERCEL_URL,VERCEL_GITHUB_ORG,VERCEL_GITHUB_REPO&envDescription=Variables%20needed%20to%20build%20your%20OneBlog&envLink=https%3A%2F%2Fgithub.com%2FOneGraph%2Foneblog%2Ftree%2Fnext%23environment-variables&project-name=oneblog&repo-name=oneblog)
83-
84-
If you've already set up the repo, just run the vercel command.
85-
86-
```
87-
# If not installed
88-
# npm i -g vercel
89-
90-
vercel
91-
```
92-
93-
If you see an error when you visit the site, make sure the site's origin is listed in the CORS origins for your app on the OneGraph dashboard.
94-
95-
### Deploying with Firebase
96-
97-
Please open an issue if you'd like help deploying with Firebase.
98-
99-
### Deploying with Netlify
100-
101-
Please open an issue if you'd like help deploying with Netlify.
102-
103-
### Deploying with Fly.io
104-
105-
Please open an issue if you'd like help deploying with Fly.io
106-
107-
## Project setup
108-
109-
### Client
110-
111-
The client is an ordinary React app. The best to place to start is `/src/App.js`.
112-
113-
It uses Grommet as the UI library. Visit [https://v2.grommet.io/components](https://v2.grommet.io/components) to view the documentation for Grommet.
114-
115-
It uses Relay as the GraphQL client. [https://relay.dev/docs/en/graphql-in-relay](https://relay.dev/docs/en/graphql-in-relay) has a good introduction to Relay.
116-
117-
To refresh the GraphQL schema, run `yarn fetch-schema`. That will fetch the schema from OneGraph and add some client-only directives that we use when we persist the queries to OneGraph.
118-
119-
#### How persisting works
120-
121-
The `persistFunction` for the relay compiler is set to `/scripts/persistQuery.js`. Every time a GraphQL query in the project changes, the relay compiler will call that function with the new query.
122-
123-
That function will parse the query and pull out the `@persistedQueryConfiguration` directive to determine if any auth should be stored alongside the query. In the changelog, the queries for fetching posts use persisted auth, but the mutations for adding reactions require the user to log in with OneGraph and use their auth.
124-
125-
The `@persistedQueryConfiguration` directive is stripped from the query and it is uploaded to OneGraph via a GraphQL mutation. Then the id for the persisted query is returned from the function. Relay stores the id in its generated file and it's used the next time the query is sent to the server.
126-
127-
### Server
128-
129-
The server uses [Next.js](https://nextjs.org) to allow us to render the content on the server. This helps with SEO and allows people to view the blog with Javascript turned off.
130-
131-
When a request comes in to the server, the server creates a mock Relay environment and prefetches the query for the route using `fetchQuery` from `relay-runtime`. This populates the record source that Relay uses to render.
132-
133-
React renders the app to a string, which is sent to the client.
134-
135-
On the client, React rehydates the app. To prevent Relay from showing a loading state, we inject the serialized record source with `getStaticProps`. That data is stored in the environment before Relay makes its first query. The `fetchPolicy` opt is set to "store-and-network" so that it uses the data from the store instead of showing a loading state.
13+
Check the cloudbuild-staging.yaml, cloudbuild.yaml, and Dockerfile for implementation details.

cloudbuild-staging.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
steps:
2+
- name: 'gcr.io/cloud-builders/docker'
3+
args: ['build',
4+
'--network=cloudbuild',
5+
'--build-arg', 'gcp_project=oph-dashboard-staging',
6+
'-t', 'gcr.io/oph-dashboard-staging/changelog', '.']
7+
- name: 'gcr.io/cloud-builders/docker'
8+
args: ['push', 'gcr.io/oph-dashboard-staging/changelog']
9+
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
10+
entrypoint: gcloud
11+
args: ['run', 'deploy', 'changelog',
12+
'--image', 'gcr.io/oph-dashboard-staging/changelog',
13+
'--region', 'us-central1',
14+
'--platform', 'managed',
15+
'--concurrency', '80',
16+
'--max-instances', '100',
17+
'--timeout', '5m',
18+
'--memory', '512Mi']
19+
images: ['gcr.io/oph-dashboard-staging/changelog']
20+
timeout: '20m'

cloudbuild.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
steps:
2+
- name: 'gcr.io/cloud-builders/docker'
3+
args: ['build',
4+
'--network=cloudbuild',
5+
'--build-arg', 'gcp_project=onegraph-prod',
6+
'-t', 'gcr.io/onegraph-prod/changelog', '.']
7+
- name: 'gcr.io/cloud-builders/docker'
8+
args: ['push', 'gcr.io/onegraph-prod/changelog']
9+
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
10+
entrypoint: gcloud
11+
args: ['run', 'deploy', 'changelog',
12+
'--image', 'gcr.io/onegraph-prod/changelog',
13+
'--region', 'us-central1',
14+
'--platform', 'managed',
15+
'--concurrency', '80',
16+
'--max-instances', '100',
17+
'--timeout', '5m',
18+
'--memory', '512Mi']
19+
images: ['gcr.io/onegraph-prod/changelog']
20+
timeout: '20m'

dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ FROM node:14 as builder
22

33
COPY package.json .
44
COPY yarn.lock .
5-
COPY .env .
65

76
RUN yarn install
87

98
COPY . .
109

10+
ENV BASE_PATH="/changelog"
1111
ENV NODE_ENV=production
12+
ARG gcp_project
1213

1314
RUN yarn build && rm -rf .next/cache
15+
RUN yarn firebase-deploy-directory --project $gcp_project --subpath changelog/_next/static --directory .next/static/ --commit
1416

1517
# Make smaller prod image
1618
FROM node:14 as node_installer
@@ -24,14 +26,17 @@ RUN yarn install --production
2426

2527
FROM node:14
2628

29+
ENV BASE_PATH="/changelog"
2730
ENV NODE_ENV=production
2831

2932
COPY package.json .
3033
COPY yarn.lock .
31-
COPY .env .
34+
# Copies public environment variables
35+
COPY .env.local .env
3236
COPY server.js.example server.js
3337
COPY next.config.js .
3438

35-
COPY --from=builder .next .next
3639
COPY --from=node_installer node_modules node_modules
40+
COPY --from=builder .next .next
41+
3742
CMD [ "node", "server.js" ]

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@
2121
"pixel-stream": "^1.0.3",
2222
"react": "0.0.0-experimental-94c0244ba",
2323
"react-dom": "0.0.0-experimental-94c0244ba",
24+
"react-embed": "^3.3.2",
2425
"react-intersection-observer": "^8.28.5",
2526
"react-markdown": "^4.3.1",
26-
"react-player": "^2.6.2",
2727
"react-relay": "0.0.0-experimental-183bdd28",
2828
"relay-runtime": "^10.0.1",
29-
"scriptjs": "^2.5.9",
3029
"sentence-case": "^3.0.3",
3130
"sitemap": "^6.3.2",
3231
"styled-components": "^5.0.0"
@@ -38,7 +37,7 @@
3837
"scripts": {
3938
"dev": "next",
4039
"start": "next",
41-
"build": "yarn ensure-publish-label && yarn relay && next build",
40+
"build": "next build",
4241
"start:prod": "NODE_ENV=production node build/server.js",
4342
"relay": "relay-compiler --src ./src --schema ./schema.graphql --persistFunction scripts/persistQuery.js",
4443
"relay:clean": "rm -r src/__generated__",
@@ -76,6 +75,7 @@
7675
"eslint-plugin-jsx-a11y": "6.x",
7776
"eslint-plugin-react": "7.x",
7877
"eslint-plugin-react-hooks": "2.x",
78+
"firebase-deploy-directory": "^1.0.4",
7979
"flow-bin": "^0.133.0",
8080
"flow-typed": "^3.2.1",
8181
"graphql": "^14.4.2",

scripts/persistQuery.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const https = require('https');
2+
const path = require('path');
23
const GraphQLLanguage = require('graphql/language');
34
const {parse, print} = require('graphql');
45

56
require('dotenv').config();
7+
require('dotenv').config({path: path.resolve(process.cwd(), '.env.local')});
68

79
if (
810
(!process.env.REPOSITORY_FIXED_VARIABLES &&

0 commit comments

Comments
 (0)