[PoC] Gradle Version Catalog 사용해보기 (#429) #427
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: dev-ci-cd | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: # for manual trigger | |
permissions: | |
id-token: write | |
jobs: | |
backend-ci: | |
runs-on: ubuntu-latest | |
services: | |
postgresql: | |
image: postgis/postgis:14-3.4-alpine | |
ports: | |
- 15432:5432 | |
env: | |
POSTGRES_USER: test | |
POSTGRES_PASSWORD: test | |
POSTGRES_DB: scc_test | |
defaults: | |
run: | |
working-directory: app-server | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup Java | |
uses: actions/setup-java@v3 | |
with: | |
distribution: adopt | |
java-version: 19 | |
- name: Setup Gradle | |
uses: gradle/gradle-build-action@v2 | |
# https://github.com/actions/cache/blob/main/examples.md#java---gradle | |
- uses: actions/cache@v3 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Gradle Check | |
run: ./gradlew clean check | |
- uses: actions/upload-artifact@v3 | |
name: Upload Check Report If Failed | |
if: failure() | |
with: | |
name: test report | |
path: "**/build/reports" | |
retention-days: 1 | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
role-to-assume: arn:aws:iam::291889421067:role/github-action-ci-cd | |
aws-region: ap-northeast-2 | |
- name: Build and Push Docker Image | |
run: ./gradlew jib -Pversion=latest-rc | |
- name: Notify CI failure to slack | |
if: failure() | |
run: | | |
CURRENT_GITHUB_ACTION_RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
curl -X POST -H 'Content-type: application/json' --data "{\"attachments\":[{\"color\":\"#FF0000\",\"title\":\"[DEV] Backend CI Failed\", \"text\":\"<!subteam^S052B9W7129> (<$CURRENT_GITHUB_ACTION_RUN_URL|github action run url>)\"}]}" ${{ secrets.SLACK_URL_SCC_SERVER_CHANNEL }} -v | |
cd: | |
runs-on: ubuntu-latest | |
needs: | |
- backend-ci | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Notify CD start to slack | |
run: | | |
curl -X POST -H 'Content-type: application/json' --data "{\"attachments\":[{\"color\":\"#46AE74\",\"title\":\"[DEV] Scc-Server Deploy Started\", \"text\":\"version - latest\"}]}" ${{ secrets.SLACK_URL_SCC_SERVER_CHANNEL }} -v | |
- name: Install kubeconfig | |
env: | |
SCC_K3S_KUBECONFIG: ${{ secrets.SCC_K3S_KUBECONFIG }} | |
run: | | |
mkdir -p ~/.kube && echo "$SCC_K3S_KUBECONFIG" > ~/.kube/config | |
- uses: azure/setup-helm@v1 | |
with: | |
version: '3.8.2' | |
id: install-helm | |
- uses: azure/setup-kubectl@v3 | |
with: | |
version: 'v1.24.1' | |
id: install-kubectl | |
- name: Upgrade scc-server helm chart | |
working-directory: infra/helm/scc-server | |
run: | | |
helm upgrade --install --namespace dev -f values-dev.yaml scc-server ./ | |
- name: Restart deploy/scc-server # tag를 latest-rc로 고정해서 사용하기 때문에 helm upgrade --install만 해서는 새 버전의 이미지가 배포되지 않는다. 따라서 강제로 rollout을 해준다. | |
run: | | |
kubectl rollout restart deploy/scc-server -n dev | |
- name: Wait for scc-server rollout | |
timeout-minutes: 10 | |
run: | | |
kubectl rollout status deployment scc-server -n dev | |
- name: Notify CD failure to slack | |
if: failure() | |
run: | | |
CURRENT_GITHUB_ACTION_RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
curl -X POST -H 'Content-type: application/json' --data "{\"attachments\":[{\"color\":\"#FF0000\",\"title\":\"[DEV] Scc-Server Deployment Failed\", \"text\":\"<!subteam^S052B9W7129> (<$CURRENT_GITHUB_ACTION_RUN_URL|github action run url>)\"}]}" ${{ secrets.SLACK_URL_SCC_SERVER_CHANNEL }} -v | |
- name: Notify CD success to slack | |
if: success() | |
run: | | |
CURRENT_GITHUB_ACTION_RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
curl -X POST -H 'Content-type: application/json' --data "{\"attachments\":[{\"color\":\"#0000FF\",\"title\":\"[DEV] Scc-Server Deploy Success\"}]}" ${{ secrets.SLACK_URL_SCC_SERVER_CHANNEL }} -v |