Skip to content

Commit

Permalink
Merge pull request #3045 from bomoko/feature/workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
tobybellwood authored Mar 15, 2022
2 parents 22adede + 670530a commit 524d2d9
Show file tree
Hide file tree
Showing 54 changed files with 5,441 additions and 147 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pipeline {
stage ('2: run second test suite') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh script: "make -j$NPROC kind/retest TESTS=[bulk-deployment,gitlab,github,bitbucket,python,node-mongodb,elasticsearch,image-cache] BRANCH_NAME=${SAFEBRANCH_NAME}", label: "Running second test suite on kind cluster"
sh script: "make -j$NPROC kind/retest TESTS=[bulk-deployment,gitlab,github,bitbucket,python,node-mongodb,elasticsearch,image-cache,workflows] BRANCH_NAME=${SAFEBRANCH_NAME}", label: "Running second test suite on kind cluster"
}
sh script: "pkill -f './local-dev/stern'", label: "Closing off test-suite-2 log after test completion"
}
Expand Down
18 changes: 10 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ services := api \
storage-calculator \
ui \
webhook-handler \
webhooks2tasks
webhooks2tasks \
workflows


service-images += $(services)
Expand Down Expand Up @@ -246,6 +247,7 @@ build/local-api-data-watcher-pusher: local-dev/api-data-watcher-pusher/Dockerfil
build/local-registry: local-dev/registry/Dockerfile
build/local-dbaas-provider: local-dev/dbaas-provider/Dockerfile
build/local-mongodb-dbaas-provider: local-dev/mongodb-dbaas-provider/Dockerfile
build/workflows: services/workflows/Dockerfile

# Images for local helpers that exist in another folder than the service images
localdevimages := local-git \
Expand Down Expand Up @@ -511,9 +513,9 @@ KIND_VERSION = v0.12.0
GOJQ_VERSION = v0.12.5
STERN_VERSION = 2.1.17
CHART_TESTING_VERSION = v3.4.0
KIND_IMAGE = kindest/node:v1.21.10@sha256:84709f09756ba4f863769bdcabe5edafc2ada72d3c8c44d6515fc581b66b029c
TESTS = [nginx,api,features-kubernetes,bulk-deployment,features-kubernetes-2,features-api-variables,active-standby-kubernetes,tasks,drush,drupal-php80,drupal-postgres,python,gitlab,github,bitbucket,node-mongodb,elasticsearch]
CHARTS_TREEISH = main
KIND_IMAGE = kindest/node:v1.21.1@sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6
TESTS = [nginx,api,features-kubernetes,bulk-deployment,features-kubernetes-2,features-api-variables,active-standby-kubernetes,tasks,drush,drupal-php80,drupal-postgres,python,gitlab,github,bitbucket,node-mongodb,elasticsearch,workflows]
CHARTS_TREEISH = "feature/workflows"

# Symlink the installed kubectl client if the correct version is already
# installed, otherwise downloads it.
Expand Down Expand Up @@ -632,7 +634,7 @@ ifeq ($(ARCH), darwin)
tcp-listen:32080,fork,reuseaddr tcp-connect:target:32080
endif

KIND_SERVICES = api api-db api-redis auth-server actions-handler broker controllerhandler docker-host drush-alias keycloak keycloak-db logs2s3 webhook-handler webhooks2tasks kubectl-build-deploy-dind local-api-data-watcher-pusher local-git ssh tests ui
KIND_SERVICES = api api-db api-redis auth-server actions-handler broker controllerhandler docker-host drush-alias keycloak keycloak-db logs2s3 webhook-handler webhooks2tasks kubectl-build-deploy-dind local-api-data-watcher-pusher local-git ssh tests ui workflows
KIND_TESTS = local-api-data-watcher-pusher local-git tests
KIND_TOOLS = kind helm kubectl jq stern

