@docupace/pipeline 1.0.3 → 1.0.4-1.haproxysync.2

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.
@@ -0,0 +1,123 @@
1
+ import axios from 'axios';
2
+
3
+ const CORE_JENKINS_URL = 'http://devops.corp.docupace.com';
4
+ const CORE_JOB_NAME = 'auto-deploy-site';
5
+ const CORE_USERNAME = process.env.CORE_JENKINS_USERNAME;
6
+ const CORE_API_TOKEN = process.env.CORE_JENKINS_API_TOKEN;
7
+
8
+ const CONNECT_JENKINS_URL = 'http://usdoc-s-buildui.corp.docupace.com/jenkins';
9
+ const CONNECT_JOB_NAME = 'docupace_build_and_run_site_v2';
10
+ const CONNECT_USERNAME = process.env.CONNECT_JENKINS_USERNAME;
11
+ const CONNECT_API_TOKEN = process.env.CONNECT_JENKINS_API_TOKEN;
12
+
13
+ export async function deployCore(env, site, liquibase, gitBranch) {
14
+ const parameters = {
15
+ environment: env,
16
+ site: site.toUpperCase(),
17
+ runLiquibase: liquibase,
18
+ gitBranch,
19
+ };
20
+
21
+ return callJenkinsJob({
22
+ jenkinsUrl: CORE_JENKINS_URL,
23
+ jobName: CORE_JOB_NAME,
24
+ auth: { username: CORE_USERNAME, password: CORE_API_TOKEN },
25
+ parameters,
26
+ });
27
+ }
28
+
29
+ // eslint-disable-next-line no-unused-vars
30
+ export async function deployConnect(env, site, liquibase, branch) {
31
+ const parameters = {
32
+ BUILD_ENVIRONMENT: env,
33
+ BUILD_SITE: site,
34
+ RUN_LIQUIBASE: liquibase,
35
+ };
36
+
37
+ return callJenkinsJob({
38
+ jenkinsUrl: CONNECT_JENKINS_URL,
39
+ jobName: CONNECT_JOB_NAME,
40
+ auth: { username: CONNECT_USERNAME, password: CONNECT_API_TOKEN },
41
+ parameters,
42
+ });
43
+ }
44
+
45
+ export async function callJenkinsJob({
46
+ jenkinsUrl,
47
+ jobName,
48
+ auth,
49
+ parameters,
50
+ }) {
51
+ try {
52
+ // Trigger the job
53
+ console.log('Triggering Jenkins job...');
54
+ const buildResponse = await axios.post(
55
+ `${jenkinsUrl}/job/${jobName}/buildWithParameters`,
56
+ new URLSearchParams(parameters),
57
+ {
58
+ auth,
59
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
60
+ validateStatus: (status) => status === 201 || status === 302, // Accept 201 and 302 as valid statuses
61
+ },
62
+ );
63
+
64
+ const queueUrl = buildResponse.headers.location;
65
+ console.log(`Job queued at: ${queueUrl}`);
66
+
67
+ // Poll queue for executable URL
68
+ let jobUrl = null;
69
+ while (!jobUrl) {
70
+ const queueResponse = await axios.get(`${queueUrl}api/json`, {
71
+ auth,
72
+ });
73
+ jobUrl = queueResponse.data.executable?.url || null;
74
+
75
+ if (!jobUrl) {
76
+ console.log('Waiting for job to start...');
77
+ await new Promise((resolve) => setTimeout(resolve, 5000));
78
+ }
79
+ }
80
+
81
+ jobUrl = jobUrl.replaceAll('https', 'http');
82
+
83
+ console.log(`Job started at: ${jobUrl}`);
84
+
85
+ // Stream console output
86
+ const consoleUrl = `${jobUrl}consoleText`;
87
+ let lastSize = 0;
88
+
89
+ console.log('Streaming job output...');
90
+ while (true) {
91
+ const consoleResponse = await axios.get(consoleUrl, {
92
+ auth,
93
+ responseType: 'text',
94
+ });
95
+
96
+ const consoleText = consoleResponse.data;
97
+ const newOutput = consoleText.slice(lastSize);
98
+ process.stdout.write(newOutput); // Write new output to console
99
+ lastSize = consoleText.length;
100
+
101
+ // Check job status
102
+ const jobResponse = await axios.get(`${jobUrl}api/json`, {
103
+ auth,
104
+ });
105
+ const result = jobResponse.data.result;
106
+
107
+ if (result) {
108
+ console.log(`\nJob completed with result: ${result}`);
109
+ if (result === 'SUCCESS') {
110
+ return;
111
+ } else {
112
+ throw new Error('Jenkins job failed');
113
+ }
114
+ }
115
+
116
+ // Wait before polling again
117
+ await new Promise((resolve) => setTimeout(resolve, 5000));
118
+ }
119
+ } catch (error) {
120
+ console.error('Error:', error.message);
121
+ throw error;
122
+ }
123
+ }
@@ -0,0 +1,83 @@
1
+ import axios from 'axios';
2
+
3
+ // Create preconfigured axios instance for Jira
4
+ const jiraClient = axios.create({
5
+ baseURL: 'https://docupacellc.atlassian.net',
6
+ auth: {
7
+ username: process.env.JIRA_API_EMAIL,
8
+ password: process.env.JIRA_API_KEY,
9
+ },
10
+ headers: {
11
+ 'Content-Type': 'application/json',
12
+ },
13
+ });
14
+
15
+ const packageComponents = {
16
+ 'docupace-ui': 'next-ui',
17
+ 'docupace-graphql-server': 'graphql-server',
18
+ '@docupace/template': 'template',
19
+ };
20
+ /**
21
+ * Updates the component version custom field in Jira
22
+ * @param {string} issueKey - The Jira issue key
23
+ * @param {string} component - The component name
24
+ * @param {string} version - The version to set
25
+ */
26
+ export async function updateComponentVersion(issueKey, packageName, version) {
27
+ const component = packageComponents[packageName] ?? packageName;
28
+ console.log(
29
+ `Updating ${issueKey} for package ${packageName} translated to component ${component} with version ${version}`,
30
+ );
31
+ try {
32
+ // First get current field value
33
+ const response = await jiraClient.get(
34
+ `/rest/api/2/issue/${issueKey}?fields=customfield_10458`,
35
+ );
36
+
37
+ let currentValue = response.data.fields.customfield_10458 || '';
38
+ let components = new Map();
39
+
40
+ // Parse existing components
41
+ if (currentValue) {
42
+ currentValue.split(';').forEach((entry) => {
43
+ const [comp, ver] = entry.split(':');
44
+ components.set(comp, ver);
45
+ });
46
+ }
47
+
48
+ // Update or add new component version
49
+ components.set(component, version);
50
+
51
+ // Convert back to string format
52
+ const newValue = Array.from(components.entries())
53
+ .map(([comp, ver]) => `${comp}:${ver}`)
54
+ .join(';');
55
+
56
+ // Update the field
57
+ await jiraClient.put(`/rest/api/2/issue/${issueKey}`, {
58
+ fields: {
59
+ customfield_10458: newValue,
60
+ },
61
+ });
62
+
63
+ console.log(`Updated component versions for ${issueKey}: ${newValue}`);
64
+ } catch (error) {
65
+ console.error(`Error updating Jira component version: ${error.message}`);
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Makes a request to the Jira API using preconfigured client
71
+ * @param {string} endpoint - The API endpoint (starting with /)
72
+ * @param {Object} options - Request options (method, body, etc)
73
+ * @returns {Promise<any>} The response data
74
+ */
75
+ export async function makeJiraRequest(endpoint, options = {}) {
76
+ try {
77
+ const response = await jiraClient.get(endpoint, options);
78
+ return response.data;
79
+ } catch (error) {
80
+ console.error(`Error making Jira request: ${error.message}`);
81
+ throw error;
82
+ }
83
+ }
@@ -0,0 +1,114 @@
1
+ import axios from 'axios';
2
+ import { getBitbucketInfo } from './config.js';
3
+
4
+ const BITBUCKET_BASE_URL = 'https://api.bitbucket.org/2.0';
5
+
6
+ const BITBUCKET_WS_URL = 'https://bitbucket.org/dp-cloud';
7
+
8
+ async function triggerPipelineByName(
9
+ repository,
10
+ pipelineName,
11
+ branch,
12
+ variables,
13
+ ) {
14
+ const { username, password, workspace } = getBitbucketInfo();
15
+ const url = `${BITBUCKET_BASE_URL}/repositories/${workspace}/${repository}/pipelines/`;
16
+ const auth = {
17
+ username: username,
18
+ password: password,
19
+ };
20
+
21
+ const payload = {
22
+ target: {
23
+ type: 'pipeline_ref_target',
24
+ ref_type: 'branch',
25
+ ref_name: branch,
26
+ selector: {
27
+ type: 'custom',
28
+ pattern: pipelineName,
29
+ },
30
+ },
31
+ variables: variables
32
+ ? Object.entries(variables).map(([key, value]) => ({
33
+ key,
34
+ value,
35
+ secured: false, // Set to true if the variable should be secure
36
+ }))
37
+ : undefined,
38
+ };
39
+
40
+ try {
41
+ const response = await axios.post(url, payload, { auth });
42
+ return response.data;
43
+ } catch (error) {
44
+ console.error(
45
+ 'Error triggering custom pipeline:',
46
+ error.response?.data || error.message,
47
+ );
48
+ throw error;
49
+ }
50
+ }
51
+
52
+ async function getPipelineStatus(repository, pipelineUUID) {
53
+ const { username, password, workspace } = getBitbucketInfo();
54
+ const url = `${BITBUCKET_BASE_URL}/repositories/${workspace}/${repository}/pipelines/${pipelineUUID}`;
55
+ const auth = {
56
+ username: username,
57
+ password: password,
58
+ };
59
+
60
+ try {
61
+ const response = await axios.get(url, { auth });
62
+ return response.data.state.name;
63
+ } catch (error) {
64
+ console.error(
65
+ 'Error fetching pipeline status:',
66
+ error.response?.data || error.message,
67
+ );
68
+ throw error;
69
+ }
70
+ }
71
+
72
+ export async function runPipeline(
73
+ repository,
74
+ pipelineName,
75
+ branch,
76
+ variables,
77
+ wait = false,
78
+ ) {
79
+ try {
80
+ console.log(
81
+ `Triggering custom pipeline: ${pipelineName} for branch: ${branch}...`,
82
+ );
83
+ const pipeline = await triggerPipelineByName(
84
+ repository,
85
+ pipelineName,
86
+ branch,
87
+ variables,
88
+ );
89
+
90
+ const pipelineUUID = pipeline.uuid;
91
+ const buildNumber = pipeline.build_number;
92
+
93
+ console.log(`Pipeline triggered with UUID: ${pipelineUUID}`);
94
+ console.log(
95
+ `See results here: ${BITBUCKET_WS_URL}/${repository}/piplines/results/${buildNumber}`,
96
+ );
97
+
98
+ if (!wait) {
99
+ return;
100
+ }
101
+
102
+ let status = '';
103
+ do {
104
+ console.log('Checking pipeline status...');
105
+ await new Promise((resolve) => setTimeout(resolve, 10000)); // Wait 10 seconds
106
+ status = await getPipelineStatus(repository, pipelineUUID);
107
+ console.log(`Pipeline status: ${status}`);
108
+ } while (['IN_PROGRESS', 'PENDING', 'RUNNING'].includes(status));
109
+
110
+ console.log(`Pipeline completed with status: ${status}`);
111
+ } catch (error) {
112
+ console.error('Error monitoring pipeline:', error.message);
113
+ }
114
+ }
@@ -1,46 +1,48 @@
1
- import { $ } from 'zx';
2
-
3
- export async function publish(GIT_SHA) {
4
- const BITBUCKET_REPO_SLUG = process.env.BITBUCKET_REPO_SLUG;
5
- const BUILD_IMAGE_NAME = `${BITBUCKET_REPO_SLUG}:build-${process.env.BITBUCKET_BUILD_NUMBER}`;
6
- const IMAGE_NAME = `${BITBUCKET_REPO_SLUG}:sha-${GIT_SHA}`;
7
- const JF_REGISTRY_FULL_URL = `${process.env.JF_REGISTRY_URL}/${process.env.JF_REGISTRY_REPO_NAME}`;
8
-
9
- console.log(`Publishing Docker image: ${IMAGE_NAME}`);
10
-
11
- // Docker login
12
- await $`echo ${process.env.JF_REGISTRY_PASSWORD_DEV} | docker login --username ${process.env.JF_REGISTRY_USER_DEV} --password-stdin ${process.env.JF_REGISTRY_URL}`;
13
-
14
- // Check if the image already exists
15
- try {
16
- await $`docker manifest inspect ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
17
- console.log(`Tag sha-${GIT_SHA} already exists in the remote repository. Skipping push.`);
18
- } catch {
19
- await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
20
- await $`docker push ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
21
- }
22
-
23
- // Tag and push build image
24
- await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
25
- await $`docker push ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
26
-
27
- // Fetch Git tags pointing to the current HEAD
28
- const gitTagsOutput = (await $`git tag --points-at HEAD`).stdout.trim();
29
- const gitTags = gitTagsOutput.split('\n').filter((tag) => tag);
30
-
31
- // Tag and push each Git tag as a Docker tag
32
- if (gitTags.length > 0) {
33
- console.log(`Found Git tags pointing to HEAD: ${gitTags.join(', ')}`);
34
- for (const gitTag of gitTags) {
35
- const dockerTag = `${JF_REGISTRY_FULL_URL}/${BITBUCKET_REPO_SLUG}:${gitTag}`;
36
- console.log(`Tagging and pushing Docker image for Git tag: ${gitTag}`);
37
- await $`docker tag ${IMAGE_NAME} ${dockerTag}`;
38
- await $`docker push ${dockerTag}`;
39
- }
40
- } else {
41
- console.log('No Git tags found pointing to the current HEAD.');
42
- }
43
-
44
- // Docker logout
45
- await $`docker logout ${process.env.JF_REGISTRY_URL}`;
46
- }
1
+ import { $ } from 'zx';
2
+
3
+ export async function publish(GIT_SHA) {
4
+ const BITBUCKET_REPO_SLUG = process.env.BITBUCKET_REPO_SLUG;
5
+ const BUILD_IMAGE_NAME = `${BITBUCKET_REPO_SLUG}:build-${process.env.BITBUCKET_BUILD_NUMBER}`;
6
+ const IMAGE_NAME = `${BITBUCKET_REPO_SLUG}:sha-${GIT_SHA}`;
7
+ const JF_REGISTRY_FULL_URL = `${process.env.JF_REGISTRY_URL}/${process.env.JF_REGISTRY_REPO_NAME}`;
8
+
9
+ console.log(`Publishing Docker image: ${IMAGE_NAME}`);
10
+
11
+ // Docker login
12
+ await $`echo ${process.env.JF_REGISTRY_PASSWORD_DEV} | docker login --username ${process.env.JF_REGISTRY_USER_DEV} --password-stdin ${process.env.JF_REGISTRY_URL}`;
13
+
14
+ // Check if the image already exists
15
+ try {
16
+ await $`docker manifest inspect ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
17
+ console.log(
18
+ `Tag sha-${GIT_SHA} already exists in the remote repository. Skipping push.`,
19
+ );
20
+ } catch {
21
+ await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
22
+ await $`docker push ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
23
+ }
24
+
25
+ // Tag and push build image
26
+ await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
27
+ await $`docker push ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
28
+
29
+ // Fetch Git tags pointing to the current HEAD
30
+ const gitTagsOutput = (await $`git tag --points-at HEAD`).stdout.trim();
31
+ const gitTags = gitTagsOutput.split('\n').filter((tag) => tag);
32
+
33
+ // Tag and push each Git tag as a Docker tag
34
+ if (gitTags.length > 0) {
35
+ console.log(`Found Git tags pointing to HEAD: ${gitTags.join(', ')}`);
36
+ for (const gitTag of gitTags) {
37
+ const dockerTag = `${JF_REGISTRY_FULL_URL}/${BITBUCKET_REPO_SLUG}:${gitTag}`;
38
+ console.log(`Tagging and pushing Docker image for Git tag: ${gitTag}`);
39
+ await $`docker tag ${IMAGE_NAME} ${dockerTag}`;
40
+ await $`docker push ${dockerTag}`;
41
+ }
42
+ } else {
43
+ console.log('No Git tags found pointing to the current HEAD.');
44
+ }
45
+
46
+ // Docker logout
47
+ await $`docker logout ${process.env.JF_REGISTRY_URL}`;
48
+ }
package/src/next/pull.js CHANGED
@@ -1,7 +1,7 @@
1
- import { $ } from 'zx';
2
-
3
- export async function pull(imageName) {
4
- const JF_REGISTRY_FULL_URL = `${process.env.JF_REGISTRY_URL}/${process.env.JF_REGISTRY_REPO_NAME}`;
5
- console.log(`Pulling Docker image: ${JF_REGISTRY_FULL_URL}/${imageName}`);
6
- await $`docker pull ${JF_REGISTRY_FULL_URL}/${imageName}`;
7
- }
1
+ import { $ } from 'zx';
2
+
3
+ export async function pull(imageName) {
4
+ const JF_REGISTRY_FULL_URL = `${process.env.JF_REGISTRY_URL}/${process.env.JF_REGISTRY_REPO_NAME}`;
5
+ console.log(`Pulling Docker image: ${JF_REGISTRY_FULL_URL}/${imageName}`);
6
+ await $`docker pull ${JF_REGISTRY_FULL_URL}/${imageName}`;
7
+ }
package/src/next/sonar.js CHANGED
@@ -1,23 +1,23 @@
1
- import { $ } from 'zx';
2
-
3
- export async function sonar(GIT_SHA) {
4
- const IMAGE_NAME = `${process.env.BITBUCKET_REPO_SLUG}:sha-${GIT_SHA}`;
5
- const SONAR_CONTAINER_NAME = `${process.env.BITBUCKET_REPO_SLUG}-${GIT_SHA}`;
6
-
7
- console.log(`Running Sonar analysis on Docker image: ${IMAGE_NAME}`);
8
-
9
- // Remove existing container
10
- const existingContainer = (
11
- await $`docker ps -a --filter "name=${SONAR_CONTAINER_NAME}" --format "{{.Names}}"`
12
- ).stdout.trim();
13
- if (existingContainer) {
14
- await $`docker rm -f ${SONAR_CONTAINER_NAME}`;
15
- }
16
-
17
- await $`docker run --rm \
18
- -e BRANCH=${process.env.BITBUCKET_BRANCH} \
19
- -e PR_ID=${process.env.BITBUCKET_PR_ID} \
20
- -e PR_DESTINATION_BRANCH=${process.env.BITBUCKET_PR_DESTINATION_BRANCH} \
21
- -e SONAR_TOKEN=${process.env.SONAR_TOKEN} \
22
- --name ${SONAR_CONTAINER_NAME} ${IMAGE_NAME} pnpm sonar`;
23
- }
1
+ import { $ } from 'zx';
2
+
3
+ export async function sonar(GIT_SHA) {
4
+ const IMAGE_NAME = `${process.env.BITBUCKET_REPO_SLUG}:sha-${GIT_SHA}`;
5
+ const SONAR_CONTAINER_NAME = `${process.env.BITBUCKET_REPO_SLUG}-${GIT_SHA}`;
6
+
7
+ console.log(`Running Sonar analysis on Docker image: ${IMAGE_NAME}`);
8
+
9
+ // Remove existing container
10
+ const existingContainer = (
11
+ await $`docker ps -a --filter "name=${SONAR_CONTAINER_NAME}" --format "{{.Names}}"`
12
+ ).stdout.trim();
13
+ if (existingContainer) {
14
+ await $`docker rm -f ${SONAR_CONTAINER_NAME}`;
15
+ }
16
+
17
+ await $`docker run --rm \
18
+ -e BRANCH=${process.env.BITBUCKET_BRANCH} \
19
+ -e PR_ID=${process.env.BITBUCKET_PR_ID} \
20
+ -e PR_DESTINATION_BRANCH=${process.env.BITBUCKET_PR_DESTINATION_BRANCH} \
21
+ -e SONAR_TOKEN=${process.env.SONAR_TOKEN} \
22
+ --name ${SONAR_CONTAINER_NAME} ${IMAGE_NAME} pnpm sonar`;
23
+ }
@@ -0,0 +1,43 @@
1
+ import axios from 'axios';
2
+
3
+ export async function vaultAddSiteData(SITE, SITE_CONFIG_REMOTE_PATH) {
4
+ const AUTH0_CLIENT_ID = process.env.AUTH0_CLIENT_ID;
5
+ const AUTH0_CLIENT_SECRET = process.env.AUTH0_CLIENT_SECRET;
6
+ const VAULT_ADDR = process.env.VAULT_ADDR; // Vault host URL from environment variables
7
+ const VAULT_TOKEN = process.env.VAULT_TOKEN; // Vault token from environment variables
8
+
9
+ if (!VAULT_ADDR || !VAULT_TOKEN) {
10
+ throw new Error('Missing VAULT_ADDR or VAULT_TOKEN environment variable.');
11
+ }
12
+
13
+ const vaultApiUrl = `${VAULT_ADDR}/v1/secret/data/${SITE}/common/config`;
14
+
15
+ try {
16
+
17
+ if (process.env.VAULT_SKIP_VERIFY === 'true') {
18
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
19
+ }
20
+
21
+ const response = await axios.post(
22
+ vaultApiUrl,
23
+ {
24
+ data: {
25
+ AUTH0_CLIENT_ID: AUTH0_CLIENT_ID,
26
+ AUTH0_CLIENT_SECRET: AUTH0_CLIENT_SECRET,
27
+ SITE_CONFIG_REMOTE_PATH: SITE_CONFIG_REMOTE_PATH,
28
+ },
29
+ },
30
+ {
31
+ headers: {
32
+ 'X-Vault-Token': VAULT_TOKEN,
33
+ 'Content-Type': 'application/json',
34
+ },
35
+ }
36
+ );
37
+
38
+ console.log('Data added to Vault successfully:', response.data);
39
+ } catch (error) {
40
+ console.error('Error adding data to Vault:', error.response?.data || error.message);
41
+ throw error;
42
+ }
43
+ }
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env bash
2
+ set -e
3
+
4
+ PROJECT=$1
5
+ export ROLE_NAME="${2:-atlassian-bitbucket-pipelines-runner-eks-role}"
6
+
7
+ if [[ -z "$PROJECT" ]]; then
8
+ echo "Error: Project name is required."
9
+ echo "Usage: $0 <project-name>"
10
+ exit 1
11
+ fi
12
+
13
+ export SESSION_NAME="EKSAdminSession"
14
+ export EKS_CLUSTER_NAME="connect-next-${CURRENT_ENVIRONMENT}-eks-cluster"
15
+ export ROLE_ARN="arn:aws:iam::$(aws sts get-caller-identity | jq -r '.Account'):role/$ROLE_NAME"
16
+ export ASSUME_ROLE_OUTPUT=$(aws sts assume-role --role-arn $ROLE_ARN --role-session-name $SESSION_NAME)
17
+ export AWS_ACCESS_KEY_ID=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.AccessKeyId')
18
+ export AWS_SECRET_ACCESS_KEY=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.SecretAccessKey')
19
+ export AWS_SESSION_TOKEN=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.SessionToken')
20
+ export TF_IN_AUTOMATION=1
21
+
22
+ aws sts get-caller-identity
23
+
24
+ cd "$BITBUCKET_CLONE_DIR/${PROJECT}"
25
+
26
+ terraform apply -input=false .tfplan
@@ -0,0 +1,61 @@
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
+ if [[ -z "$PROJECT" ]]; then
9
+ echo "Error: Project name is required."
10
+ echo "Usage: $0 <project-name> $1 <environment>"
11
+ exit 1
12
+ fi
13
+
14
+ if [[ -z "$CURRENT_ENVIRONMENT" ]]; then
15
+ echo "Error: ENVIRONMENT is required."
16
+ echo "Usage: $0 <project-name> $1 <environment>"
17
+ exit 1
18
+ fi
19
+
20
+ export SESSION_NAME="EKSAdminSession"
21
+ export EKS_CLUSTER_NAME="connect-next-${CURRENT_ENVIRONMENT}-eks-cluster"
22
+ export ROLE_ARN="arn:aws:iam::$(aws sts get-caller-identity | jq -r '.Account'):role/$ROLE_NAME"
23
+ export ASSUME_ROLE_OUTPUT=$(aws sts assume-role --role-arn $ROLE_ARN --role-session-name $SESSION_NAME)
24
+ export AWS_ACCESS_KEY_ID=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.AccessKeyId')
25
+ export AWS_SECRET_ACCESS_KEY=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.SecretAccessKey')
26
+ export AWS_SESSION_TOKEN=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.SessionToken')
27
+
28
+ aws sts get-caller-identity
29
+ cd "$BITBUCKET_CLONE_DIR/${PROJECT}"
30
+ mkdir -p ~/.ssh
31
+
32
+ echo "$atlassian_workspace_runner_ssh_key" | base64 -d > ~/.ssh/id_ed25519
33
+ chmod 600 ~/.ssh/id_ed25519
34
+ ssh-keyscan bitbucket.org > ~/.ssh/known_hosts
35
+
36
+ info () {
37
+ echo "PROJECT => $PROJECT"
38
+ echo "CURRENT_ENVIRONMENT => $CURRENT_ENVIRONMENT"
39
+ echo "SITE_NAME => $SITE_NAME"
40
+ echo "Using AWS Role: $ROLE_NAME"
41
+ }
42
+
43
+ if [[ "$PROJECT" == "s3" ]]; then
44
+ info
45
+ terraform init \
46
+ -input=false \
47
+ -reconfigure \
48
+ -backend=true \
49
+ -backend-config=./env/${CURRENT_ENVIRONMENT}/us-west-2/backend.tfvars \
50
+ -backend-config="key=us-west-2/${PROJECT}/${SITE_NAME}/${CURRENT_ENVIRONMENT}/terraform.tfstate"
51
+ elif [[ "$PROJECT" == "idp" ]]; then
52
+ info
53
+ terraform init \
54
+ -input=false \
55
+ -reconfigure \
56
+ -backend=true \
57
+ -backend-config=./env/${CURRENT_ENVIRONMENT}/us-west-2/backend.tfvars \
58
+ -backend-config="key=us-west-2/${PROJECT}/${SITE_NAME}/${CURRENT_ENVIRONMENT}/terraform.tfstate"
59
+ else
60
+ terraform init -backend-config=./env/${CURRENT_ENVIRONMENT}/us-west-2/backend.tfvars --reconfigure
61
+ fi
@@ -0,0 +1,63 @@
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
+ if [[ -z "$PROJECT" ]]; then
9
+ echo "Error: Project name is required."
10
+ echo "Usage: $0 <project-name> $1 <environment>"
11
+ exit 1
12
+ fi
13
+
14
+ if [[ -z "$CURRENT_ENVIRONMENT" ]]; then
15
+ echo "Error: ENVIRONMENT is required."
16
+ echo "Usage: $0 <project-name> $1 <environment>"
17
+ exit 1
18
+ fi
19
+
20
+ export SESSION_NAME="EKSAdminSession"
21
+ export EKS_CLUSTER_NAME="connect-next-${CURRENT_ENVIRONMENT}-eks-cluster"
22
+ export ROLE_ARN="arn:aws:iam::$(aws sts get-caller-identity | jq -r '.Account'):role/$ROLE_NAME"
23
+ export ASSUME_ROLE_OUTPUT=$(aws sts assume-role --role-arn $ROLE_ARN --role-session-name $SESSION_NAME)
24
+ export AWS_ACCESS_KEY_ID=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.AccessKeyId')
25
+ export AWS_SECRET_ACCESS_KEY=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.SecretAccessKey')
26
+ export AWS_SESSION_TOKEN=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.SessionToken')
27
+
28
+ aws sts get-caller-identity
29
+
30
+ cd "$BITBUCKET_CLONE_DIR/${PROJECT}"
31
+
32
+ if [[ "$PROJECT" == "bb-build-agent-shell" ]]; then
33
+ if [[ "$CURRENT_ENVIRONMENT" == "dev" ]]; then
34
+ echo "$dev_build_agent_configuration" | base64 -d > ./env/${CURRENT_ENVIRONMENT}/us-west-2/build_agent_configuration.tfvars.json
35
+ elif [[ "$CURRENT_ENVIRONMENT" == "qa" ]]; then
36
+ echo "$qa_build_agent_configuration" | base64 -d > ./env/${CURRENT_ENVIRONMENT}/us-west-2/build_agent_configuration.tfvars.json
37
+ fi
38
+
39
+ terraform plan -var-file="./env/${CURRENT_ENVIRONMENT}/us-west-2/terraform.tfvars" \
40
+ -var-file="./env/${CURRENT_ENVIRONMENT}/us-west-2/build_agent_configuration.tfvars.json" \
41
+ -out .tfplan
42
+ elif [[ "$PROJECT" == "s3" ]];then
43
+ terraform plan -var-file="./env/${CURRENT_ENVIRONMENT}/us-west-2/terraform.tfvars" \
44
+ -var="site=${SITE_NAME}" \
45
+ -var="env=${CURRENT_ENVIRONMENT}" \
46
+ -out .tfplan
47
+ elif [[ "$PROJECT" == "idp" ]];then
48
+ terraform plan -var-file="./env/${CURRENT_ENVIRONMENT}/us-west-2/terraform.tfvars" \
49
+ -var="site=${SITE_NAME}" \
50
+ -var="env=${CURRENT_ENVIRONMENT}" \
51
+ -var="docupace_domain=${DOCUPACE_DOMAIN}" \
52
+ -var="docupace_next_domain=${DOCUPACE_NEXT_DOMAIN}" \
53
+ -var="old_page_design=${USE_OLD_PAGE_DESIGN}" \
54
+ -var="use_new_domain=${USE_NEW_DOMAIN}" \
55
+ -var="configure_autologin=${CONFIGURE_AUTOLOGIN}" \
56
+ -var="configure_enterprise_ui=${CONFIGURE_ENTERPRISE_UI}" \
57
+ -var="enable_mfa=${ENABLE_MFA}" \
58
+ -var="configure_ui_cc=${CONFIGURE_UI_CC}" \
59
+ -var="configure_precisefp_client_credentials=${CONFIGURE_PRECISEFP_CLIENT_CREDENTIALS}" \
60
+ -out .tfplan
61
+ else
62
+ terraform plan -var-file="./env/${CURRENT_ENVIRONMENT}/us-west-2/terraform.tfvars" -out .tfplan
63
+ fi