Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pull request preview with graphql #42

Merged
merged 22 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.next
.vercel
.turbo
dist
35 changes: 35 additions & 0 deletions .github/workflows/pr-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Deploy preview

on:
pull_request:
branches: [main]
types: [labeled, unlabeled, synchronize, closed, reopened]

jobs:
deploy:
permissions:
contents: read
deployments: write
pull-requests: write
statuses: write
name: deploy
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3

- name: Add pullpreview label
if: ${{ github.event.action == 'opened' || github.event.action == 'synchronize' }}
uses: KeisukeYamashita/attach-labels@v1
with:
labels: pullpreview
token: ${{ secrets.GITHUB_TOKEN }}

- uses: pullpreview/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
compose_files: .preview/docker-compose.yml
env:
AWS_ACCESS_KEY_ID: "${{ secrets.AWS_ACCESS_KEY_ID }}"
AWS_SECRET_ACCESS_KEY: "${{ secrets.AWS_SECRET_ACCESS_KEY }}"
AWS_REGION: "us-east-1"
2 changes: 1 addition & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: "PR Checks"

on:
pull_request:
types: [opened, synchronize, edited, closed]
types: [opened, synchronize, edited]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand Down
27 changes: 27 additions & 0 deletions .preview/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM node:20-slim AS base

# Receive envs on build time
ARG IS_PREVIEW
ARG GRAPHQL_API
ARG FUEL_PROVIDER_URL

# Expose the args to the env of the container
ENV IS_PREVIEW="${IS_PREVIEW}"
ENV GRAPHQL_API="${GRAPHQL_API}"
ENV FUEL_PROVIDER_URL="${FUEL_PROVIDER_URL}"

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

RUN corepack enable

COPY . /preview

WORKDIR /preview

RUN pnpm install --frozen-lockfile
RUN pnpm build:preview

EXPOSE 3000

CMD ["pnpm", "start"]
16 changes: 16 additions & 0 deletions .preview/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3.9'

services:
fuel-explorer:
platform: linux/amd64
container_name: fuel-explorer
build:
context: ../
dockerfile: ./.preview/Dockerfile
args:
IS_PREVIEW: true
GRAPHQL_API: http://localhost:4444/graphql
FUEL_PROVIDER_URL: http://beta-4.fuel.network/graphql
ports:
- '80:3000'
- '4000:4444'
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
"clean:indexer": "pnpm --filter=indexer clean",
"deploy:indexer": "pnpm --filter=indexer run deploy",
"deps:update": "updates -gu && pnpm -r exec updates -gu",
"dev": "pnpm turbo:run dev --filter=!indexer",
"dev": "pnpm turbo:run --filter=!indexer dev",
"dev:app": "pnpm --filter=app dev",
"dev:graphql": "pnpm --filter=graphql dev",
"dev:indexer": "pnpm --filter=indexer dev:indexer",
"start": "pnpm turbo:run --filter=!indexer start",
"lint": "run-s lint:check prettier:check",
"lint:check": "pnpm turbo:run lint",
"node:clean": "make -C ./docker clean",
Expand Down
13 changes: 13 additions & 0 deletions packages/app/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ const config = {
eslint: {
ignoreDuringBuilds: !!process.env.CI,
},
rewrites: async () => {
// This is as proxy route to enable next.js
// to proxy requests to the graphql server on
// preview environment.
return process.env.IS_PREVIEW
? [
{
source: '/graphql',
destination: process.env.GRAPHQL_API,
},
]
: [];
},
redirects: async () => {
return [
{
Expand Down
5 changes: 5 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"$schema": "https://turbo.build/schema.json",
"globalEnv": ["NODE_ENV", "IS_PREVIEW", "FUEL_PROVIDER_URL", "GRAPHQL_API"],
"pipeline": {
"build": {
"outputs": ["dist/**", "build/**", ".next/**"],
Expand All @@ -25,6 +27,9 @@
},
"lint": {
"cache": true
},
"start": {
"cache": false
}
}
}