From 353ff388eb3c69798113574e7e9de11597972827 Mon Sep 17 00:00:00 2001 From: williams-jack Date: Thu, 25 Jul 2024 20:45:59 -0400 Subject: [PATCH] refactor: no build key needed for grader build reqs --- .../api/src/__mocks__/grader-image-build-request.ts | 1 - .../packages/common/src/types/image-build-service.ts | 1 - .../validations/__mocks__/grader-image-build-request.ts | 1 - .../src/validations/schemas/grader-image-build-request.ts | 1 - .../migration.sql | 4 ---- orchestrator/packages/db/prisma/schema.prisma | 3 --- .../db/src/server-operations/enqueue-image-build.ts | 3 +-- orchestrator/packages/image-build-service/src/index.ts | 1 - .../src/process-request/__tests__/image-creation.test.ts | 1 - orchestrator/packages/image-build-service/src/utils.ts | 7 ++----- 10 files changed, 3 insertions(+), 20 deletions(-) rename orchestrator/packages/db/prisma/migrations/{20240720201049_init => 20240725233443_init}/migration.sql (94%) diff --git a/orchestrator/packages/api/src/__mocks__/grader-image-build-request.ts b/orchestrator/packages/api/src/__mocks__/grader-image-build-request.ts index f8e78bea..5ef4d3a2 100644 --- a/orchestrator/packages/api/src/__mocks__/grader-image-build-request.ts +++ b/orchestrator/packages/api/src/__mocks__/grader-image-build-request.ts @@ -4,5 +4,4 @@ export const defaultGraderImageBuildRequest: GraderImageBuildRequest = { dockerfile_contents: `FROM hello-world:latest`, dockerfile_sha_sum: "generated-sha-sum", response_url: "http://example.com/response", - build_key: "{\"grader_id\": 1}" }; diff --git a/orchestrator/packages/common/src/types/image-build-service.ts b/orchestrator/packages/common/src/types/image-build-service.ts index 8cc78b67..ec0b8085 100644 --- a/orchestrator/packages/common/src/types/image-build-service.ts +++ b/orchestrator/packages/common/src/types/image-build-service.ts @@ -23,5 +23,4 @@ export interface GraderImageBuildRequest { dockerfile_contents: string, dockerfile_sha_sum: string, response_url: string, - build_key: string, } diff --git a/orchestrator/packages/common/src/validations/__mocks__/grader-image-build-request.ts b/orchestrator/packages/common/src/validations/__mocks__/grader-image-build-request.ts index 84176eb9..2cd8d3e1 100644 --- a/orchestrator/packages/common/src/validations/__mocks__/grader-image-build-request.ts +++ b/orchestrator/packages/common/src/validations/__mocks__/grader-image-build-request.ts @@ -4,5 +4,4 @@ export const defaultGraderImageBuildRequest: GraderImageBuildRequest = { dockerfile_contents: `FROM hello-world:latest`, dockerfile_sha_sum: "generated-sha-sum", response_url: "http://example.com/response", - build_key: "{\"grader_id\": 1}" }; diff --git a/orchestrator/packages/common/src/validations/schemas/grader-image-build-request.ts b/orchestrator/packages/common/src/validations/schemas/grader-image-build-request.ts index f033fb80..c4ae05c0 100644 --- a/orchestrator/packages/common/src/validations/schemas/grader-image-build-request.ts +++ b/orchestrator/packages/common/src/validations/schemas/grader-image-build-request.ts @@ -5,6 +5,5 @@ export const graderImageBuildRequestSchema = { dockerfile_contents: { type: "string" }, dockerfile_sha_sum: { type: "string" }, response_url: { type: "string" }, - build_key: { type: "string" }, }, } as const; diff --git a/orchestrator/packages/db/prisma/migrations/20240720201049_init/migration.sql b/orchestrator/packages/db/prisma/migrations/20240725233443_init/migration.sql similarity index 94% rename from orchestrator/packages/db/prisma/migrations/20240720201049_init/migration.sql rename to orchestrator/packages/db/prisma/migrations/20240725233443_init/migration.sql index f11a1e9e..0d15730d 100644 --- a/orchestrator/packages/db/prisma/migrations/20240720201049_init/migration.sql +++ b/orchestrator/packages/db/prisma/migrations/20240725233443_init/migration.sql @@ -38,7 +38,6 @@ CREATE TABLE "Job" ( CREATE TABLE "ImageBuildInfo" ( "dockerfileSHA" TEXT NOT NULL, "dockerfileContent" TEXT NOT NULL, - "buildKey" TEXT NOT NULL, "responseURL" TEXT NOT NULL, "inProgress" BOOLEAN NOT NULL DEFAULT false, "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, @@ -67,9 +66,6 @@ CREATE UNIQUE INDEX "Submitter_clientURL_collationType_collationID_key" ON "Subm -- CreateIndex CREATE UNIQUE INDEX "Job_clientURL_clientKey_key" ON "Job"("clientURL", "clientKey"); --- CreateIndex -CREATE UNIQUE INDEX "ImageBuildInfo_buildKey_responseURL_key" ON "ImageBuildInfo"("buildKey", "responseURL"); - -- CreateIndex CREATE UNIQUE INDEX "JobConfigAwaitingImage_clientKey_clientURL_key" ON "JobConfigAwaitingImage"("clientKey", "clientURL"); diff --git a/orchestrator/packages/db/prisma/schema.prisma b/orchestrator/packages/db/prisma/schema.prisma index 64ddf051..934c6210 100644 --- a/orchestrator/packages/db/prisma/schema.prisma +++ b/orchestrator/packages/db/prisma/schema.prisma @@ -60,14 +60,11 @@ model Job { model ImageBuildInfo { dockerfileSHA String @id dockerfileContent String - buildKey String responseURL String inProgress Boolean @default(false) createdAt DateTime @default(now()) jobConfigs JobConfigAwaitingImage[] - - @@unique([buildKey, responseURL]) } model JobConfigAwaitingImage { diff --git a/orchestrator/packages/db/src/server-operations/enqueue-image-build.ts b/orchestrator/packages/db/src/server-operations/enqueue-image-build.ts index fdd57b15..487f3959 100644 --- a/orchestrator/packages/db/src/server-operations/enqueue-image-build.ts +++ b/orchestrator/packages/db/src/server-operations/enqueue-image-build.ts @@ -1,7 +1,7 @@ import { GraderImageBuildRequest } from '@codegrade-orca/common'; import prismaInstance from '../prisma-instance'; -const enqueueImageBuild = ({ dockerfile_sha_sum, dockerfile_contents, response_url, build_key }: GraderImageBuildRequest): Promise => { +const enqueueImageBuild = ({ dockerfile_sha_sum, dockerfile_contents, response_url }: GraderImageBuildRequest): Promise => { return prismaInstance.$transaction(async (tx) => { const buildInfoAlreadyExists = (await tx.imageBuildInfo.count({ where: { @@ -16,7 +16,6 @@ const enqueueImageBuild = ({ dockerfile_sha_sum, dockerfile_contents, response_u dockerfileSHA: dockerfile_sha_sum, dockerfileContent: dockerfile_contents, responseURL: response_url, - buildKey: build_key } }); return true; diff --git a/orchestrator/packages/image-build-service/src/index.ts b/orchestrator/packages/image-build-service/src/index.ts index eeb44997..f87f00fb 100644 --- a/orchestrator/packages/image-build-service/src/index.ts +++ b/orchestrator/packages/image-build-service/src/index.ts @@ -26,7 +26,6 @@ const main = async () => { dockerfile_sha_sum: nextBuildReq.dockerfileSHA, dockerfile_contents: nextBuildReq.dockerfileContent, response_url: nextBuildReq.responseURL, - build_key: nextBuildReq.buildKey }; const result = await createAndStoreGraderImage(infoAsBuildReq); await handleCompletedImageBuild(nextBuildReq.dockerfileSHA, true); diff --git a/orchestrator/packages/image-build-service/src/process-request/__tests__/image-creation.test.ts b/orchestrator/packages/image-build-service/src/process-request/__tests__/image-creation.test.ts index b5243690..1fea841b 100644 --- a/orchestrator/packages/image-build-service/src/process-request/__tests__/image-creation.test.ts +++ b/orchestrator/packages/image-build-service/src/process-request/__tests__/image-creation.test.ts @@ -10,7 +10,6 @@ describe("grader image functionality", () => { dockerfile_contents: `FROM hello-world`, dockerfile_sha_sum: "generated-sha-sum", response_url: "http://example.com/response", - build_key: "{\"grader_id\": 1}" }; beforeAll(() => { diff --git a/orchestrator/packages/image-build-service/src/utils.ts b/orchestrator/packages/image-build-service/src/utils.ts index 7d280c0f..4c7abebb 100644 --- a/orchestrator/packages/image-build-service/src/utils.ts +++ b/orchestrator/packages/image-build-service/src/utils.ts @@ -63,16 +63,13 @@ export const sendJobResultForBuildFail = async (cancelInfo: CancelJobInfo) => { } export const notifyClientOfBuildResult = async (result: GraderImageBuildResult, originalReq: GraderImageBuildRequest) => { - const { response_url, build_key } = originalReq; + const { response_url } = originalReq; await fetch(response_url, { method: "POST", headers: { "Accept": "application/json", "Content-Type": "application/json" }, - body: JSON.stringify({ - ...result, - build_key - }) + body: JSON.stringify(result) }); }