Skip to content

Commit

Permalink
refactor: no build key needed for grader build reqs
Browse files Browse the repository at this point in the history
  • Loading branch information
williams-jack committed Jul 26, 2024
1 parent 78d5d11 commit 353ff38
Show file tree
Hide file tree
Showing 10 changed files with 3 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ export interface GraderImageBuildRequest {
dockerfile_contents: string,
dockerfile_sha_sum: string,
response_url: string,
build_key: string,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
};
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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");

Expand Down
3 changes: 0 additions & 3 deletions orchestrator/packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<boolean> => {
const enqueueImageBuild = ({ dockerfile_sha_sum, dockerfile_contents, response_url }: GraderImageBuildRequest): Promise<boolean> => {
return prismaInstance.$transaction(async (tx) => {
const buildInfoAlreadyExists = (await tx.imageBuildInfo.count({
where: {
Expand All @@ -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;
Expand Down
1 change: 0 additions & 1 deletion orchestrator/packages/image-build-service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
7 changes: 2 additions & 5 deletions orchestrator/packages/image-build-service/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
}

0 comments on commit 353ff38

Please sign in to comment.