Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/workflows #3045

Merged
merged 39 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a0241c3
First commit for workflow api
bomoko Sep 2, 2021
eb99704
Fixes merge conflict
bomoko Nov 14, 2021
6579162
Adds first pass at service
bomoko Nov 15, 2021
2d4dd8d
Adds matcher starts
bomoko Nov 17, 2021
9953cc5
Merge branch 'main' into feature/workflows
bomoko Nov 23, 2021
8884f67
Merge pull request #2943 from bomoko/feature/workflows
bomoko Nov 24, 2021
4edd818
Changes log
bomoko Nov 24, 2021
03ceb13
Removes .gitignore from workflows
bomoko Nov 24, 2021
a22309e
Merge branch 'uselagoon:feature/workflows' into feature/workflows
bomoko Nov 28, 2021
df8619b
Merge branch 'main' into feature/workflows
bomoko Nov 28, 2021
22f0202
Adds workflow resolver to environment
bomoko Nov 28, 2021
34dddb6
Adds task resolver for workflows
bomoko Nov 29, 2021
7f16f56
Adds ad task def struct
bomoko Nov 30, 2021
e5a3b43
Merge branch 'main' into feature/workflows
bomoko Dec 8, 2021
40d8be4
Merge remote-tracking branch 'bomoko/feature/custom_task_arguments' i…
Dec 14, 2021
2a3ed09
Adding updateTaskDefinition
Dec 14, 2021
df7fb77
adding userActivityLogger
Dec 14, 2021
aebb313
Adds initial pass at testing workflows
bomoko Dec 14, 2021
25ee2f8
Merge branch 'workflows/taskDefinitionResolvers' into feature/workflows
Dec 15, 2021
c4ebd23
update and delete workflow resolvers, sql queries, permissions and na…
Dec 16, 2021
2f3dc1c
Merge pull request #2955 from uselagoon/workflows/taskDefinitionResol…
Dec 16, 2021
aa531fd
Merge pull request #2969 from uselagoon/workflows/addAndUpdateWorkflo…
Dec 16, 2021
804b86e
Updating workflows code and tests
bomoko Jan 6, 2022
b39c99d
Working read/register/kickoff
bomoko Jan 7, 2022
22c242c
Merge remote-tracking branch 'upstream/feature/workflows' into featur…
bomoko Jan 9, 2022
78f7a74
Merge branch 'main' into feature/workflows
bomoko Jan 10, 2022
bb20911
Merge branch 'main' into feature/workflows
bomoko Jan 25, 2022
8c62ae6
Small fixes to service
bomoko Jan 25, 2022
96a0a4d
First pass at workflows testing
bomoko Jan 25, 2022
1c85203
Fixes merge issues
bomoko Feb 20, 2022
84fd021
Better logging
bomoko Feb 20, 2022
49eaf9b
Adds completed test and some changes to workflows internals
bomoko Feb 23, 2022
e8faea4
Merge branch 'main' into feature/workflows
bomoko Feb 23, 2022
71b281d
Support new namespace deploy strategy
bomoko Feb 23, 2022
b489999
Removing unused code
bomoko Feb 23, 2022
34c1fb1
Changes charts branch for testing
bomoko Feb 23, 2022
d8f5e8f
Adds workflows test to makefile
bomoko Feb 23, 2022
14fd773
Adds workflows to test suite 2
bomoko Feb 23, 2022
670530a
Merge branch 'main' into feature/workflows
tobybellwood Mar 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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=[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=[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
16 changes: 9 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ services := api \
storage-calculator \
ui \
webhook-handler \
webhooks2tasks
webhooks2tasks \
workflows


service-images += $(services)
Expand Down Expand Up @@ -244,6 +245,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 @@ -510,8 +512,8 @@ GOJQ_VERSION = v0.12.5
STERN_VERSION = 2.1.17
CHART_TESTING_VERSION = v3.4.0
KIND_IMAGE = kindest/node:v1.21.1@sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6
TESTS = [nginx,api,features-kubernetes,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
TESTS = [nginx,api,features-kubernetes,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 @@ -629,7 +631,7 @@ ifeq ($(ARCH), darwin)
tcp-listen:32080,fork,reuseaddr tcp-connect:target:32080
endif

KIND_SERVICES = api api-db api-redis auth-server 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 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 @@ -770,8 +772,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 @@ -781,7 +783,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 @@ -332,3 +332,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 @@ -70,6 +70,7 @@ const {

const {
addAdvancedTaskDefinition,
updateAdvancedTaskDefinition,
advancedTaskDefinitionById,
resolveTasksForEnvironment,
getRegisteredTasksByEnvironmentId,
Expand Down Expand Up @@ -230,6 +231,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 @@ -335,6 +345,7 @@ const resolvers = {
facts: getFactsByEnvironmentId,
openshift: getOpenshiftByEnvironmentId,
kubernetes: getOpenshiftByEnvironmentId,
workflows: getWorkflowsByEnvironmentId,
},
Fact: {
references: getFactReferencesByFactId,
Expand Down Expand Up @@ -393,6 +404,9 @@ const resolvers = {
Restore: {
restoreLocation: getRestoreLocation,
},
Workflow: {
advancedTaskDefinition: resolveAdvancedTaskDefinitionsForWorkflow,
},
Query: {
me: getMe,
lagoonVersion: getLagoonVersion,
Expand Down Expand Up @@ -424,6 +438,7 @@ const resolvers = {
allProblemHarborScanMatchers: getProblemHarborScanMatches,
projectsByMetadata: getProjectsByMetadata,
projectsByFactSearch: getProjectsByFactSearch,
workflowsForEnvironment: resolveWorkflowsForEnvironment,
deployTargetConfigById: getDeployTargetConfigById,
deployTargetConfigsByProjectId: getDeployTargetConfigsByProjectId,
deployTargetConfigsByDeployTarget: getDeployTargetConfigsByDeployTarget,
Expand Down Expand Up @@ -506,6 +521,7 @@ const resolvers = {
deleteEnvVariable,
addTask,
addAdvancedTaskDefinition,
updateAdvancedTaskDefinition,
deleteAdvancedTaskDefinition,
invokeRegisteredTask,
taskDrushArchiveDump,
Expand Down Expand Up @@ -533,6 +549,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