Skip to content

Merge pull request #56 from Project-Catcher/refactor-jdb-gitaction-wo… #23

Merge pull request #56 from Project-Catcher/refactor-jdb-gitaction-wo…

Merge pull request #56 from Project-Catcher/refactor-jdb-gitaction-wo… #23

Workflow file for this run

name: Java CI with Gradle
on:
push:
branches: [ "main", "dev" ]
env:
AWS_DEV_BATCH_ECR: ${{ secrets.AWS_DEV_BATCH_ECR }}
AWS_PRD_BATCH_ECR: ${{ secrets.AWS_PRD_BATCH_ECR }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
AWS_REGION: ${{ secrets.AWS_REGION }}
WEBHOOK_URL: ${{ secrets.WEBHOOK }}
DEPLOY_ENV: ${{ github.ref == 'refs/heads/main' && 'PROD' || 'DEV' }}
permissions:
id-token: write
contents: write
jobs:
build:
name: Build
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: 'gradle'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew bootJar
- name: Docker build
run: docker build -t batch-service .
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: ${{ env.AWS_REGION }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Publish Image to ECR(BATCH-SERVICE)
run: |
echo ${{ github.sha }}
if [ "${{ env.DEPLOY_ENV }}" == "PROD" ]; then
docker tag batch-service:latest ${{ env.AWS_PRD_BATCH_ECR }}:${{ github.sha }}
docker push ${{ env.AWS_PRD_BATCH_ECR }}:${{ github.sha }}
else
docker tag batch-service:latest ${{ env.AWS_DEV_BATCH_ECR }}:${{ github.sha }}
docker push ${{ env.AWS_DEV_BATCH_ECR }}:${{ github.sha }}
fi
- name: Send Notification
if: ${{ always() }}
run: |
if [[ ${{ job.status }} == "success" ]]; then
MESSAGE="✅ ${{ job.status }} 백엔드 ECR 도커파일 업로드 성공: batch-service - by ${{ github.actor }}"
else
MESSAGE="❌ ${{ job.status }} 백엔드 ECR 도커파일 업로드 실패: batch-service - by ${{ github.actor }}"
fi
curl -X POST -H "Content-Type: application/json" --data "{\"text\":\"${MESSAGE}\"}" ${{ env.WEBHOOK_URL }}
- name: Setup Kustomize
uses: imranismail/setup-kustomize@v1
- name: Checkout for Kustomize repository
uses: actions/checkout@v2
with:
repository: Project-Catcher/batch-service-kusto
ref: main
token: ${{ env.GIT_TOKEN }}
path: batch-service-kusto
- name: Update Kustomize image
run: |
echo ${{ github.sha }}
if [ "${{ env.DEPLOY_ENV }}" == "PROD" ]; then
KUSTOMIZE_PATH="batch-service-kusto/overlays/prd" && cd $KUSTOMIZE_PATH
kustomize edit set image app-batch-img="${{ env.AWS_PRD_BATCH_ECR }}:${{ github.sha }}"
else
KUSTOMIZE_PATH="batch-service-kusto/overlays/dev" && cd $KUSTOMIZE_PATH
kustomize edit set image app-batch-img="${{ env.AWS_DEV_BATCH_ECR }}:${{ github.sha }}"
fi
kustomize build .
- name: Commit minifest files
run: |
cd batch-service-kusto
git config --global user.email "[email protected]"
git config --global user.name "github-actions"
git commit -am "Update image tag"
git push -u origin main
- name: Sync ArgoCD Application
run: |
argocd app sync dev-app-batch \
--server argocd.dev-alltimecatcher.com \
--auth-token ${{ secrets.ARGOCD_TOKEN }} --insecure