review-service CI/Cd 파이프라인 설정

이 섹션은 product-composite-service 마이크로서비스 설정에 이어서 수행하는 것이 좋습니다. [product-composite-server CI/CD 파이프라인 설정]

1. 파이프라인에서 사용할 ArgoCD Admin 암호 Secrets Manager에 저장

cd ~/environment/eks-workshop/cloud9

# 파이프라인에서 참조할 ArgoCD 암호를 AWS Secrets Manager에 저장합니다.
# ArgoCD Admin 암호는 `테라폼을 통한 아마존 EKS 프로비저닝` 단계에서 설정한 암호를 사용합니다.
./set-argocd-admin-password-secrets-manager.sh "Abraca00#1" review-service-ci-argocd-admin-password

2. review-service Helm Chart 의존성 빌드

review-service 마이크로서비스 Helm Chart의 의존성을 빌드하여 이후 ArgoCD 애플리케이션을 생성할 수 있도록 준비합니다. 이 작업은 초기에 한번만 수행하면 되고 이후에는 빌드 파이프라인이 Helm 리포지터리를 변경하면 ArgoCD에 의해 자동으로 Sync되게 됩니다.

# 작업을 도와주는 어플리케이션 Makefile 경로로 이동합니다.
cd ~/environment/eks-workshop/microservices-cicd-pipeline/review-service

# Helm 의존성을 업데이트합니다.
make helm-dep-up-all ENV=prod

# Helm 의존성을 업데이트한 템플릿 결과를 확인합니다.
make helm-template-env ENV=prod

3. review-serviceHelm 리포지터리 설정

# 어플리케이션 Helm 경로로 이동합니다.
cd ~/environment/eks-workshop/microservices-cicd-pipeline/review-service/kubernetes/helm

# CodeCommit GitOps 리포지터리와 연결합니다.
# 우리는 Git 리포지터리를 초기화하지 않았으므로, 아래와 같이 하면 Outer git 저장소 내에 Inner git 저장소를 Tracking하게 됩니다. 이와 유사하지만 Git 저장소 내에서 Nested Git 저장소를 좀 더 체계적으로 운영하는 방법은 Git Submodule이 있습니다.
git init
git branch -M main

export HELM_CODECOMMIT_URL=$(aws codecommit get-repository --repository-name review-service-configuration --region ap-northeast-2 | grep -o '"cloneUrlHttp": "[^"]*' | grep -o '[^"]*$')
echo $HELM_CODECOMMIT_URL

git remote add ccorigin $HELM_CODECOMMIT_URL

# Git 스테이징 영역에 파일을 추가합니다.
git add .

# Commit 및 배포 리포지터리에 Push합니다.
git commit -am "First commit."
git push --set-upstream ccorigin main

3. ArgoCD 애플리케이션 설정

이번에는 product-composite-service 마이크로서비스 설정 시 ArgoCD UI를 사용한 것과 달리 ArgoCD CLI를 활용하여 애플리케이션 설정을 수행해 보도록 하겠습니다.

  1. ArgoCD ServerArgoCD CLI로 로그인 합니다

# Production EKS 클러스터에서 작업합니다.
kcp

ARGOCD_SERVER=`kubectl get ingress/argocd-server -n argocd -o json | jq --raw-output '.status.loadBalancer.ingress[0].hostname'`
echo "ARGOCD_SERVER: ${ARGOCD_SERVER}"

argocd login ${ARGOCD_SERVER} --username admin --password "Abraca00#1" --insecure --grpc-web
  1. review-service 마이크로서비스의 GitOps 리포지터리를 ArgoCD에 연결합니다. 아래에서 <Username><Password>는 앞서 [product-composite-service CI/CD 파이프라인 설정] 페이지의 3. ArgoCD 애플리케이션 설정 섹션에서 생성한 `AWS CodeCommit₩용 ₩IAM User₩의 Git Credentials를 사용합니다.

export HELM_CODECOMMIT_URL=$(aws codecommit get-repository --repository-name review-service-configuration --region ap-northeast-2 | grep -o '"cloneUrlHttp": "[^"]*' | grep -o '[^"]*$')
echo $HELM_CODECOMMIT_URL

# 아래에서 <Username>과 <Password>는 앞서 AWS CodeCommit에서 생성한 IAM User의 Git Credentials를 사용합니다.
argocd repo add $HELM_CODECOMMIT_URL --type git --username "<Username>" --password "<Password>" --insecure-skip-server-verification
  1. review-service 마이크로서비스의 ArgoCD 애플리케이션을 생성합니다.

# ArgoCD 어플리케이션 정의 파일을 담은 디렉토리로 이동합니다.
cd ~/environment/eks-workshop/microservices-cicd-pipeline/review-service/kubernetes/argocd

APPLICATION_NAME=review-service NAMESPACE=hands-on envsubst < argocd-application-template.yaml > argocd-application.yaml

# ArgoCD 어플리케이션을 생성합니다.
argocd app create -f argocd-application.yaml

위와 같이 수행하면 ArgoCDreview-service 마이크로서비스의 애플리케이션이 생성됩니다.

  1. 이렇게 ArgoCD에서 어플리케이션을 생성하기만 하고 Sync 하지 않은 채로 두어도 됩니다. ArgoCD 파이프라인이 이후에 Sync를 수행하게 됩니다.

4. review-service 빌드 및 켄테이너 이미지 전달

  1. 이제 어플리케이션의 빌드 및 전달 파이프라인이 시작될 수 있도록 애플리케이션 소스를 소스 리포지터리에 연결하고 푸시합니다.

# 어플리케이션 소스 경로로 이동합니다.
cd ~/environment/eks-workshop/microservices-cicd-pipeline/review-service/app-src

# Git에 연결합니다.
# 우리는 Git 리포지터리를 초기화하지 않았으므로, 아래와 같이 하면 Outer git 저장소 내에 Inner git 저장소를 Tracking하게 됩니다. 이와 유사하지만 Git 저장소 내에서 Nested Git 저장소를 좀 더 체계적으로 운영하는 방법은 Git Submodule이 있습니다.
git init
git branch -M main

# AWS CLI를 통해서도 HTTPS URL을 바로 확인할 수 있습니다.
export APP_CODECOMMIT_URL=$(aws codecommit get-repository --repository-name review-service-application --region ap-northeast-2 | grep -o '"cloneUrlHttp": "[^"]*' | grep -o '[^"]*$')
echo $APP_CODECOMMIT_URL

# CodeCommit 소스 리포지터리와 연결
git remote add ccorigin $APP_CODECOMMIT_URL

# 3. Git 스테이징 영역에 파일을 추가합니다.
git add .

# 4. Commit 및 배포 리포지터리에 Push합니다.
git commit -am "First commit."
git push --set-upstream ccorigin main
  1. 빌드 파이프라인이 성공적으로 수행되는지 확인합니다.

진행자의 안내를 받아 파이프라인의 각 단계를 둘러보면서 어떤 작업이 수행되는지 확인합니다.

Last updated