From 79ba58c971a13b3b7a42ca90012bbcbac3b668a4 Mon Sep 17 00:00:00 2001 From: nxtcoder17 Date: Tue, 12 Mar 2024 17:04:49 +0530 Subject: [PATCH] fix: gateway supergraph build script updates --- .github/workflows/build-gateway.yml | 7 +------ apps/gateway/.dockerignore | 2 +- apps/gateway/Containerfile | 3 +++ apps/gateway/Taskfile.yml | 11 ++++++++--- apps/gateway/generate-schema.sh | 24 +++++++++++++----------- apps/gateway/src/index.js | 2 +- flake.nix | 4 +++- 7 files changed, 30 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build-gateway.yml b/.github/workflows/build-gateway.yml index 0bfe8bb47..e0f9e29eb 100644 --- a/.github/workflows/build-gateway.yml +++ b/.github/workflows/build-gateway.yml @@ -43,11 +43,6 @@ jobs: # 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 @@ -96,4 +91,4 @@ jobs: set -e cd apps/gateway - task container:build-and-push Image=$image_name:$IMAGE_TAG \ No newline at end of file + task container:build-and-push Image=$image_name:$IMAGE_TAG diff --git a/apps/gateway/.dockerignore b/apps/gateway/.dockerignore index 4004ba20d..e708dc025 100644 --- a/apps/gateway/.dockerignore +++ b/apps/gateway/.dockerignore @@ -2,4 +2,4 @@ !package.json !src !pnpm-lock.yaml -!prod-schema.graphql +!*.graphqls diff --git a/apps/gateway/Containerfile b/apps/gateway/Containerfile index cfc17194f..78c957bd2 100644 --- a/apps/gateway/Containerfile +++ b/apps/gateway/Containerfile @@ -5,4 +5,7 @@ USER node COPY --chown=node package.json pnpm-lock.yaml ./ RUN pnpm i COPY --chown=node . ./ +ARG SUPERGRAPH_FILE +COPY ${SUPERGRAPH_FILE} ./ +ENV SUPERGRAPH_SCHEMA_FILE=${SUPERGRAPH_FILE} ENTRYPOINT ["npm","start"] diff --git a/apps/gateway/Taskfile.yml b/apps/gateway/Taskfile.yml index 10e3b549e..91657e5d7 100644 --- a/apps/gateway/Taskfile.yml +++ b/apps/gateway/Taskfile.yml @@ -6,7 +6,7 @@ vars: tasks: generate-schema: cmds: - - bash ./generate-schema.sh + - bash ./generate-schema.sh {{.Output}} dev: dotenv: - "./.secrets/env" @@ -22,11 +22,16 @@ tasks: - task generate-schema - docker buildx build -f ./Containerfile -t {{.Image}} . + container:build-and-push: preconditions: - sh: '[[ -n "{{.Image}}" ]]' msg: "var Image must have a value, of format 'image_repository:image_tag'" + vars: + SupergraphSchemaFile: "./supergraph.graphqls" cmds: - - docker buildx build -f ./Containerfile -t {{.Image}} . --push - + - task: generate-schema + vars: + Output: "{{.SupergraphSchemaFile}}" + - docker buildx build -f ./Containerfile --build-arg SUPERGRAPH_FILE="{{.SupergraphSchemaFile}}" -t {{.Image}} . --push diff --git a/apps/gateway/generate-schema.sh b/apps/gateway/generate-schema.sh index d7f4850fc..c75a2fa30 100644 --- a/apps/gateway/generate-schema.sh +++ b/apps/gateway/generate-schema.sh @@ -1,20 +1,22 @@ #! /usr/bin/env bash +out=$1 + 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 ../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 ../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 ../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 ../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 +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 +rover supergraph compose --config ./supergraph.yml --output "$out" --elv2-license accept diff --git a/apps/gateway/src/index.js b/apps/gateway/src/index.js index c909084a8..17ec93312 100644 --- a/apps/gateway/src/index.js +++ b/apps/gateway/src/index.js @@ -37,7 +37,7 @@ class CustomDataSource extends RemoteGraphQLDataSource { } } -const superGraphSchema = await fs.readFile("./prod-schema.graphql"); +const superGraphSchema = await fs.readFile(useEnv("SUPERGRAPH_SCHEMA_FILE")); const gateway = new ApolloGateway({ supergraphSdl: superGraphSchema.toString(), diff --git a/flake.nix b/flake.nix index dfb7605a2..b28090bfa 100644 --- a/flake.nix +++ b/flake.nix @@ -35,7 +35,7 @@ # source version control git pre-commit - (python312.withPackages(ps: with ps; [ + (python312.withPackages (ps: with ps; [ ggshield ])) @@ -58,6 +58,8 @@ # build tools podman upx + + rover ]; shellHook = ''