Skip to content

Commit

Permalink
control plane source config changed to github
Browse files Browse the repository at this point in the history
  • Loading branch information
sfdevops committed Aug 23, 2024
1 parent a96ea82 commit 8791747
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 29 deletions.
4 changes: 2 additions & 2 deletions terraform/control-plane-application/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ spec:
namespace: ${local.kubernetes_ns}
server: 'https://kubernetes.default.svc'
source:
path: control-plane
repoURL: 'https://git-codecommit.${var.region}.amazonaws.com/v1/repos/${var.namespace}-${var.environment}-tenant-management-gitops-repository'
path: onboarded-tenants/control-plane
repoURL: 'https://${data.aws_ssm_parameter.github_user.value}@github.com/${data.aws_ssm_parameter.github_repo.value}.git'
targetRevision: main
helm:
valueFiles:
Expand Down
68 changes: 41 additions & 27 deletions terraform/control-plane-application/push-helm-values.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,63 @@ export NAMESPACE=sf-arc-saas
export ENVIRONMENT=dev


# Install git-remote-codecommit
pip3 install git-remote-codecommit || { echo "Failed to install git-remote-codecommit"; exit 1; }
# Retrieve GitHub username from SSM Parameter Store
GITHUB_USERNAME=$(aws ssm get-parameter --name "/github_user" --with-decryption --region "${AWS_REGION}" --query "Parameter.Value" --output text)
if [ -z "$GITHUB_USERNAME" ]; then
echo "Failed to retrieve GitHub username from SSM Parameter Store"
exit 1
fi

# Clone codecommit repo
git clone codecommit::${AWS_REGION}://${NAMESPACE}-${ENVIRONMENT}-tenant-management-gitops-repository || { echo "Failed to clone repository"; exit 1; }
# Retrieve GitHub token from SSM Parameter Store
GITHUB_TOKEN=$(aws ssm get-parameter --name "/github_token" --with-decryption --region "${AWS_REGION}" --query "Parameter.Value" --output text)
if [ -z "$GITHUB_TOKEN" ]; then
echo "Failed to retrieve GitHub token from SSM Parameter Store"
exit 1
fi

# Change directory
cd ${NAMESPACE}-${ENVIRONMENT}-tenant-management-gitops-repository || { echo "Failed to change directory"; exit 1; }
# Retrieve GitHub Repo from SSM Parameter Store
GITHUB_REPO=$(aws ssm get-parameter --name "/github_saas_repo" --with-decryption --region "${AWS_REGION}" --query "Parameter.Value" --output text)
if [ -z "$GITHUB_REPO" ]; then
echo "Failed to retrieve GitHub repo from SSM Parameter Store"
exit 1
fi

# Copy control-plane values.yaml to control-plane directory
if [ -d "../output" ]; then
cp -r ../output/* control-plane/ || { echo "Failed to copy files"; exit 1; }
else
echo "'output' folder does not exist. Skipping file copy."
# Construct the GitHub repository URL
GITHUB_REPO_URL="https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@github.com/${GITHUB_REPO}.git"

# Check if the directory already exists and remove it if necessary
if [ -d "${NAMESPACE}-saas-management-repository" ]; then
echo "Directory '${NAMESPACE}-saas-management-repository' already exists. Removing it."
rm -rf "${NAMESPACE}-saas-management-repository" || { echo "Failed to remove existing directory"; exit 1; }
fi

# Set origin URL
git remote set-url origin codecommit::${AWS_REGION}://${NAMESPACE}-${ENVIRONMENT}-tenant-management-gitops-repository || { echo "Failed to set remote URL"; exit 1; }
# Clone the GitHub repository
git clone "${GITHUB_REPO_URL}" || { echo "Failed to clone GitHub repository"; exit 1; }

# Check if main branch already exists
if git show-ref --verify --quiet refs/heads/main; then
echo "Main branch already exists. Skipping branch creation."
# Change to the cloned repository directory
cd "${NAMESPACE}-saas-management-repository" || { echo "Failed to change directory to cloned repository"; exit 1; }

# Copy control-plane values.yaml to control-plane directory
if [ -d "../output" ]; then
cp -r ../output/* onboarded-tenants/control-plane/ || { echo "Failed to copy files"; exit 1; }
else
# Create and switch to main branch
git checkout -b main || { echo "Failed to create and switch to main branch"; exit 1; }
echo "'output' folder does not exist. Skipping file copy."
fi

# Configure user email
# Configure Git with user details
git config --global --unset credential.helper
git config --global credential.helper 'cache --timeout=900'
git config --global user.email 'devops@sourcefuse.com' || { echo "Failed to configure user email"; exit 1; }

# Configure user name
git config --global user.name 'sfdevops' || { echo "Failed to configure user name"; exit 1; }

# Add and commit changes
if [ -n "$(git status --porcelain)" ]; then
git add . || { echo "Failed to add files"; exit 1; }

git commit -m 'Helm Chart Updated' || { echo "Failed to commit changes"; exit 1; }

git push origin main || { echo "Failed to push changes"; exit 1; }

git commit -m 'control plane values.yaml updated' || { echo "Failed to commit changes"; exit 1; }
git push ${GITHUB_REPO_URL} main || { echo "Failed to push changes"; exit 1; }
echo "Changes committed and pushed successfully"
else
echo "Nothing to commit, working tree clean. Exiting..."
fi

echo "Script executed successfully"
echo "Script executed successfully"

0 comments on commit 8791747

Please sign in to comment.