Expand Down Expand Up @@ -773,8 +775,8 @@ kind/retest:
&& export IMAGE_REGISTRY="registry.$$(./local-dev/kubectl get nodes -o jsonpath='{.items[0].status.addresses[0].address}').nip.io:32080/library" \
&& cd lagoon-charts.kind.lagoon \
&& $(MAKE) fill-test-ci-values TESTS=$(TESTS) IMAGE_TAG=$(SAFE_BRANCH_NAME) \
HELM=$$(cd .. && realpath ./local-dev/helm) KUBECTL=$$(cd .. && realpath ./local-dev/kubectl) \
JQ=$$(cd .. && realpath ./local-dev/jq) \
HELM=$$(realpath ../local-dev/helm) KUBECTL=$$(realpath ../local-dev/kubectl) \
JQ=$$(realpath ../local-dev/jq) \
OVERRIDE_BUILD_DEPLOY_DIND_IMAGE=$$IMAGE_REGISTRY/kubectl-build-deploy-dind:$(SAFE_BRANCH_NAME) \
IMAGE_REGISTRY=$$IMAGE_REGISTRY \
SKIP_ALL_DEPS=true \
Expand All @@ -784,7 +786,7 @@ kind/retest:
&& docker run --rm --network host --name ct-$(CI_BUILD_TAG) \
--volume "$$(pwd)/test-suite-run.ct.yaml:/etc/ct/ct.yaml" \
--volume "$$(pwd):/workdir" \
--volume "$$(cd .. && realpath ./kubeconfig.kind.$(CI_BUILD_TAG)):/root/.kube/config" \
--volume "$$(realpath ../kubeconfig.kind.$(CI_BUILD_TAG)):/root/.kube/config" \
--workdir /workdir \
"quay.io/helmpack/chart-testing:$(CHART_TESTING_VERSION)" \
ct install
Expand Down
11 changes: 11 additions & 0 deletions services/api-db/docker-entrypoint-initdb.d/00-tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,14 @@ CREATE TABLE IF NOT EXISTS notification_webhook (
name varchar(50) UNIQUE,
webhook varchar(2000)
);


CREATE TABLE IF NOT EXISTS workflow (
id int NOT NULL auto_increment PRIMARY KEY,
name varchar(50) NOT NULL,
event varchar(300) NOT NULL,
project int NOT NULL REFERENCES project(id),
advanced_task_definition int NOT NULL REFERENCES advanced_task_definition(id),
created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
deleted timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
);
17 changes: 17 additions & 0 deletions services/api/src/models/workflows.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Pool } from 'mariadb';


export interface WorkflowInterface {
id?: number
name: string
project: number
event: string
advancedTaskDefinition: number
}

