Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions node-packages/commons/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Transport } from './lokka-transport-http-retry';
import { replace, pipe, toLower } from 'ramda';
import { getConfigFromEnv } from './util/config';

import { DeploymentSourceType, DeployType, TaskStatusType, TaskSourceType } from './types';
import { DeploymentSourceType, DeploymentBuildType, DeployType, TaskStatusType, TaskSourceType } from './types';

export interface Project {
autoIdle: number;
Expand Down Expand Up @@ -1190,12 +1190,13 @@ export const addDeployment = (
bulkName: string | null = null,
sourceUser: string | null = null,
sourceType: DeploymentSourceType,
buildType: DeploymentBuildType,
): Promise<any> =>
graphqlapi.mutate(
`
($name: String!, $status: DeploymentStatusType!, $created: String!, $environment: Int!, $id: Int, $remoteId: String,
$started: String, $completed: String, $priority: Int, $bulkId: String, $bulkName: String,
$sourceUser: String, $sourceType: DeploymentSourceType) {
$sourceUser: String, $sourceType: DeploymentSourceType, $buildType: DeploymentBuildType) {
addDeployment(input: {
name: $name
status: $status
Expand All @@ -1210,6 +1211,7 @@ export const addDeployment = (
bulkName: $bulkName
sourceUser: $sourceUser
sourceType: $sourceType
buildType: $buildType
}) {
...${deploymentFragment}
}
Expand Down
2 changes: 2 additions & 0 deletions node-packages/commons/src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ export const getControllerBuildData = async function(deployTarget: any, deployDa
bulkId,
bulkName,
sourceType,
buildType,
} = deployData;

const buildVariables = deployData.buildVariables || [];
Expand Down Expand Up @@ -543,6 +544,7 @@ export const getControllerBuildData = async function(deployTarget: any, deployDa
bulkName,
sourceUser,
sourceType,
buildType,
);
} catch (error) {
logger.error(`Could not save deployment for project ${lagoonProjectData.id}. Message: ${error}`);
Expand Down
6 changes: 6 additions & 0 deletions node-packages/commons/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export enum DeploymentSourceType {
WEBHOOK = 'webhook'
}

export enum DeploymentBuildType {
BUILD = 'build',
VARIABLES = 'variables'
}

export enum TaskStatusType {
NEW = 'new',
PENDING = 'pending',
Expand Down Expand Up @@ -91,6 +96,7 @@ export interface DeployData {
sha?: string,
sourceType: DeploymentSourceType,
sourceUser?: string,
buildType?: DeploymentBuildType,
type: DeployType;
}

Expand Down
3 changes: 3 additions & 0 deletions node-packages/commons/src/util/lagoon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { EnvKeyValue } from '../api';
export const generateBuildId = () =>
`lagoon-build-${Math.random().toString(36).substring(7)}`;

export const generateVariableOnlyBuildId = () =>
`lagoon-variables-${Math.random().toString(36).substring(7)}`;

export const generateTaskName = () =>
`lagoon-task-${Math.random().toString(36).substring(7)}`;

Expand Down
24 changes: 24 additions & 0 deletions services/api/database/migrations/20251115000000_buildtype.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function(knex) {
return knex.schema
.alterTable('deployment', (table) => {
table.enu('build_type',['build','variables']).notNullable().defaultTo('build');;
})
// set all existing deployments to build
.raw("UPDATE deployment SET build_type='build'");
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function(knex) {
// cant alter enums in place, so drop the column first :D
return knex.schema
.alterTable('deployment', (table) => {
table.dropColumn('build_type');
})
};
4 changes: 4 additions & 0 deletions services/api/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ async function getResolvers() {
API: 'api',
WEBHOOK: 'webhook'
},
DeploymentBuildType: {
BUILD: 'build',
VARIABLES: 'variables'
},
TaskSourceType: {
API: 'api',
},
Expand Down
14 changes: 11 additions & 3 deletions services/api/src/resources/deployment/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import { addTask } from '@lagoon/commons/dist/api';
import { Sql as environmentSql } from '../environment/sql';
const { S3Client, GetObjectCommand } = require('@aws-sdk/client-s3');
import sha1 from 'sha1';
import { generateBuildId } from '@lagoon/commons/dist/util/lagoon';
import { generateBuildId, generateVariableOnlyBuildId } from '@lagoon/commons/dist/util/lagoon';
import { jsonMerge } from '@lagoon/commons/dist/util/func';
import { logger } from '../../loggers/logger';
import { getUserProjectIdsFromRoleProjectIds } from '../../util/auth';
import uuid4 from 'uuid4';
import { DeploymentSourceType, DeployType, TaskStatusType, TaskSourceType, DeployData, AuditType } from '@lagoon/commons/dist/types';
import { DeploymentSourceType, DeployType, TaskStatusType, TaskSourceType, DeployData, AuditType, DeploymentBuildType } from '@lagoon/commons/dist/types';
import { AuditLog } from '../audit/types';

const accessKeyId = process.env.S3_FILES_ACCESS_KEY_ID || 'minio'
Expand Down Expand Up @@ -780,6 +780,13 @@ export const deployEnvironmentLatest: ResolverFn = async (
}

let buildName = generateBuildId();
let buildType = DeploymentBuildType.BUILD
// change the buildname to a variables only name if the build variable for lagoon variables only is found
if (buildVariables && buildVariables.find(e => e.name === 'LAGOON_VARIABLES_ONLY' && e.value === "true")) {
buildName = generateVariableOnlyBuildId();
buildType = DeploymentBuildType.VARIABLES
}

const sourceUser = await Helpers(sqlClientPool).getSourceUser(keycloakGrant, legacyGrant)
let deployData: DeployData;
let meta: {
Expand All @@ -800,7 +807,8 @@ export const deployEnvironmentLatest: ResolverFn = async (
buildVariables: buildVariables,
sourceType: DeploymentSourceType.API,
sourceUser: sourceUser,
branchName: environment.deployBaseRef
branchName: environment.deployBaseRef,
buildType: buildType
};
meta = {
...meta,
Expand Down
7 changes: 7 additions & 0 deletions services/api/src/typeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ const typeDefs = gql`
API
}

enum DeploymentBuildType {
BUILD
VARIABLES
}

scalar SeverityScore

type AdvancedTaskDefinitionArgument {
Expand Down Expand Up @@ -1007,6 +1012,7 @@ const typeDefs = gql`
The source of this task from the available deplyoment trigger types
"""
sourceType: DeploymentSourceType
buildType: DeploymentBuildType
}

type Insight {
Expand Down Expand Up @@ -1999,6 +2005,7 @@ const typeDefs = gql`
buildStep: String
sourceUser: String
sourceType: DeploymentSourceType
buildType: DeploymentBuildType
}

input DeleteDeploymentInput {
Expand Down
Loading