Skip to content

Commit

Permalink
spring session+redis 도입 4 .. #13
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean-creative committed Feb 25, 2024
1 parent 3ebea84 commit 4f7b784
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 1,644 deletions.
12 changes: 1 addition & 11 deletions .github/workflows/gkeWithArgoCD.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
# This workflow will build a docker container, publish it to Google Container Registry, and deploy it to GKE when there is a push to the "main" branch.
#
# To configure this workflow:
#
# 1. Ensure that your repository contains the necessary configuration for your Google Kubernetes Engine cluster, including deployment.yml, kustomization.yml, service.yml, etc.
# 2. Create and configure a Workload Identity Provider for GitHub (https://github.com/google-github-actions/auth#setting-up-workload-identity-federation)
#
# 3. Change the values for the GAR_LOCATION, GKE_ZONE, GKE_CLUSTER, IMAGE, REPOSITORY and DEPLOYMENT_NAME environment variables (below).
#
# For more support on how to run the workflow, please visit https://github.com/google-github-actions/setup-gcloud/tree/master/example-workflows/gke-kustomize

#기존 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
- release2

env:
GKE_PROJECT: ${{ secrets.GKE_PROJECT }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-charts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release Charts
on:
push:
branches:
- release
- release2
paths:
- 'charts/**'
- 'kustomize/**'
Expand Down
148 changes: 148 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@

#기존 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

- name: JDK 16 설치
uses: actions/setup-java@v3
with:
java-version: '16'
distribution: 'corretto'

- name: application.properties 파일 생성
run: touch ./src/main/resources/application.properties
- name: application.properties에 작성
run: echo "${{ secrets.APPLICATION }}" > ./src/main/resources/application.properties
- name: application.properties 내용 표시
run: cat ./src/main/resources/application.properties

- 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.release.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
30 changes: 30 additions & 0 deletions charts/jsvill-chart/templates/sessionRedis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: session-redis
spec:
replicas: 1
selector:
matchLabels:
app: session-redis
template:
metadata:
labels:
app: session-redis
spec:
containers:
- name: session-redis
image: redis:alpine
ports:
- containerPort: 6379
---
apiVersion: v1
kind: Service
metadata:
name: session-redis
spec:
ports:
- port: 6379
targetPort: 6379
selector:
app: session-redis
Loading

0 comments on commit 4f7b784

Please sign in to comment.