export interface WorkflowInputInterface {
name: string
project: number
event: string
advanced_task_definition: number
}
19 changes: 19 additions & 0 deletions services/api/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const {

const {
addAdvancedTaskDefinition,
updateAdvancedTaskDefinition,
advancedTaskDefinitionById,
resolveTasksForEnvironment,
getRegisteredTasksByEnvironmentId,
Expand Down Expand Up @@ -233,6 +234,15 @@ const {
deleteEnvVariable,
} = require('./resources/env-variables/resolvers');

const {
addWorkflow,
updateWorkflow,
deleteWorkflow,
resolveWorkflowsForEnvironment,
getWorkflowsByEnvironmentId,
resolveAdvancedTaskDefinitionsForWorkflow,
} = require("./resources/workflow/resolvers");

const resolvers = {
Upload: GraphQLUpload,
GroupRole: {
Expand Down Expand Up @@ -344,6 +354,7 @@ const resolvers = {
facts: getFactsByEnvironmentId,
openshift: getOpenshiftByEnvironmentId,
kubernetes: getOpenshiftByEnvironmentId,
workflows: getWorkflowsByEnvironmentId,
},
Fact: {
references: getFactReferencesByFactId,
Expand Down Expand Up @@ -402,6 +413,9 @@ const resolvers = {
Restore: {
restoreLocation: getRestoreLocation,
},
Workflow: {
advancedTaskDefinition: resolveAdvancedTaskDefinitionsForWorkflow,
},
Query: {
me: getMe,
lagoonVersion: getLagoonVersion,
Expand Down Expand Up @@ -434,6 +448,7 @@ const resolvers = {
allProblemHarborScanMatchers: getProblemHarborScanMatches,
projectsByMetadata: getProjectsByMetadata,
projectsByFactSearch: getProjectsByFactSearch,
workflowsForEnvironment: resolveWorkflowsForEnvironment,
deployTargetConfigById: getDeployTargetConfigById,
deployTargetConfigsByProjectId: getDeployTargetConfigsByProjectId,
deployTargetConfigsByDeployTarget: getDeployTargetConfigsByDeployTarget,
Expand Down Expand Up @@ -517,6 +532,7 @@ const resolvers = {
deleteEnvVariable,
addTask,
addAdvancedTaskDefinition,
updateAdvancedTaskDefinition,
deleteAdvancedTaskDefinition,
invokeRegisteredTask,
taskDrushArchiveDump,
Expand Down Expand Up @@ -544,6 +560,9 @@ const resolvers = {
removeUserFromGroup,
addGroupsToProject,
removeGroupsFromProject,
addWorkflow,
updateWorkflow,
deleteWorkflow,
addDeployTargetConfig,
deleteDeployTargetConfig,
updateDeployTargetConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@


// class AdvancedTaskDefinitionArgument {
// constructor

import { sqlClientPool } from "../../../clients/sqlClient";
import { advancedTaskDefinitionArgumentById } from "../task_definition_resolvers";
import { Helpers as environmentHelpers } from '../../environment/helpers';
import { Helpers as projectHelpers } from '../../project/helpers';
import { Helpers } from "../../project/helpers";
import { isPatchEmpty, query, knex } from '../../../util/db';
import { query } from '../../../util/db';
import * as R from 'ramda';

export class ArgumentBase {
Expand Down Expand Up @@ -117,4 +107,4 @@ export const advancedTaskDefinitionTypeFactory = (sqlClientPool, task, environme
throw new Error(`Unable to find AdvancedTaskDefinitionType ${name}`);
break;
}
}
}
47 changes: 47 additions & 0 deletions services/api/src/resources/task/models/taskRegistration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,50 @@ export class TaskRegistration {
image: string;
permission: string;
}

export interface AdvancedTaskDefinitionInterface {
id?: number;
type: string;
name: string;
description?: string;
environment?: number;
project?: number;
groupName?: string;
created: string;
deleted: string;
permission?: string;
command?: string;
service?: string;
image?: string;
advancedTaskDefinitionArguments?: Partial<AdvancedTaskDefinitionArguments>;
}


export const AdvancedTaskDefinitionType = {
command: 'COMMAND',
image: 'IMAGE'
};

export interface AdvancedTaskDefinitionArguments {
name?: string;
type?: string;
range?: string;
advancedTaskDefinition?: number;
};

export const getAdvancedTaskDefinitionType = (taskDef:AdvancedTaskDefinitionInterface) => {
if(taskDef.type.toLowerCase() == AdvancedTaskDefinitionType.command.toLowerCase()) {
return AdvancedTaskDefinitionType.command;
}
return AdvancedTaskDefinitionType.image;
}

export const isAdvancedTaskDefinitionSystemLevelTask = (taskDef:AdvancedTaskDefinitionInterface): boolean => {
return taskDef.project == null && taskDef.environment == null && taskDef.groupName == null;
}

export const doesAdvancedTaskDefinitionNeedAdminRights = (taskDef:AdvancedTaskDefinitionInterface): boolean => {
return isAdvancedTaskDefinitionSystemLevelTask(taskDef)
|| getAdvancedTaskDefinitionType(taskDef) == AdvancedTaskDefinitionType.image
|| taskDef.groupName != undefined;
}
24 changes: 17 additions & 7 deletions services/api/src/resources/task/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ export const Sql = {
type
})
.toString(),
updateAdvancedTaskDefinition: ({ id, patch }: { id: number; patch: { [key: string]: any } }) =>
knex('advanced_task_definition')
.where('id', id)
.update(patch)
.toString(),
selectAdvancedTaskDefinitionEnvironmentLinkById: (id: number) =>
knex('task_registration')
.where('task_registration.id', '=', id)
Expand Down Expand Up @@ -160,6 +165,11 @@ export const Sql = {
knex('advanced_task_definition_argument')
.where('advanced_task_definition_argument.id', '=', id)
.toString(),
deleteAdvancedTaskDefinitionArgumentByTaskDef:(advanced_task_definition: number) =>
knex('advanced_task_definition_argument')
.where('advanced_task_definition_argument.advanced_task_definition', '=', advanced_task_definition)
.del()
.toString(),
selectAdvancedTaskDefinitionByName:(name: string) =>
knex('advanced_task_definition')
.where('advanced_task_definition.name', '=', name)
Expand Down Expand Up @@ -194,12 +204,12 @@ export const Sql = {
.where('group_name', 'in', groups)
.toString(),
deleteAdvancedTaskDefinition:(id: number) =>
knex('advanced_task_definition')
.where('id', id)
.del()
.toString(),
knex('advanced_task_definition')
.where('id', id)
.del()
.toString(),
deleteAdvancedTaskDefinitionArgumentsForTask:(taskId: number) => knex('advanced_task_definition_argument')
.where('advanced_task_definition', taskId)
.del()
.toString()
.where('advanced_task_definition', taskId)
.del()
.toString(),
};
Loading

0 comments on commit 524d2d9

Please sign in to comment.