Skip to content

Merge remote-tracking branch 'origin/release' into release #14

Merge remote-tracking branch 'origin/release' into release

Merge remote-tracking branch 'origin/release' into release #14

Workflow file for this run

#두개를 하나로 합쳐서 빌드 후 차트 배포까지 하는중
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: ${{ secrets.GKE_ZONE }}
GKE_CLUSTER: ${{ secrets.GKE_CLUSTER }}
REGISTRY_HOSTNAME: gcr.io
IMAGE: jsvill-fullstack
IMAGE_TAG: latest
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 }}" | base64 -d > ./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=$(awk '/^version: /{print $2}' $CHART_DIR/Chart.yaml)
NEW_VERSION=$(echo $VERSION | awk -F. '{++$NF}1' | tr ' ' '.')
echo "Current VERSION: $VERSION"
echo "New VERSION: $NEW_VERSION"
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 }}"