Merge remote-tracking branch 'origin/release' into release #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#기존 gke 구성에서 gke kustomize 배포기능을 제외함 (Argo CD)가 그 역할을 대신함 | |
#Docker 이미지를 빌드하고, Google Container Registry(GCR)에 푸시한 후, 추가적으로 Argo CD를 사용하여 GKE(Google Kubernetes Engine)에 배포 | |
name: Build and Deploy to GKE For Argo CD | |
on: | |
push: | |
branches: | |
- release | |
env: | |
GKE_PROJECT: ${{ secrets.GKE_PROJECT }} | |
GKE_EMAIL: ${{ secrets.GKE_EMAIL }} | |
# GITHUB_SHA: ${{ github.sha }} | |
GKE_ZONE: asia-east1-a | |
GKE_CLUSTER: jsvill-cluster-1 | |
IMAGE: jsvill | |
IMAGE_TAG: latest | |
REGISTRY_HOSTNAME: gcr.io | |
DEPLOYMENT_NAME: jsvill | |
jobs: | |
#job을 여러개로 나누면, job마다 checkout을 중복으로 해줘야함해서 하나로함 | |
setup-build-publish-deploy: | |
name: Setup, Build, Publish, and Deploy | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: release | |
- name: JDK 16 설치 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '16' | |
distribution: 'corretto' | |
- name: application.yaml 파일 생성 | |
run: touch ./src/main/resources/application.yaml | |
- name: application.yaml에 작성 | |
run: echo "${{ secrets.APPLICATION }}" > ./src/main/resources/application.yaml | |
- name: application.yaml 내용 표시 | |
run: cat ./src/main/resources/application.yaml | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
- name: Build with Gradle | |
run: ./gradlew clean build -x test | |
- name: Authenticate with Google Cloud | |
uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: ${{ secrets.GKE_KEY }} | |
# Setup gcloud CLI | |
- name: Set up Cloud SDK | |
uses: 'google-github-actions/setup-gcloud@v2' | |
with: | |
project_id: ${{ secrets.GCP_PROJECT_ID }} | |
service_account_email: ${{ secrets.GKE_EMAIL }} | |
service_account_key: ${{ secrets.GKE_KEY }} | |
- name: Install gke-gcloud-auth-plugin | |
run: gcloud components install gke-gcloud-auth-plugin | |
- name: Enable gke-gcloud-auth-plugin | |
run: echo "USE_GKE_GCLOUD_AUTH_PLUGIN=True" >> $GITHUB_ENV | |
- name: Get GKE credentials | |
run: gcloud container clusters get-credentials $GKE_CLUSTER --zone $GKE_ZONE --project $GKE_PROJECT | |
- name: Configure Docker | |
run: gcloud auth configure-docker | |
# Build the Docker image | |
- name: Build | |
run: |- | |
docker build -t "$REGISTRY_HOSTNAME"/"$GKE_PROJECT"/"$IMAGE":"$IMAGE_TAG" \ | |
--build-arg IMAGE_TAG="$IMAGE_TAG" \ | |
--build-arg GITHUB_REF="$GITHUB_REF" . | |
# Push the Docker image to Google Container Registry | |
- name: Publish | |
run: docker push $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:$IMAGE_TAG | |
bump-version-and-release-charts: | |
needs: setup-build-publish-deploy | |
permissions: | |
contents: write | |
runs-on: ubuntu-latest | |
outputs: | |
new-version: ${{ steps.bump-version.outputs.new-version }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
ref: release | |
- name: Configure Git | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "Sean-creative" | |
- name: Bump chart version | |
id: bump-version | |
run: | | |
CHART_DIR=charts/jsvill-chart | |
VERSION=$(grep 'version:' $CHART_DIR/Chart.yaml | awk '{print $2}') | |
NEW_VERSION=$(echo $VERSION | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g') | |
sed -i "s/version: $VERSION/version: $NEW_VERSION/" $CHART_DIR/Chart.yaml | |
echo "::set-output name=new-version::$NEW_VERSION" | |
git add $CHART_DIR/Chart.yaml | |
git commit -m "Bump chart version to $NEW_VERSION" | |
git push origin HEAD | |
- name: Install Helm | |
uses: azure/setup-helm@v3 | |
- name: Run chart-releaser | |
uses: helm/[email protected] | |
with: | |
charts_dir: charts | |
env: | |
CR_TOKEN: "${{ secrets.CR_TOKEN }}" | |
update-kustomization: | |
needs: bump-version-and-release-charts | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: release | |
- name: Configure Git | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "Sean-creative" | |
- name: Update kustomization version | |
run: | | |
cd kustomize | |
NEW_VERSION=${{ needs.bump-version-and-release-charts.outputs.new-version }} | |
sed -i "/jsvill-charts/,/version:/s/version: .*/version: $NEW_VERSION/" kustomization.yaml | |
git pull origin release | |
git add kustomization.yaml | |
git commit -m "Update jsvill-charts version to $NEW_VERSION" | |
git push origin HEAD |