Skip to content

Commit 9675cf7

Browse files
committed
Initial commit
0 parents  commit 9675cf7

File tree

171 files changed

+16673
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+16673
-0
lines changed

.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.git
2+
.github
3+
.env
4+
**/node_modules
5+
**/README.md
6+
**/build
7+
docker-compose.yml
8+
.k8s
9+
.terraform
10+
.npmrc
11+
key.json

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
NPM_TOKEN=
2+
NEXT_PUBLIC_BASE_PATH=/docs

.eslintrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "next/core-web-vitals",
3+
"rules": {
4+
"import/no-anonymous-default-export": "off",
5+
"@next/next/no-img-element": "off"
6+
}
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
set -e # immediately fail the script on any command error
3+
4+
# wait 5 min for the new pod to be ready. If the pod is not ready there is a problem with the new container
5+
for APP_NAME in "$@"
6+
do
7+
kubectl wait pod --for condition=Ready --timeout=300s \
8+
$(kubectl get pods -l app=$APP_NAME --sort-by {.metadata.creationTimestamp} -o jsonpath={.items[-1].metadata.name})
9+
done

.github/scripts/kustomize-apply.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
set -e # immediately fail the script on any command error
3+
4+
ENVIRONMENT="$1"
5+
IMAGE="$2"
6+
DIR=$(dirname "$0")
7+
cd $DIR/../../.k8s/$ENVIRONMENT
8+
9+
kustomize edit set image $IMAGE
10+
kustomize build | kubectl apply -f -
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
headers: {
3+
accept: 'text/html', // this avoids graphql endpoint error by returning the playground html
4+
},
5+
}

.github/scripts/npx-wait-on/run.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
set -e # immediately fail the script on any command error
3+
4+
DIR=$(dirname "$0")
5+
TIMEOUT_MS=10000
6+
7+
npx wait-on \
8+
--verbose \
9+
--config $DIR/config.js \
10+
--timeout=$TIMEOUT_MS \
11+
"$@"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Production CI/CD
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
env:
9+
BASE_IMAGE: ghcr.io/graphprotocol/graph-docs-production
10+
HEALTH_CHECK_URL: https://thegraph.com/docs
11+
APP_NAME: graph-docs
12+
NEXT_PUBLIC_BASE_PATH: /docs
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout the repo
19+
uses: actions/checkout@v2
20+
21+
- name: Login to GitHub Container Registry
22+
uses: docker/login-action@v1
23+
with:
24+
registry: ghcr.io
25+
username: Jannis
26+
password: ${{ secrets.GH_ACCESS_TOKEN_JANNIS }}
27+
28+
- name: Build and push Docker image
29+
uses: docker/build-push-action@v2
30+
with:
31+
context: . # required to respect .dockerignore
32+
cache-from: type=registry,ref=${{ env.BASE_IMAGE }}:latest
33+
cache-to: type=inline
34+
secrets: npmrc=//registry.npmjs.org/:_authToken=${{ secrets.NPM_SECRET_TOKEN }}
35+
tags: |
36+
${{ env.BASE_IMAGE }}:${{ github.sha }}
37+
${{ env.BASE_IMAGE }}:latest
38+
push: true
39+
build-args: NEXT_PUBLIC_BASE_PATH=${{ env.NEXT_PUBLIC_BASE_PATH }}
40+
41+
deploy:
42+
runs-on: ubuntu-latest
43+
needs: build
44+
steps:
45+
- name: Checkout the repo
46+
uses: actions/checkout@v2
47+
48+
- name: Set up kubectl
49+
uses: google-github-actions/get-gke-credentials@main
50+
with:
51+
cluster_name: hosted-service
52+
location: us-central1-a
53+
credentials: ${{ secrets.GCP_SA_KEY_PRODUCTION }}
54+
55+
- name: Set a new k8s image and apply the manifests
56+
run: .github/scripts/kustomize-apply.sh production $APP_NAME=$BASE_IMAGE:$GITHUB_SHA
57+
58+
- name: Wait for pods to be ready
59+
run: .github/scripts/kubectl-wait-ready.sh $APP_NAME
60+
61+
- name: Check the endpoints
62+
run: .github/scripts/npx-wait-on/run.sh $HEALTH_CHECK_URL
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Staging CI/CD
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
env:
9+
BASE_IMAGE: ghcr.io/graphprotocol/graph-docs-staging
10+
HEALTH_CHECK_URL: https://staging.thegraph.com/docs
11+
APP_NAME: graph-docs
12+
NEXT_PUBLIC_BASE_PATH: /docs
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout the repo
19+
uses: actions/checkout@v2
20+
21+
- name: Login to GitHub Container Registry
22+
uses: docker/login-action@v1
23+
with:
24+
registry: ghcr.io
25+
username: Jannis
26+
password: ${{ secrets.GH_ACCESS_TOKEN_JANNIS }}
27+
28+
- name: Build and push Docker image
29+
uses: docker/build-push-action@v2
30+
with:
31+
context: . # required to respect .dockerignore
32+
cache-from: type=registry,ref=${{ env.BASE_IMAGE }}:latest
33+
cache-to: type=inline
34+
secrets: npmrc=//registry.npmjs.org/:_authToken=${{ secrets.NPM_SECRET_TOKEN }}
35+
tags: |
36+
${{ env.BASE_IMAGE }}:${{ github.sha }}
37+
${{ env.BASE_IMAGE }}:latest
38+
push: true
39+
build-args: NEXT_PUBLIC_BASE_PATH=${{ env.NEXT_PUBLIC_BASE_PATH }}
40+
41+
deploy:
42+
runs-on: ubuntu-latest
43+
needs: build
44+
steps:
45+
- name: Checkout the repo
46+
uses: actions/checkout@v2
47+
48+
- name: Set up kubectl
49+
uses: google-github-actions/get-gke-credentials@main
50+
with:
51+
cluster_name: hosted-service
52+
location: us-central1-a
53+
credentials: ${{ secrets.GCP_SA_KEY_STAGING }}
54+
55+
- name: Set a new k8s image and apply the manifests
56+
run: .github/scripts/kustomize-apply.sh staging $APP_NAME=$BASE_IMAGE:$GITHUB_SHA
57+
58+
- name: Wait for pods to be ready
59+
run: .github/scripts/kubectl-wait-ready.sh $APP_NAME
60+
61+
- name: Check the endpoints
62+
run: .github/scripts/npx-wait-on/run.sh $HEALTH_CHECK_URL

.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# dependencies
2+
/node_modules
3+
/.pnp
4+
.pnp.js
5+
.yalc
6+
yalc.lock
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
.next
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env.local
29+
.env.development.local
30+
.env.test.local
31+
.env.production.local
32+
33+
# vercel
34+
.vercel
35+
36+
# typescript
37+
*.tsbuildinfo

0 commit comments

Comments
 (0)