Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
benface committed Dec 20, 2021
0 parents commit 9675cf7
Show file tree
Hide file tree
Showing 171 changed files with 16,673 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.git
.github
.env
**/node_modules
**/README.md
**/build
docker-compose.yml
.k8s
.terraform
.npmrc
key.json
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NPM_TOKEN=
NEXT_PUBLIC_BASE_PATH=/docs
7 changes: 7 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "next/core-web-vitals",
"rules": {
"import/no-anonymous-default-export": "off",
"@next/next/no-img-element": "off"
}
}
9 changes: 9 additions & 0 deletions .github/scripts/kubectl-wait-ready.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
set -e # immediately fail the script on any command error

# wait 5 min for the new pod to be ready. If the pod is not ready there is a problem with the new container
for APP_NAME in "$@"
do
kubectl wait pod --for condition=Ready --timeout=300s \
$(kubectl get pods -l app=$APP_NAME --sort-by {.metadata.creationTimestamp} -o jsonpath={.items[-1].metadata.name})
done
10 changes: 10 additions & 0 deletions .github/scripts/kustomize-apply.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
set -e # immediately fail the script on any command error

ENVIRONMENT="$1"
IMAGE="$2"
DIR=$(dirname "$0")
cd $DIR/../../.k8s/$ENVIRONMENT

kustomize edit set image $IMAGE
kustomize build | kubectl apply -f -
5 changes: 5 additions & 0 deletions .github/scripts/npx-wait-on/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
headers: {
accept: 'text/html', // this avoids graphql endpoint error by returning the playground html
},
}
11 changes: 11 additions & 0 deletions .github/scripts/npx-wait-on/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
set -e # immediately fail the script on any command error

DIR=$(dirname "$0")
TIMEOUT_MS=10000

npx wait-on \
--verbose \
--config $DIR/config.js \
--timeout=$TIMEOUT_MS \
"$@"
62 changes: 62 additions & 0 deletions .github/workflows/ci-cd-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Production CI/CD

on:
push:
tags:
- v*

env:
BASE_IMAGE: ghcr.io/graphprotocol/graph-docs-production
HEALTH_CHECK_URL: https://thegraph.com/docs
APP_NAME: graph-docs
NEXT_PUBLIC_BASE_PATH: /docs

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: Jannis
password: ${{ secrets.GH_ACCESS_TOKEN_JANNIS }}

- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: . # required to respect .dockerignore
cache-from: type=registry,ref=${{ env.BASE_IMAGE }}:latest
cache-to: type=inline
secrets: npmrc=//registry.npmjs.org/:_authToken=${{ secrets.NPM_SECRET_TOKEN }}
tags: |
${{ env.BASE_IMAGE }}:${{ github.sha }}
${{ env.BASE_IMAGE }}:latest
push: true
build-args: NEXT_PUBLIC_BASE_PATH=${{ env.NEXT_PUBLIC_BASE_PATH }}

deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout the repo
uses: actions/checkout@v2

- name: Set up kubectl
uses: google-github-actions/get-gke-credentials@main
with:
cluster_name: hosted-service
location: us-central1-a
credentials: ${{ secrets.GCP_SA_KEY_PRODUCTION }}

- name: Set a new k8s image and apply the manifests
run: .github/scripts/kustomize-apply.sh production $APP_NAME=$BASE_IMAGE:$GITHUB_SHA

- name: Wait for pods to be ready
run: .github/scripts/kubectl-wait-ready.sh $APP_NAME

- name: Check the endpoints
run: .github/scripts/npx-wait-on/run.sh $HEALTH_CHECK_URL
62 changes: 62 additions & 0 deletions .github/workflows/ci-cd-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Staging CI/CD

on:
push:
branches:
- main

env:
BASE_IMAGE: ghcr.io/graphprotocol/graph-docs-staging
HEALTH_CHECK_URL: https://staging.thegraph.com/docs
APP_NAME: graph-docs
NEXT_PUBLIC_BASE_PATH: /docs

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: Jannis
password: ${{ secrets.GH_ACCESS_TOKEN_JANNIS }}

- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: . # required to respect .dockerignore
cache-from: type=registry,ref=${{ env.BASE_IMAGE }}:latest
cache-to: type=inline
secrets: npmrc=//registry.npmjs.org/:_authToken=${{ secrets.NPM_SECRET_TOKEN }}
tags: |
${{ env.BASE_IMAGE }}:${{ github.sha }}
${{ env.BASE_IMAGE }}:latest
push: true
build-args: NEXT_PUBLIC_BASE_PATH=${{ env.NEXT_PUBLIC_BASE_PATH }}

deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout the repo
uses: actions/checkout@v2

- name: Set up kubectl
uses: google-github-actions/get-gke-credentials@main
with:
cluster_name: hosted-service
location: us-central1-a
credentials: ${{ secrets.GCP_SA_KEY_STAGING }}

- name: Set a new k8s image and apply the manifests
run: .github/scripts/kustomize-apply.sh staging $APP_NAME=$BASE_IMAGE:$GITHUB_SHA

- name: Wait for pods to be ready
run: .github/scripts/kubectl-wait-ready.sh $APP_NAME

- name: Check the endpoints
run: .github/scripts/npx-wait-on/run.sh $HEALTH_CHECK_URL
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# dependencies
/node_modules
/.pnp
.pnp.js
.yalc
yalc.lock

# testing
/coverage

# next.js
.next
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel

# typescript
*.tsbuildinfo
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn build
26 changes: 26 additions & 0 deletions .k8s/base/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: graph-docs
spec:
replicas: 1
selector:
matchLabels:
app: graph-docs
template:
metadata:
labels:
app: graph-docs
spec:
imagePullSecrets:
- name: docker-registry
containers:
- name: app
image: graph-docs
ports:
- name: http
containerPort: 80
protocol: TCP
readinessProbe:
httpGet:
port: http
3 changes: 3 additions & 0 deletions .k8s/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resources:
- deployment.yaml
- service.yaml
12 changes: 12 additions & 0 deletions .k8s/base/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: graph-docs
spec:
type: ClusterIP
selector:
app: graph-docs
ports:
- name: http
port: 80
protocol: TCP
1 change: 1 addition & 0 deletions .k8s/production/auth.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gcloud container clusters get-credentials hosted-service --project the-graph-production --zone us-central1-a
6 changes: 6 additions & 0 deletions .k8s/production/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: graph-docs
spec:
replicas: 5
15 changes: 15 additions & 0 deletions .k8s/production/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: graph-docs
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: thegraph.com
http:
paths:
- path: /docs
backend:
serviceName: graph-docs
servicePort: http
8 changes: 8 additions & 0 deletions .k8s/production/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
bases:
- ../base
resources:
- ingress.yaml
patchesStrategicMerge:
- deployment.yaml
1 change: 1 addition & 0 deletions .k8s/staging/auth.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gcloud container clusters get-credentials hosted-service --project the-graph-staging --zone us-central1-a
15 changes: 15 additions & 0 deletions .k8s/staging/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: graph-docs
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: staging.thegraph.com
http:
paths:
- path: /docs
backend:
serviceName: graph-docs
servicePort: http
6 changes: 6 additions & 0 deletions .k8s/staging/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
bases:
- ../base
resources:
- ingress.yaml
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.yalc
.next
/out/
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"semi": false,
"printWidth": 120
}
1 change: 1 addition & 0 deletions .terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.terraform*
24 changes: 24 additions & 0 deletions .terraform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Graph Docs Terraform configs

## Setup

Initialize terraform and apply:

```
terraform init
terraform apply
```

Get service account JSON keys and add as github repo secrets:

1. `GCP_SA_KEY_STAGING`

```
terraform show -json | jq -r '.values.root_module.child_modules[] | select(.address=="module.staging") | .resources[] | select(.address=="module.staging.google_service_account_key.graph-docs-ci-cd") | .values.private_key' | base64 -d
```

2. `GCP_SA_KEY_PRODUCTION`

```
terraform show -json | jq -r '.values.root_module.child_modules[] | select(.address=="module.production") | .resources[] | select(.address=="module.production.google_service_account_key.graph-docs-ci-cd") | .values.private_key' | base64 -d
```
7 changes: 7 additions & 0 deletions .terraform/config.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# gsutil mb gs://tf-state-graph-docs
terraform {
backend "gcs" {
bucket = "tf-state-graph-docs"
}
}
9 changes: 9 additions & 0 deletions .terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module staging {
source = "./module"
project = "the-graph-staging"
}

module production {
source = "./module"
project = "the-graph-production"
}
Loading

0 comments on commit 9675cf7

Please sign in to comment.