Skip to content

Commit d462aa3

Browse files
committed
feat: improve graphql docker iamge for deployment
1 parent 4522070 commit d462aa3

File tree

8 files changed

+37
-7
lines changed

8 files changed

+37
-7
lines changed

.github/actions/docker-publish/action.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ inputs:
1919
dockerfile:
2020
description: 'Path to the Dockerfile'
2121
required: true
22+
context:
23+
description: 'Path to the Context'
24+
default: .
25+
required: true
2226
build-args:
2327
description: 'List of build-time variables'
2428
required: false
@@ -65,7 +69,7 @@ runs:
6569
uses: docker/build-push-action@v4
6670
id: publish
6771
with:
68-
context: .
72+
context: ${{ inputs.context }}
6973
file: ${{ inputs.dockerfile }}
7074
push: true
7175
tags: ${{ steps.meta.outputs.tags }}

.github/workflows/docker-publish.yml

+1
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ jobs:
3030
password: ${{ secrets.GITHUB_TOKEN }}
3131
image: ghcr.io/fuellabs/fuel-explorer
3232
dockerfile: deployment/Dockerfile
33+
context: ./packages/graphql

deployment/Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FROM node:20-slim AS base
44

55
# Expose the ENVs to the env of the container
66
ENV PORT="${PORT}"
7-
ENV FUEL_PROVIDER_BETA5="${FUEL_PROVIDER_BETA5}"
7+
ENV FUEL_PROVIDER="${FUEL_PROVIDER:-https://beta-5.fuel.network/graphql}"
88
ENV PNPM_HOME="/pnpm"
99
ENV PATH="$PNPM_HOME:$PATH"
1010

@@ -14,10 +14,10 @@ RUN corepack enable
1414
COPY . /app-explorer
1515
WORKDIR /app-explorer
1616

17-
RUN pnpm install --frozen-lockfile
17+
RUN pnpm install
1818

1919
EXPOSE ${PORT}
2020

21-
WORKDIR /app-explorer/packages/graphql
21+
WORKDIR /app-explorer
2222

23-
CMD ["pnpm", "start"]
23+
CMD ["pnpm", "server:start"]

packages/app-explorer/src/app/api/graphql/route.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { createExecutor, createSchema } from '@fuel-explorer/graphql';
22
import { ContextDomain } from '@fuel-explorer/graphql/src/domains/Context';
33
import { createYoga } from 'graphql-yoga';
4+
import { requireEnv } from '~/systems/utils/requireEnv';
5+
6+
const { FUEL_PROVIDER_BETA5: url } = requireEnv(['FUEL_PROVIDER_BETA5']);
47

5-
const url = process.env.FUEL_PROVIDER_BETA5!;
68
const executor = createExecutor(async ({ body }) => {
79
return fetch(url, {
810
body,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export function requireEnv<
2+
A extends string[],
3+
B extends { [key in A[number]]: string },
4+
>(keys: string[]): B {
5+
return keys.reduce((ret, key) => {
6+
if (!process.env[key]) {
7+
throw new Error(`Environment variable ${key} is required`);
8+
}
9+
ret[key] = process.env[key]!;
10+
return ret;
11+
}, {} as B);
12+
}

packages/graphql/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
"typings": "./src/index.ts",
1111
"scripts": {
1212
"build": "run-s codegen:fuel build:lib",
13-
"build:lib": "tsup --dts",
13+
"build:lib": "tsup",
1414
"build:watch": "pnpm build:lib --watch",
1515
"codegen:fuel": "gql-gen -r dotenv/config --config codegen.fuel.ts",
1616
"codegen:app": "gql-gen -r dotenv/config --config codegen.ts",
1717
"dev": "pnpm build:watch",
18+
"server:start": "node ./dist/index.js",
1819
"fix:generated": "node ./scripts/fix-generated.mjs",
1920
"ts:check": "tsc --noEmit",
2021
"prepare": "pnpm build"
@@ -63,7 +64,9 @@
6364
"execa": "8.0.1",
6465
"graphql-codegen-typescript-common": "0.18.2",
6566
"graphql-codegen-typescript-mock-data": "3.7.1",
67+
"npm-run-all": "^4.1.5",
6668
"tsconfig-paths": "^4.2.0",
69+
"tsup": "8.0.1",
6770
"tsx": "4.7.0"
6871
}
6972
}

packages/graphql/tsup.config.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export default defineConfig((options) => ({
1313
format: ['esm', 'cjs'],
1414
sourcemap: true,
1515
clean: false,
16+
dts: false,
17+
minify: false,
1618
esbuildPlugins: [graphqlLoaderPlugin()],
1719
entry: { index: 'src/bin/index.ts' },
1820
async onSuccess() {

pnpm-lock.yaml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)