-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): use hasura action for pipelines (#378)
- Loading branch information
Showing
12 changed files
with
178 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import Boom from "@hapi/boom"; | ||
import { apiError } from "src/lib/apiError"; | ||
import { getPipelines, getPipelineVariables } from "src/lib/gitlab.api"; | ||
|
||
export default async function ActivateAccount(req, res) { | ||
if (req.method === "GET") { | ||
res.setHeader("Allow", ["POST"]); | ||
return apiError(Boom.methodNotAllowed("GET method not allowed")); | ||
} | ||
|
||
if ( | ||
!req.headers["actions-secret"] || | ||
req.headers["actions-secret"] !== process.env.ACTIONS_SECRET | ||
) { | ||
return apiError(res, Boom.unauthorized("Missing secret or env")); | ||
} | ||
|
||
try { | ||
const pipelines = await getPipelines(); | ||
|
||
const activePipelines = pipelines.filter( | ||
({ status }) => status === "pending" || status === "running" | ||
); | ||
|
||
const pipelinesDetails = await Promise.all( | ||
activePipelines.map(({ id }) => getPipelineVariables(id)) | ||
); | ||
const runningDeployementPipeline = pipelinesDetails.reduce( | ||
(state, variables) => { | ||
const varsObj = variables.reduce( | ||
(obj, { key, value }) => ({ ...obj, [key]: value }), | ||
{} | ||
); | ||
if ( | ||
varsObj.ACTION === "ingest_documents_dev" && | ||
varsObj.ES_INDEX_PREFIX === "cdtn-preprod" | ||
) { | ||
state.preprod = true; | ||
} | ||
if (varsObj.ACTION === "ingest_documents_prod") { | ||
state.prod = true; | ||
} | ||
return state; | ||
}, | ||
{ preprod: false, prod: false } | ||
); | ||
res.json(runningDeployementPipeline); | ||
} catch (error) { | ||
console.error(`[actions] get pipelines failed`, error); | ||
res | ||
.status(error.status) | ||
.json({ code: error.status, message: "[actions]: can't get pipelines" }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
targets/frontend/src/pages/api/actions/trigger_pipeline.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Boom from "@hapi/boom"; | ||
import { createErrorFor } from "src/lib/apiError"; | ||
import { triggerDeploy } from "src/lib/gitlab.api"; | ||
|
||
export default async function (req, res) { | ||
const apiError = createErrorFor(res); | ||
|
||
if (req.method === "GET") { | ||
res.setHeader("Allow", ["POST"]); | ||
return apiError(Boom.methodNotAllowed("GET method not allowed")); | ||
} | ||
const { env } = req.body.input; | ||
|
||
try { | ||
await triggerDeploy(env); | ||
res.status(200).json({ message: "ok" }); | ||
} catch (error) { | ||
console.error(`[actions] trigger pipeline failed, error`, error); | ||
apiError(res, Boom.serverUnavailable(`[actions] can't trigger pipeline`)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.