@docupace/pipeline 1.0.81-alpha.9 → 1.0.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/merge/cli-merge-all.js +2 -15
- package/src/merge/cli-merge.js +3 -82
- package/src/micro/cli.js +51 -0
- package/src/micro/ms-deploy.js +451 -0
- package/src/micro/ms-publish.js +186 -0
- package/src/next/cli.js +1 -10
- package/terraform/import.sh +111 -0
- package/terraform/plan.sh +17 -4
- package/src/micro/deploy-microservice.js +0 -153
- package/src/micro/publish-ms.js +0 -188
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
//import { $ } from '../next/logger.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Publish Docker images for microservices with flexible naming
|
|
5
|
+
* @param {string} gitSha - Git commit SHA
|
|
6
|
+
* @param {Object} options - Configuration options
|
|
7
|
+
* @param {string} options.imageName - Docker image name (e.g., 'swp')
|
|
8
|
+
* @param {string} options.registryUrl - JFrog registry URL
|
|
9
|
+
* @param {string} options.repoName - Repository name in JFrog
|
|
10
|
+
* @param {string} options.username - JFrog username
|
|
11
|
+
* @param {string} options.password - JFrog password
|
|
12
|
+
* @param {string} options.buildNumber - Build number
|
|
13
|
+
*/
|
|
14
|
+
// export async function publishMicroservice(serviceName, options = {}) {
|
|
15
|
+
// // Use environment variables as defaults, but allow overrides
|
|
16
|
+
|
|
17
|
+
// const gitSha = (await $`git log --pretty=format:'%h' -n 1 `).stdout.trim();
|
|
18
|
+
|
|
19
|
+
// const config = {
|
|
20
|
+
// imageName: serviceName,
|
|
21
|
+
// registryUrl: options.registryUrl || process.env.JF_REGISTRY_URL,
|
|
22
|
+
// repoName: options.repoName || process.env.JF_REGISTRY_REPO_NAME,
|
|
23
|
+
// username: options.username || process.env.JF_REGISTRY_USER_DEV,
|
|
24
|
+
// password: options.password || process.env.JF_REGISTRY_PASSWORD_DEV,
|
|
25
|
+
// buildNumber: options.buildNumber || process.env.BITBUCKET_BUILD_NUMBER,
|
|
26
|
+
// tag: options.tag || process.env.VERSION_TAG,
|
|
27
|
+
// };
|
|
28
|
+
|
|
29
|
+
// // Validate required fields
|
|
30
|
+
// if (!config.imageName) {
|
|
31
|
+
// throw new Error(
|
|
32
|
+
// 'Image name is required. Set IMAGE_NAME or APP_NAME environment variable.',
|
|
33
|
+
// );
|
|
34
|
+
// }
|
|
35
|
+
|
|
36
|
+
// console.log('=== Docker Image Publishing Configuration ===');
|
|
37
|
+
// console.log(`Image Name: ${config.imageName}`);
|
|
38
|
+
// console.log(`Git SHA: ${gitSha}`);
|
|
39
|
+
// console.log(`Build Number: ${config.buildNumber}`);
|
|
40
|
+
// console.log(`Version Tag: ${config.tag || 'none'}`);
|
|
41
|
+
// console.log(`Registry: ${config.registryUrl}/${config.repoName}`);
|
|
42
|
+
// console.log('==========================================');
|
|
43
|
+
|
|
44
|
+
// const registryPath = `${config.registryUrl}/${config.repoName}`;
|
|
45
|
+
// const SHA_IMAGE_NAME = `${config.imageName}:sha-${gitSha}`;
|
|
46
|
+
|
|
47
|
+
// // Docker login
|
|
48
|
+
// await $`echo ${config.password} | docker login --username ${config.username} --password-stdin ${config.registryUrl}`;
|
|
49
|
+
|
|
50
|
+
// try {
|
|
51
|
+
// // Build the image if it doesn't exist locally
|
|
52
|
+
// const imageExists = await checkLocalImage(SHA_IMAGE_NAME);
|
|
53
|
+
// if (!imageExists) {
|
|
54
|
+
// console.log(`Building Docker image ${SHA_IMAGE_NAME}...`);
|
|
55
|
+
// await $`docker build -t ${SHA_IMAGE_NAME} .`;
|
|
56
|
+
// }
|
|
57
|
+
|
|
58
|
+
// // Array to track all tags we're pushing
|
|
59
|
+
// const tagsToPush = [];
|
|
60
|
+
|
|
61
|
+
// // 1. Push SHA tag
|
|
62
|
+
// const shaTag = `${registryPath}/${SHA_IMAGE_NAME}`;
|
|
63
|
+
// console.log(`Tagging and pushing SHA: ${shaTag}`);
|
|
64
|
+
// await $`docker tag ${SHA_IMAGE_NAME} ${shaTag}`;
|
|
65
|
+
// await $`docker push ${shaTag}`;
|
|
66
|
+
// tagsToPush.push(SHA_IMAGE_NAME);
|
|
67
|
+
|
|
68
|
+
// // 2. Push build number tag
|
|
69
|
+
// if (config.buildNumber) {
|
|
70
|
+
// const BUILD_IMAGE_NAME = `${config.imageName}:build-${config.buildNumber}`;
|
|
71
|
+
// const buildTag = `${registryPath}/${BUILD_IMAGE_NAME}`;
|
|
72
|
+
// console.log(`Tagging and pushing build: ${buildTag}`);
|
|
73
|
+
// await $`docker tag ${SHA_IMAGE_NAME} ${buildTag}`;
|
|
74
|
+
// await $`docker push ${buildTag}`;
|
|
75
|
+
// tagsToPush.push(BUILD_IMAGE_NAME);
|
|
76
|
+
// }
|
|
77
|
+
|
|
78
|
+
// // 3. Push version tag (this is what ArgoCD needs!)
|
|
79
|
+
// if (config.tag) {
|
|
80
|
+
// // Handle various tag formats
|
|
81
|
+
// let version = config.tag;
|
|
82
|
+
|
|
83
|
+
// // If tag contains @, extract version after it
|
|
84
|
+
// if (version.includes('@')) {
|
|
85
|
+
// version = 'v' + version.split('@')[1];
|
|
86
|
+
// }
|
|
87
|
+
|
|
88
|
+
// // Ensure version starts with 'v' if it's a semver without it
|
|
89
|
+
// if (/^\d+\.\d+\.\d+/.test(version) && !version.startsWith('v')) {
|
|
90
|
+
// version = 'v' + version;
|
|
91
|
+
// }
|
|
92
|
+
|
|
93
|
+
// const VERSION_IMAGE_NAME = `${config.imageName}:${version}`;
|
|
94
|
+
// const versionTag = `${registryPath}/${VERSION_IMAGE_NAME}`;
|
|
95
|
+
|
|
96
|
+
// console.log(`Tagging and pushing version: ${versionTag}`);
|
|
97
|
+
// await $`docker tag ${SHA_IMAGE_NAME} ${versionTag}`;
|
|
98
|
+
// await $`docker push ${versionTag}`;
|
|
99
|
+
// tagsToPush.push(VERSION_IMAGE_NAME);
|
|
100
|
+
|
|
101
|
+
// // Also push 'latest' tag when we have a version
|
|
102
|
+
// const LATEST_IMAGE_NAME = `${config.imageName}:latest`;
|
|
103
|
+
// const latestTag = `${registryPath}/${LATEST_IMAGE_NAME}`;
|
|
104
|
+
// console.log(`Tagging and pushing latest: ${latestTag}`);
|
|
105
|
+
// await $`docker tag ${SHA_IMAGE_NAME} ${latestTag}`;
|
|
106
|
+
// await $`docker push ${latestTag}`;
|
|
107
|
+
// tagsToPush.push(LATEST_IMAGE_NAME);
|
|
108
|
+
// }
|
|
109
|
+
|
|
110
|
+
// // 4. Check for git tags at current commit
|
|
111
|
+
// try {
|
|
112
|
+
// const gitTags = (await $`git tag --points-at HEAD`).stdout
|
|
113
|
+
// .trim()
|
|
114
|
+
// .split('\n')
|
|
115
|
+
// .filter(Boolean);
|
|
116
|
+
|
|
117
|
+
// if (gitTags.length > 0) {
|
|
118
|
+
// console.log(`Found git tags at HEAD: ${gitTags.join(', ')}`);
|
|
119
|
+
|
|
120
|
+
// for (const gitTag of gitTags) {
|
|
121
|
+
// // Skip if we already handled this tag above
|
|
122
|
+
// if (gitTag === config.tag) continue;
|
|
123
|
+
|
|
124
|
+
// let version = gitTag;
|
|
125
|
+
// if (version.includes('@')) {
|
|
126
|
+
// version = 'v' + version.split('@')[1];
|
|
127
|
+
// }
|
|
128
|
+
|
|
129
|
+
// const TAG_IMAGE_NAME = `${config.imageName}:${version}`;
|
|
130
|
+
// const gitTagPath = `${registryPath}/${TAG_IMAGE_NAME}`;
|
|
131
|
+
|
|
132
|
+
// console.log(`Tagging and pushing git tag: ${gitTagPath}`);
|
|
133
|
+
// await $`docker tag ${SHA_IMAGE_NAME} ${gitTagPath}`;
|
|
134
|
+
// await $`docker push ${gitTagPath}`;
|
|
135
|
+
// tagsToPush.push(TAG_IMAGE_NAME);
|
|
136
|
+
// }
|
|
137
|
+
// }
|
|
138
|
+
// } catch (e) {
|
|
139
|
+
// console.log('No git tags found at HEAD or error checking tags', e);
|
|
140
|
+
// }
|
|
141
|
+
|
|
142
|
+
// console.log('\n✅ Docker image published successfully!');
|
|
143
|
+
// console.log('=== Summary of pushed tags ===');
|
|
144
|
+
// tagsToPush.forEach((tag) => console.log(` ✓ ${tag}`));
|
|
145
|
+
// console.log('==============================\n');
|
|
146
|
+
|
|
147
|
+
// // Verify the version tag if we expect one
|
|
148
|
+
// if (config.tag) {
|
|
149
|
+
// const version = config.tag.includes('@')
|
|
150
|
+
// ? 'v' + config.tag.split('@')[1]
|
|
151
|
+
// : config.tag;
|
|
152
|
+
// const expectedTag = `${registryPath}/${config.imageName}:${version}`;
|
|
153
|
+
// console.log(`Verifying version tag exists: ${expectedTag}`);
|
|
154
|
+
// try {
|
|
155
|
+
// await $`docker manifest inspect ${expectedTag}`;
|
|
156
|
+
// console.log('✅ Version tag verified in registry!');
|
|
157
|
+
// } catch (e) {
|
|
158
|
+
// console.error('❌ WARNING: Could not verify version tag in registry!');
|
|
159
|
+
// console.error('ArgoCD may fail to pull this image.', e);
|
|
160
|
+
// }
|
|
161
|
+
// }
|
|
162
|
+
// } catch (error) {
|
|
163
|
+
// console.error('Error during image publishing:', error);
|
|
164
|
+
// throw error;
|
|
165
|
+
// } finally {
|
|
166
|
+
// // Always logout
|
|
167
|
+
// await $`docker logout ${config.registryUrl}`;
|
|
168
|
+
// }
|
|
169
|
+
// }
|
|
170
|
+
|
|
171
|
+
// async function checkLocalImage(imageName) {
|
|
172
|
+
// try {
|
|
173
|
+
// $.verbose = false;
|
|
174
|
+
// await $`docker image inspect ${imageName}`;
|
|
175
|
+
// return true;
|
|
176
|
+
// } catch {
|
|
177
|
+
// return false;
|
|
178
|
+
// } finally {
|
|
179
|
+
// $.verbose = true;
|
|
180
|
+
// }
|
|
181
|
+
// }
|
|
182
|
+
|
|
183
|
+
// // Backward compatibility wrapper
|
|
184
|
+
// export async function publishWithDefaults(gitSha) {
|
|
185
|
+
// return publishMicroservice(gitSha);
|
|
186
|
+
// }
|
package/src/next/cli.js
CHANGED
|
@@ -4,7 +4,6 @@ import { Command } from 'commander';
|
|
|
4
4
|
import { pull } from './pull.js';
|
|
5
5
|
import { sonar } from './sonar.js';
|
|
6
6
|
import { publish } from './publish.js';
|
|
7
|
-
import { publishMicroservice } from '../micro/publish-ms.js';
|
|
8
7
|
import {
|
|
9
8
|
deployAppWithTag,
|
|
10
9
|
deployFromSite,
|
|
@@ -12,7 +11,7 @@ import {
|
|
|
12
11
|
getDefaultDeploySite,
|
|
13
12
|
getDeployTag,
|
|
14
13
|
} from './deploy.js';
|
|
15
|
-
import {
|
|
14
|
+
import { copy2 } from './copy.js';
|
|
16
15
|
import { vaultAddSiteData } from './vault.js';
|
|
17
16
|
import { addApacheSite } from './apache.js';
|
|
18
17
|
import { haproxySync } from './haproxy.js';
|
|
@@ -83,14 +82,6 @@ program
|
|
|
83
82
|
await publish(GIT_SHA);
|
|
84
83
|
});
|
|
85
84
|
|
|
86
|
-
// Add the new publish-microservice command
|
|
87
|
-
program
|
|
88
|
-
.command('publish-microservice')
|
|
89
|
-
.description('Publish a microservice Docker image with version tags')
|
|
90
|
-
.action(async () => {
|
|
91
|
-
await publishMicroservice(GIT_SHA);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
85
|
program
|
|
95
86
|
.command('deploy-from-site')
|
|
96
87
|
.description('Deploy an application for a specific site')
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -e
|
|
3
|
+
|
|
4
|
+
PROJECT=$1
|
|
5
|
+
CURRENT_ENVIRONMENT=$2
|
|
6
|
+
export ROLE_NAME="${3:-atlassian-bitbucket-pipelines-runner-eks-role}"
|
|
7
|
+
|
|
8
|
+
AWS_REGION="${4:-us-west-2}"
|
|
9
|
+
CLUSTER_NAME="${5:-}"
|
|
10
|
+
IMPORT_ADDRESS="${IMPORT_ADDRESS:-}"
|
|
11
|
+
IMPORT_ID="${IMPORT_ID:-}"
|
|
12
|
+
|
|
13
|
+
if [[ -z "$PROJECT" ]]; then
|
|
14
|
+
echo "Error: Project name is required."
|
|
15
|
+
echo "Usage: $0 <project-name> <environment> [role-name] [aws-region] [cluster-name]"
|
|
16
|
+
exit 1
|
|
17
|
+
fi
|
|
18
|
+
|
|
19
|
+
if [[ -z "$CURRENT_ENVIRONMENT" ]]; then
|
|
20
|
+
echo "Error: ENVIRONMENT is required."
|
|
21
|
+
echo "Usage: $0 <project-name> <environment> [role-name] [aws-region] [cluster-name]"
|
|
22
|
+
exit 1
|
|
23
|
+
fi
|
|
24
|
+
|
|
25
|
+
if [[ -z "$IMPORT_ADDRESS" ]]; then
|
|
26
|
+
echo "Error: IMPORT_ADDRESS environment variable is required."
|
|
27
|
+
echo "Example: IMPORT_ADDRESS=module.vpc.aws_vpc.main"
|
|
28
|
+
exit 1
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
if [[ -z "$IMPORT_ID" ]]; then
|
|
32
|
+
echo "Error: IMPORT_ID environment variable is required."
|
|
33
|
+
echo "Example: IMPORT_ID=vpc-1234567890abcdef0"
|
|
34
|
+
exit 1
|
|
35
|
+
fi
|
|
36
|
+
|
|
37
|
+
if [ -n "$CLUSTER_NAME" ]; then
|
|
38
|
+
export EKS_CLUSTER_NAME="$CLUSTER_NAME"
|
|
39
|
+
elif [ "$CURRENT_ENVIRONMENT" == "prd" ]; then
|
|
40
|
+
export EKS_CLUSTER_NAME="connect-next-prd-eks-cluster"
|
|
41
|
+
CURRENT_ENVIRONMENT="prod"
|
|
42
|
+
elif [ "$CURRENT_ENVIRONMENT" == "stg" ]; then
|
|
43
|
+
export EKS_CLUSTER_NAME="connect-next-stg-eks-cluster"
|
|
44
|
+
CURRENT_ENVIRONMENT="stage"
|
|
45
|
+
else
|
|
46
|
+
export EKS_CLUSTER_NAME="connect-next-${CURRENT_ENVIRONMENT}-eks-cluster"
|
|
47
|
+
fi
|
|
48
|
+
|
|
49
|
+
echo "=========================================="
|
|
50
|
+
echo "Terraform Import Configuration"
|
|
51
|
+
echo "=========================================="
|
|
52
|
+
echo "Project: $PROJECT"
|
|
53
|
+
echo "Environment: $CURRENT_ENVIRONMENT"
|
|
54
|
+
echo "EKS Cluster: $EKS_CLUSTER_NAME"
|
|
55
|
+
echo "AWS Region: $AWS_REGION"
|
|
56
|
+
echo "Resource Address: $IMPORT_ADDRESS"
|
|
57
|
+
echo "Resource ID: $IMPORT_ID"
|
|
58
|
+
echo "=========================================="
|
|
59
|
+
|
|
60
|
+
export SESSION_NAME="EKSAdminSession"
|
|
61
|
+
export ROLE_ARN="arn:aws:iam::$(aws sts get-caller-identity | jq -r '.Account'):role/$ROLE_NAME"
|
|
62
|
+
export ASSUME_ROLE_OUTPUT=$(aws sts assume-role --role-arn $ROLE_ARN --role-session-name $SESSION_NAME)
|
|
63
|
+
export AWS_ACCESS_KEY_ID=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.AccessKeyId')
|
|
64
|
+
export AWS_SECRET_ACCESS_KEY=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.SecretAccessKey')
|
|
65
|
+
export AWS_SESSION_TOKEN=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.SessionToken')
|
|
66
|
+
|
|
67
|
+
aws sts get-caller-identity
|
|
68
|
+
|
|
69
|
+
cd "$BITBUCKET_CLONE_DIR/${PROJECT}"
|
|
70
|
+
|
|
71
|
+
echo "Executing: terraform import \"$IMPORT_ADDRESS\" \"$IMPORT_ID\""
|
|
72
|
+
|
|
73
|
+
if [[ "$PROJECT" == "bb-build-agent-shell" ]]; then
|
|
74
|
+
if [[ "$CURRENT_ENVIRONMENT" == "dev" ]]; then
|
|
75
|
+
echo "$dev_build_agent_configuration" | base64 -d >./env/${CURRENT_ENVIRONMENT}/${AWS_REGION}/build_agent_configuration.tfvars.json
|
|
76
|
+
elif [[ "$CURRENT_ENVIRONMENT" == "qa" ]]; then
|
|
77
|
+
echo "$qa_build_agent_configuration" | base64 -d >./env/${CURRENT_ENVIRONMENT}/${AWS_REGION}/build_agent_configuration.tfvars.json
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
terraform import \
|
|
81
|
+
-var-file="./env/${CURRENT_ENVIRONMENT}/${AWS_REGION}/terraform.tfvars" \
|
|
82
|
+
-var-file="./env/${CURRENT_ENVIRONMENT}/${AWS_REGION}/build_agent_configuration.tfvars.json" \
|
|
83
|
+
-- "$IMPORT_ADDRESS" "$IMPORT_ID"
|
|
84
|
+
elif [[ "$PROJECT" == "s3" ]]; then
|
|
85
|
+
terraform import \
|
|
86
|
+
-var-file="./env/${CURRENT_ENVIRONMENT}/${AWS_REGION}/terraform.tfvars" \
|
|
87
|
+
-var="site=${SITE_NAME}" \
|
|
88
|
+
-var="env=${CURRENT_ENVIRONMENT}" \
|
|
89
|
+
-- "$IMPORT_ADDRESS" "$IMPORT_ID"
|
|
90
|
+
elif [[ "$PROJECT" == "idp" ]]; then
|
|
91
|
+
terraform import \
|
|
92
|
+
-var-file="./env/${CURRENT_ENVIRONMENT}/${AWS_REGION}/terraform.tfvars" \
|
|
93
|
+
-var="site=${SITE_NAME}" \
|
|
94
|
+
-var="env=${CURRENT_ENVIRONMENT}" \
|
|
95
|
+
-var="docupace_domain=${DOCUPACE_DOMAIN}" \
|
|
96
|
+
-var="docupace_next_domain=${DOCUPACE_NEXT_DOMAIN}" \
|
|
97
|
+
-var="old_page_design=${USE_OLD_PAGE_DESIGN}" \
|
|
98
|
+
-var="use_new_domain=${USE_NEW_DOMAIN}" \
|
|
99
|
+
-var="configure_autologin=${CONFIGURE_AUTOLOGIN}" \
|
|
100
|
+
-var="configure_enterprise_ui=${CONFIGURE_ENTERPRISE_UI}" \
|
|
101
|
+
-var="enable_mfa=${ENABLE_MFA}" \
|
|
102
|
+
-var="configure_ui_cc=${CONFIGURE_UI_CC}" \
|
|
103
|
+
-var="configure_precisefp_client_credentials=${CONFIGURE_PRECISEFP_CLIENT_CREDENTIALS}" \
|
|
104
|
+
-var="use_azuread_app=${USE_AZUREAD_APP}" \
|
|
105
|
+
-var="deploy_azuread_app=${DEPLOY_AZUREAD_APP}" \
|
|
106
|
+
-- "$IMPORT_ADDRESS" "$IMPORT_ID"
|
|
107
|
+
else
|
|
108
|
+
terraform import \
|
|
109
|
+
-var-file="./env/${CURRENT_ENVIRONMENT}/${AWS_REGION}/terraform.tfvars" \
|
|
110
|
+
-- "$IMPORT_ADDRESS" "$IMPORT_ID"
|
|
111
|
+
fi
|
package/terraform/plan.sh
CHANGED
|
@@ -7,6 +7,8 @@ export ROLE_NAME="${3:-atlassian-bitbucket-pipelines-runner-eks-role}"
|
|
|
7
7
|
|
|
8
8
|
AWS_REGION="${4:-us-west-2}"
|
|
9
9
|
CLUSTER_NAME="${5:-}"
|
|
10
|
+
TF_OPTIONS="${TF_OPTIONS:-}"
|
|
11
|
+
TARGET="${TARGET:-}"
|
|
10
12
|
|
|
11
13
|
if [[ -z "$PROJECT" ]]; then
|
|
12
14
|
echo "Error: Project name is required."
|
|
@@ -34,6 +36,8 @@ fi
|
|
|
34
36
|
|
|
35
37
|
echo "Using EKS cluster: $EKS_CLUSTER_NAME"
|
|
36
38
|
echo "Current environment: $CURRENT_ENVIRONMENT"
|
|
39
|
+
echo "TF_OPTIONS: $TF_OPTIONS"
|
|
40
|
+
echo "TARGET: $TARGET"
|
|
37
41
|
|
|
38
42
|
export SESSION_NAME="EKSAdminSession"
|
|
39
43
|
export ROLE_ARN="arn:aws:iam::$(aws sts get-caller-identity | jq -r '.Account'):role/$ROLE_NAME"
|
|
@@ -55,12 +59,16 @@ if [[ "$PROJECT" == "bb-build-agent-shell" ]]; then
|
|
|
55
59
|
|
|
56
60
|
terraform plan -var-file="./env/${CURRENT_ENVIRONMENT}/${AWS_REGION}/terraform.tfvars" \
|
|
57
61
|
-var-file="./env/${CURRENT_ENVIRONMENT}/${AWS_REGION}/build_agent_configuration.tfvars.json" \
|
|
58
|
-
|
|
62
|
+
$TARGET \
|
|
63
|
+
-out .tfplan \
|
|
64
|
+
$TF_OPTIONS
|
|
59
65
|
elif [[ "$PROJECT" == "s3" ]]; then
|
|
60
66
|
terraform plan -var-file="./env/${CURRENT_ENVIRONMENT}/${AWS_REGION}/terraform.tfvars" \
|
|
61
67
|
-var="site=${SITE_NAME}" \
|
|
62
68
|
-var="env=${CURRENT_ENVIRONMENT}" \
|
|
63
|
-
|
|
69
|
+
$TARGET \
|
|
70
|
+
-out .tfplan \
|
|
71
|
+
$TF_OPTIONS
|
|
64
72
|
elif [[ "$PROJECT" == "idp" ]]; then
|
|
65
73
|
terraform plan -var-file="./env/${CURRENT_ENVIRONMENT}/${AWS_REGION}/terraform.tfvars" \
|
|
66
74
|
-var="site=${SITE_NAME}" \
|
|
@@ -76,7 +84,12 @@ elif [[ "$PROJECT" == "idp" ]]; then
|
|
|
76
84
|
-var="configure_precisefp_client_credentials=${CONFIGURE_PRECISEFP_CLIENT_CREDENTIALS}" \
|
|
77
85
|
-var="use_azuread_app=${USE_AZUREAD_APP}" \
|
|
78
86
|
-var="deploy_azuread_app=${DEPLOY_AZUREAD_APP}" \
|
|
79
|
-
|
|
87
|
+
$TARGET \
|
|
88
|
+
-out .tfplan \
|
|
89
|
+
$TF_OPTIONS
|
|
80
90
|
else
|
|
81
|
-
terraform plan -var-file="./env/${CURRENT_ENVIRONMENT}/${AWS_REGION}/terraform.tfvars"
|
|
91
|
+
terraform plan -var-file="./env/${CURRENT_ENVIRONMENT}/${AWS_REGION}/terraform.tfvars" \
|
|
92
|
+
$TARGET \
|
|
93
|
+
-out .tfplan \
|
|
94
|
+
$TF_OPTIONS
|
|
82
95
|
fi
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { $ } from '../next/logger.js';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import axios from 'axios';
|
|
5
|
-
|
|
6
|
-
export async function deployMicroservice(
|
|
7
|
-
appName,
|
|
8
|
-
helmPath,
|
|
9
|
-
environment = 'dev',
|
|
10
|
-
tag = null,
|
|
11
|
-
) {
|
|
12
|
-
if (!appName || !helmPath) {
|
|
13
|
-
throw new Error(
|
|
14
|
-
'Missing required parameters. Usage: deployMicroservice(appName, helmPath, [environment], [tag])',
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
let deployTag = tag;
|
|
19
|
-
if (!deployTag) {
|
|
20
|
-
deployTag =
|
|
21
|
-
process.env.VERSION_TAG ||
|
|
22
|
-
process.env.BITBUCKET_TAG ||
|
|
23
|
-
(process.env.BITBUCKET_BUILD_NUMBER
|
|
24
|
-
? `build-${process.env.BITBUCKET_BUILD_NUMBER}`
|
|
25
|
-
: null);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (!deployTag) {
|
|
29
|
-
throw new Error(
|
|
30
|
-
'No tag specified and no default tag available from environment variables',
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const repoName = `gitops-${environment}`;
|
|
35
|
-
const filePath = `dp/${helmPath}/${appName}.values.yaml`;
|
|
36
|
-
|
|
37
|
-
const gitopsBranch =
|
|
38
|
-
environment === 'dev' || environment === 'uat'
|
|
39
|
-
? process.env.GITOPS_BRANCH || 'master'
|
|
40
|
-
: process.env.GITOPS_BRANCH || 'main';
|
|
41
|
-
|
|
42
|
-
let repoUrl;
|
|
43
|
-
if (environment === 'dev' && process.env.GITOPS_REP_TOKEN) {
|
|
44
|
-
repoUrl = `https://x-token-auth:${process.env.GITOPS_REP_TOKEN}@bitbucket.org/dp-cloud/${repoName}.git`;
|
|
45
|
-
} else if (
|
|
46
|
-
process.env.BITBUCKET_USERNAME &&
|
|
47
|
-
process.env.BITBUCKET_APP_PASSWORD
|
|
48
|
-
) {
|
|
49
|
-
repoUrl = `https://${process.env.BITBUCKET_USERNAME}:${process.env.BITBUCKET_APP_PASSWORD}@bitbucket.org/dp-cloud/${repoName}.git`;
|
|
50
|
-
} else {
|
|
51
|
-
throw new Error(
|
|
52
|
-
'No authentication credentials found for GitOps repository',
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
console.log('=========================================');
|
|
57
|
-
console.log('Microservice Deployment Configuration');
|
|
58
|
-
console.log('=========================================');
|
|
59
|
-
console.log(`Application: ${appName}`);
|
|
60
|
-
console.log(`Environment: ${environment}`);
|
|
61
|
-
console.log(`Tag: ${deployTag}`);
|
|
62
|
-
console.log(`GitOps Repo: ${repoName}`);
|
|
63
|
-
console.log(`Values File: ${filePath}`);
|
|
64
|
-
console.log(`Branch: ${gitopsBranch}`);
|
|
65
|
-
console.log('=========================================');
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
console.log('Cloning GitOps repository...');
|
|
69
|
-
await $`git clone --depth 1 ${repoUrl} ${repoName}`;
|
|
70
|
-
|
|
71
|
-
console.log('Checking if directory exists...');
|
|
72
|
-
await $`ls -la ${repoName}`;
|
|
73
|
-
|
|
74
|
-
console.log(`Changing to directory: ${repoName}`);
|
|
75
|
-
const originalDir = process.cwd();
|
|
76
|
-
process.chdir(repoName);
|
|
77
|
-
|
|
78
|
-
console.log('Verifying directory change...');
|
|
79
|
-
const newDir = process.cwd();
|
|
80
|
-
console.log(`Original: ${originalDir}`);
|
|
81
|
-
console.log(`New: ${newDir}`);
|
|
82
|
-
|
|
83
|
-
await $`cd ${repoName} && git config user.email "pipeline@bitbucket.org"`;
|
|
84
|
-
|
|
85
|
-
if (process.env.BITBUCKET_STEP_TRIGGERER_UUID) {
|
|
86
|
-
try {
|
|
87
|
-
const response = await axios.get(
|
|
88
|
-
`https://api.bitbucket.org/2.0/users/${process.env.BITBUCKET_STEP_TRIGGERER_UUID}`,
|
|
89
|
-
);
|
|
90
|
-
const triggererUsername = response.data.display_name;
|
|
91
|
-
console.log(`📌 Run triggered by: ${triggererUsername}`);
|
|
92
|
-
await $`cd ${repoName} && git config user.name ${triggererUsername}`;
|
|
93
|
-
} catch (error) {
|
|
94
|
-
console.warn('Failed to fetch Bitbucket user info:', error.message);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
console.log(`Attempting to checkout branch: ${gitopsBranch}`);
|
|
99
|
-
await $`cd ${repoName} && git checkout ${gitopsBranch}`;
|
|
100
|
-
|
|
101
|
-
const fullFilePath = path.resolve(filePath);
|
|
102
|
-
console.log(`Looking for file at: ${fullFilePath}`);
|
|
103
|
-
if (!fs.existsSync(fullFilePath)) {
|
|
104
|
-
throw new Error(
|
|
105
|
-
`Values file ${filePath} does not exist in ${repoName} on branch ${gitopsBranch}`,
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
console.log(`Updating image tag to ${deployTag}...`);
|
|
110
|
-
|
|
111
|
-
let fileContent = fs.readFileSync(fullFilePath, 'utf8');
|
|
112
|
-
|
|
113
|
-
const tagRegex = /^ {2}tag: .*/gm;
|
|
114
|
-
const newContent = fileContent.replace(tagRegex, ` tag: ${deployTag}`);
|
|
115
|
-
|
|
116
|
-
if (fileContent === newContent) {
|
|
117
|
-
console.log(`No changes detected - tag is already ${deployTag}`);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
fs.writeFileSync(fullFilePath, newContent, 'utf8');
|
|
122
|
-
|
|
123
|
-
console.log('Changes to be committed:');
|
|
124
|
-
await $`cd ${repoName} && git diff ${filePath}`;
|
|
125
|
-
|
|
126
|
-
await $`cd ${repoName} && git add ${filePath}`;
|
|
127
|
-
await $`cd ${repoName} && git commit -m "Update ${appName} image tag to ${deployTag} in ${environment} environment"`;
|
|
128
|
-
|
|
129
|
-
console.log('Pushing changes to GitOps repository...');
|
|
130
|
-
await $`cd ${repoName} && git push origin ${gitopsBranch}`;
|
|
131
|
-
|
|
132
|
-
console.log('=========================================');
|
|
133
|
-
console.log(
|
|
134
|
-
`✅ Successfully deployed ${appName}:${deployTag} to ${environment}`,
|
|
135
|
-
);
|
|
136
|
-
console.log('=========================================');
|
|
137
|
-
} catch (error) {
|
|
138
|
-
console.error('Error during microservice deployment:', error.message);
|
|
139
|
-
throw error;
|
|
140
|
-
} finally {
|
|
141
|
-
try {
|
|
142
|
-
process.chdir('..');
|
|
143
|
-
await $`rm -rf ${repoName}`;
|
|
144
|
-
} catch (cleanupError) {
|
|
145
|
-
console.warn(
|
|
146
|
-
'Warning: Failed to clean up temporary directory:',
|
|
147
|
-
cleanupError.message,
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export default deployMicroservice;
|