Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.
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
99 changes: 99 additions & 0 deletions .github/workflows/build-gateway.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: build-gateway-images

on:
workflow_dispatch:

repository_dispatch:
types:
- webhook

push:
paths:
- "apps/**/graph/*.graphqls"
- "apps/**/graph/struct-to-graphql/*.graphqls"
- "apps/gateway/**"
- ".github/workflows/build-gateway.yml"

permissions:
contents: read
packages: write

jobs:
docker-builds:
runs-on: ubuntu-latest
name: Deploy to Docker Image
steps:
- name: Checkout
uses: actions/checkout@v3

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

- name: Install Task
uses: arduino/setup-task@v1
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Install Rover
run: |
curl -sSL https://rover.apollo.dev/nix/v0.23.0-rc.3 | sh

# Add Rover to the $GITHUB_PATH so it can be used in another step
# https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#adding-a-system-path
echo "$HOME/.rover/bin" >> $GITHUB_PATH

- name: Generate Schema
run: |
cd apps/gateway
task generate-schema

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create Image Tag from branch name
if: startsWith(github.ref, 'refs/heads/release')
run: |
set +e
IMAGE_TAG=$(echo ${GITHUB_REF#refs/heads/} | sed 's/release-//g')
echo "$IMAGE_TAG" | grep -i '\-nightly$'
if [ $? -ne 0 ]; then
IMAGE_TAG="$IMAGE_TAG-nightly"
fi
set -e

echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
echo "OVERRIDE_PUSHED_IMAGE=true" >> $GITHUB_ENV

- name: Create Image Tag from tag
if: startsWith(github.ref, 'refs/tags/')
run: |
IMAGE_TAG=$(echo ${GITHUB_REF#refs/tags/})

echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
echo "OVERRIDE_PUSHED_IMAGE=false" >> $GITHUB_ENV

- name: Build & Push Image
if: startsWith(github.ref, 'refs/heads/release') || startsWith(github.ref, 'refs/tags/')
run: |
set +e
image_name="ghcr.io/${{ github.repository }}/gateway"

docker manifest inspect $image_name:$IMAGE_TAG
exit_status=$?
if [ $exit_status -eq 0 ]; then
[ "$OVERRIDE_PUSHED_IMAGE" = "false" ] && echo "image ($image_name:$IMAGE_TAG) already exists, and override image is disable, exiting" && exit 0
echo "image exists, but override pushed image is set to true. proceeding with building image"
fi

set -e

cd apps/gateway
task container:build-and-push Image=$image_name:$IMAGE_TAG
1 change: 1 addition & 0 deletions apps/gateway/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
!package.json
!src
!pnpm-lock.yaml
!prod-schema.graphql
2 changes: 2 additions & 0 deletions apps/gateway/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schemas
prod-schema.graphql
11 changes: 11 additions & 0 deletions apps/gateway/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@ vars:
app: gateway

tasks:
generate-schema:
cmds:
- bash ./generate-schema.sh
dev:
dotenv:
- "./.secrets/env"
interactive: true
cmds:
- npm start

local:build:
preconditions:
- sh: '[[ -n "{{.Image}}" ]]'
msg: "var Image must have a value, of format 'image_repository:image_tag'"
cmds:
- task generate-schema
- docker buildx build -f ./Containerfile -t {{.Image}} .

container:build-and-push:
preconditions:
- sh: '[[ -n "{{.Image}}" ]]'
Expand Down
20 changes: 20 additions & 0 deletions apps/gateway/generate-schema.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /usr/bin/env bash

mkdir -p schemas

cat ../accounts/internal/app/graph/*.graphqls > ./schemas/accounts-api.schema
cat ../accounts/internal/app/graph/struct-to-graphql/*.graphqls >> ./schemas/accounts-api.schema

cat ../console/internal/app/graph/*.graphqls > ./schemas/console-api.schema
cat ../console/internal/app/graph/struct-to-graphql/*.graphqls >> ./schemas/console-api.schema

cat ../container-registry/internal/app/graph/*.graphqls > ./schemas/container-registry-api.schema
cat ../container-registry/internal/app/graph/struct-to-graphql/*.graphqls >> ./schemas/container-registry-api.schema

cat ../infra/internal/app/graph/*.graphqls > ./schemas/infra-api.schema
cat ../infra/internal/app/graph/struct-to-graphql/*.graphqls >> ./schemas/infra-api.schema

cat ../auth/internal/app/graph/*.graphqls > ./schemas/auth-api.schema
cat ../message-office/internal/app/graph/*.graphqls > ./schemas/message-office-api.schema

rover supergraph compose --config ./supergraph.yml --output prod-schema.graphql --elv2-license accept
8 changes: 4 additions & 4 deletions apps/gateway/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const useEnv = (key) => {
return v
};

const cfgMap = yaml.load(await fs.readFile(useEnv("SUPERGRAPH_CONFIG"), 'utf8'));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (performance): Consider using asynchronous file reading with fs.promises.readFile instead of fs.readFileSync to avoid blocking the event loop, especially since this operation is performed at the startup.

Suggested change
-const superGraphSchema = fs.readFileSync("./prod-schema.graphql");
+const superGraphSchema = await fs.promises.readFile("./prod-schema.graphql", "utf-8");


class CustomDataSource extends RemoteGraphQLDataSource {
// eslint-disable-next-line class-methods-use-this
Expand All @@ -37,10 +37,10 @@ class CustomDataSource extends RemoteGraphQLDataSource {
}
}

const superGraphSchema = await fs.readFile("./prod-schema.graphql");

const gateway = new ApolloGateway({
supergraphSdl: new IntrospectAndCompose({
subgraphs: cfgMap.serviceList,
}),
supergraphSdl: superGraphSchema.toString(),
buildService({ name, url }) {
return new CustomDataSource({ name, url });
},
Expand Down
22 changes: 22 additions & 0 deletions apps/gateway/supergraph.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
federation_version: =2.3.2
subgraphs:
auth-api:
routing_url: http://auth-api
schema:
file: ./schemas/auth-api.schema
account-api:
routing_url: https://accounts-api
schema:
file: ./schemas/accounts-api.schema
container-registry-api:
routing_url: https://container-registry-api
schema:
file: ./schemas/container-registry-api.schema
console-api:
routing_url: https://console-api
schema:
file: ./schemas/console-api.schema
infra-api:
routing_url: https://infra-api
schema:
file: ./schemas/infra-api.schema