Workflow file for this run
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
name: Deploy to KC Container Registry and Update K8S Manifest | |
on: | |
release: | |
types: [ published ] | |
permissions: | |
contents: read | |
jobs: | |
build-docker-image: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Set Secret yml file. | |
run: | | |
touch ./src/main/resources/secret.yml | |
echo "${{ secrets.SECRETYML }}" > ./src/main/resources/secret.yml | |
cat ./src/main/resources/secret.yml | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
shell: bash | |
- name: Build with Gradle | |
run: ./gradlew bootJar | |
shell: bash | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to KakaoCloud Container Registry | |
run: docker login ${{ secrets.KC_REGISTRY_URL }} --username ${{ secrets.KC_ACCESS_KEY_ID }} --password ${{ secrets.KC_SECRET_KEY }} | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
platforms: linux/amd64 | |
tags: ${{ secrets.KC_REGISTRY_URL }}/${{ secrets.IMAGE_NAME }}:${{ github.event.release.tag_name }}, ${{ secrets.KC_REGISTRY_URL }}/${{ secrets.IMAGE_NAME }}:latest | |
update-k8s: | |
needs: build-docker-image | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
repository: kea-dpang/k8s-manifast | |
token: ${{ secrets.GIT_TOKEN }} | |
- name: Extract repository name | |
id: repo-name | |
run: echo "REPO_NAME=$(echo ${{ github.repository }} | cut -d'/' -f2)" >> $GITHUB_ENV | |
- name: Extract directory name | |
id: directory-name | |
run: echo "DIRECTORY_NAME=$(echo ${{ secrets.IMAGE_NAME }} | cut -d'/' -f2)" >> $GITHUB_ENV | |
- name: Update image version | |
run: sed -i 's|${{ secrets.KC_REGISTRY_URL }}/${{ secrets.IMAGE_NAME }}.*|${{ secrets.KC_REGISTRY_URL }}/${{ secrets.IMAGE_NAME }}:${{ github.event.release.tag_name }}|' ./backend/${{ env.DIRECTORY_NAME }}/${{ env.REPO_NAME }}-deployment.yaml | |
- name: Commit and push changes | |
run: | | |
git config --global user.name ${{ secrets.GIT_USER_NAME }} | |
git config --global user.email ${{ secrets.GIT_USER_EMAIL }} | |
git add ./backend/${{ env.DIRECTORY_NAME }}/${{ env.REPO_NAME }}-deployment.yaml | |
git commit -m "update: 이미지 버전 수정 ${{ secrets.IMAGE_NAME }} v${{ github.event.release.tag_name }} by Git Action" | |
git push |