Skip to content

Commit 0001997

Browse files
erastusndicoerastus.ndi
andauthored
feat: Updated Prod Workflow To Match AWS Profile (#36)
* feat: Updated Prod Workflow To Match AWS Profile * feat: Updated Prod Workflow To Match AWS Profile * feat: Updated Prod Workflow To Match AWS Profile --------- Co-authored-by: erastus.ndi <[email protected]>
1 parent 9285a7c commit 0001997

File tree

3 files changed

+86
-15
lines changed

3 files changed

+86
-15
lines changed

.github/workflows/deploy-to-prod.yaml

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,43 @@ jobs:
2828
- name: Checkout
2929
uses: actions/checkout@v4
3030

31+
- name: Install Required Tools
32+
run: |
33+
npm install -g typescript
34+
echo "NODE.JS version: $(node -v)"
35+
echo "NPM version: $(npm -v)"
36+
echo "AWS CLI version: $(aws --version)"
37+
38+
# First, authenticate to non-prod to access staging artifacts
39+
- name: Configure AWS credentials for Non-Prod (Staging)
40+
uses: aws-actions/[email protected]
41+
with:
42+
role-to-assume: ${{ env.NON_PROD_DEPLOYMENT_ROLE }}
43+
aws-region: ${{ env.AWS_REGION }}
44+
role-session-name: staging-access
45+
46+
- name: Setup Non-Prod AWS Profile
47+
run: |
48+
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile nonprod
49+
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile nonprod
50+
aws configure set aws_session_token $AWS_SESSION_TOKEN --profile nonprod
51+
aws configure set region ${{ env.AWS_REGION }} --profile nonprod
52+
echo "Non-Prod profile configured"
53+
54+
# Then, authenticate to prod for deployment
3155
- name: Configure AWS credentials for Prod
3256
uses: aws-actions/[email protected]
3357
with:
3458
role-to-assume: ${{ env.PROD_DEPLOYMENT_ROLE }}
3559
aws-region: ${{ env.AWS_REGION }}
3660

37-
- name: Install Required Tools
61+
- name: Setup Prod AWS Profile
3862
run: |
39-
npm install -g typescript
40-
echo "NODE.JS version: $(node -v)"
41-
echo "NPM version: $(npm -v)"
42-
echo "AWS CLI version: $(aws --version)"
63+
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile prod
64+
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile prod
65+
aws configure set aws_session_token $AWS_SESSION_TOKEN --profile prod
66+
aws configure set region ${{ env.AWS_REGION }} --profile prod
67+
echo "Prod profile configured"
4368
4469
- name: Prepare Scripts
4570
run: |
@@ -55,6 +80,15 @@ jobs:
5580
chmod +x ./pipeline_scripts/functions.sh
5681
ls -la ./pipeline_scripts/
5782
83+
- name: Verify AWS Profiles
84+
run: |
85+
echo "Available AWS profiles:"
86+
aws configure list-profiles
87+
echo "Testing nonprod profile access:"
88+
aws sts get-caller-identity --profile nonprod
89+
echo "Testing prod profile access:"
90+
aws sts get-caller-identity --profile prod
91+
5892
- name: Copy Artifacts and Deploy to Prod
5993
run: |
6094
echo "Starting prod deployment for version ${{ github.event.inputs.version }}"

pipeline_scripts/deploy-to-prod.sh

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,73 @@ if [ ! -f "./functions.sh" ]; then
2929
fi
3030
source ./functions.sh
3131

32-
log_message "Getting bucket names from SSM parameters"
32+
log_message "Getting bucket names from SSM parameters (using prod profile)"
33+
# Get S3 bucket base name using prod profile since SSM parameters are in prod account
34+
export AWS_PROFILE=prod
3335
s3_bucket_zip_files
3436
STAGING_BUCKET="$S3-staging"
3537
PROD_BUCKET="$S3-$ENVIRONMENT"
3638

3739
log_message "STAGING_BUCKET: $STAGING_BUCKET"
3840
log_message "PROD_BUCKET: $PROD_BUCKET"
3941

40-
log_message "Checking if version $VERSION exists in staging bucket"
42+
log_message "Checking if version $VERSION exists in staging bucket (using nonprod profile)"
43+
44+
# Switch to nonprod profile for staging bucket access
45+
export AWS_PROFILE=nonprod
4146
aws s3 ls s3://$STAGING_BUCKET/ | grep -v '/$' | grep "v${VERSION}"
4247
if [ $? -ne 0 ]; then
4348
log_message "ERROR: Version $VERSION not found in staging bucket $STAGING_BUCKET"
4449
exit 1
4550
fi
4651
log_message "Version $VERSION found in staging bucket"
4752

48-
log_message "Copying versioned artifacts from staging to prod"
49-
artifacts_copied=0
50-
aws s3 ls s3://$STAGING_BUCKET/ | grep -v '/$' | grep "v${VERSION}" | awk '{print $4}' | while read FILENAME; do
51-
log_message "Copying $FILENAME from staging to prod"
52-
aws s3 cp s3://$STAGING_BUCKET/$FILENAME s3://$PROD_BUCKET/$FILENAME
53-
artifacts_copied=$((artifacts_copied + 1))
53+
# Create temporary directory for artifacts
54+
TEMP_DIR="/tmp/artifacts_v${VERSION}"
55+
mkdir -p "$TEMP_DIR"
56+
log_message "Created temporary directory: $TEMP_DIR"
57+
58+
log_message "Downloading versioned artifacts from staging to local runner (using nonprod profile)"
59+
artifacts_downloaded=0
60+
61+
# Use nonprod profile for staging bucket access
62+
export AWS_PROFILE=nonprod
63+
while read FILENAME; do
64+
log_message "Downloading $FILENAME from staging to local runner"
65+
aws s3 cp s3://$STAGING_BUCKET/$FILENAME "$TEMP_DIR/$FILENAME"
66+
artifacts_downloaded=$((artifacts_downloaded + 1))
67+
done < <(aws s3 ls s3://$STAGING_BUCKET/ | grep -v '/$' | grep "v${VERSION}" | awk '{print $4}')
68+
69+
log_message "Downloaded $artifacts_downloaded artifacts to local runner"
70+
71+
log_message "Uploading artifacts from local runner to prod bucket (using prod profile)"
72+
artifacts_uploaded=0
73+
# Switched to prod profile for prod bucket access
74+
export AWS_PROFILE=prod
75+
for FILENAME in "$TEMP_DIR"/*; do
76+
if [ -f "$FILENAME" ]; then
77+
BASENAME=$(basename "$FILENAME")
78+
log_message "Uploading $BASENAME from runner to prod bucket"
79+
aws s3 cp "$FILENAME" s3://$PROD_BUCKET/$BASENAME
80+
artifacts_uploaded=$((artifacts_uploaded + 1))
81+
fi
5482
done
5583

56-
log_message "$artifacts_copied artifacts copied successfully"
84+
log_message "$artifacts_uploaded artifacts uploaded successfully to prod"
85+
86+
# Clean up temporary directory
87+
rm -rf "$TEMP_DIR"
88+
log_message "Cleaned up temporary directory"
5789

5890
export SEMANTIC_VERSION="$VERSION"
5991

6092

6193
log_message "Running update-lambda-functions.sh with version $SEMANTIC_VERSION"
6294
./update-lambda-functions.sh "$SEMANTIC_VERSION"
6395

64-
log_message "Verifying Lambda deployments in $ENVIRONMENT environment"
96+
log_message "Verifying Lambda deployments in $ENVIRONMENT environment (using prod profile)"
97+
98+
export AWS_PROFILE=prod
6599

66100
CORE_LAMBDA=$(aws ssm get-parameter \
67101
--name /lambda/kccorename \

pipeline_scripts/update-lambda-functions.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
set -e
33
PIPELINE_DIR="$GITHUB_WORKSPACE/pipeline_scripts"
44

5+
# ======== Set AWS Profile =========
6+
export AWS_PROFILE=prod
7+
58
# =================================
69
cd $PIPELINE_DIR
710
source ./functions.sh

0 commit comments

Comments
 (0)