Skip to content
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
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules
docs
docker
!docker/app-e2e-test-env
!docker/scripts
Dockerfile
Dockerfile.dev
.git
.gitignore
.env
build
57 changes: 57 additions & 0 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Build Docker Image (and push to registry if main or staging)

on:
push:
branches:
- main
- staging
pull_request:
branches:
- main

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Setup buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKER_USERNAME }}/multiplayer

- uses: actions/setup-node@v4
with:
node-version: 22

- name: Install deps. Unnecessary but cannot download the schema without this. Got a better idea? Open a PR!
run: npm ci

- name: Download GQL schema from main
run: GRAPHQL_URL=https://drips-multichain-api.up.railway.app/ GRAPHQL_ACCESS_TOKEN=${{ secrets.GRAPHQL_ACCESS_TOKEN }} ./scripts/generate-schema.sh

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile.dockerhub
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/arm64
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,5 @@ dist
**/__generated__/

.idea/

schema.graphql
23 changes: 23 additions & 0 deletions Dockerfile.dockerhub
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM node:22

ARG SKIP_BUILD=false

WORKDIR /app

# Copies both package.json and package-lock.json
COPY package*.json ./
# Install dependencies
RUN npm ci --ignore-scripts;

COPY . .

# Check on schema.graphql file being present in root dir, if not print error
RUN if [ "$SKIP_BUILD" = "false" ]; then test -f schema.graphql || (echo "schema.graphql file not found in root directory. Run gql:generate-schema before trying to build the container." && exit 1); fi

# This relies on schema.graphql file being present in the root dir.
RUN if [ "$SKIP_BUILD" = "false" ]; then npm run gql:build-types; fi

RUN if [ "$SKIP_BUILD" = "false" ]; then npx tsc; fi
RUN if [ "$SKIP_BUILD" = "false" ]; then npm run copy-abis; fi

CMD ["node", "dist/src/main.js"]
10 changes: 1 addition & 9 deletions codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@ import 'dotenv/config';
import type { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
schema: [
{
[process.env.GRAPHQL_URL]: {
headers: {
Authorization: `Bearer ${process.env.GRAPHQL_ACCESS_TOKEN}`,
},
},
},
],
schema: './schema.graphql',
generates: {
'./src/application/__generated__/graphql/base-types.ts': {
plugins: ['typescript', 'typescript-operations'],
Expand Down
28 changes: 28 additions & 0 deletions generate-schema.codegen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'dotenv/config';
import type { CodegenConfig } from '@graphql-codegen/cli';
import shouldNeverHappen from './src/application/shouldNeverHappen';

if (!process.env.GRAPHQL_ACCESS_TOKEN || !process.env.GRAPHQL_URL) {
throw new Error(
`In order to build GraphQL types, you must provide GRAPHQL_URL and GRAPHQL_ACCESS_TOKEN env vars for the Drips GraphQL API.`,
);
}

const config: CodegenConfig = {
schema: [
{
[process.env.GRAPHQL_URL ?? shouldNeverHappen()]: {
headers: {
Authorization: `Bearer ${process.env.GRAPHQL_ACCESS_TOKEN}`,
},
},
},
],
generates: {
'./schema.graphql': {
plugins: ['schema-ast'],
},
},
};

export default config;
Loading
Loading