Skip to content

update: 환경별 ECR 변수 신규 생성 및 적용 테스트 #35

update: 환경별 ECR 변수 신규 생성 및 적용 테스트

update: 환경별 ECR 변수 신규 생성 및 적용 테스트 #35

Workflow file for this run

name: Java CI with Gradle
on:
push:
branches: [ "main", "dev", "refactor-jdb-gitaction-workflow" ]
env:
AWS_REGION: ${{ secrets.AWS_REGION }}
OIDC_ROLE_ARN: ${{ secrets.OIDC_ROLE }}
DEPLOY_ENV: ${{ github.ref == 'refs/heads/main' && 'PROD' || 'DEV' }}
GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }}
ECR_URL: ${{ secrets.AWS_ECR_DEV_CORE }}
AWS_DEV_CORE_ECR: ${{ secrets.AWS_DEV_CORE_ECR }}
AWS_PRD_CORE_ECR: ${{ secrets.AWS_PRD_CORE_ECR }}
webhook_url: ${{ secrets.WEBHOOK }}
permissions:
id-token: write
contents: write
jobs:
build:
name: Build
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v3
- 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 core-service .
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: ${{ env.AWS_REGION }}
role-session-name: GitHubActions
role-to-assume: ${{ env.OIDC_ROLE_ARN }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Publish Image to ECR(CORE-SERVICE)
run: |
if [ "${{ env.DEPLOY_ENV }}" == "PROD" ]; then
docker tag core-service:latest ${{ env.AWS_PRD_CORE_ECR }}:${{ github.sha }}
docker push ${{ env.AWS_PRD_CORE_ECR }}:${{ github.sha }}
else
docker tag core-service:latest ${{ env.AWS_DEV_CORE_ECR }}:${{ github.sha }}
docker push ${{ env.AWS_DEV_CORE_ECR }}:${{ github.sha }}
fi
# - name: notification to swit
# uses: roharon/action-swit@v1
# with:
# webhooks_url: ${{ env.webhook_url }}
# MESSAGE: "🏷 ${{ job.status }} 백엔드 ECR 도커파일 업로드 : Core-service - by ${{ github.actor }}"
- name: Setup Kustomize
uses: imranismail/setup-kustomize@v1
- name: Checkout for Kustomize repository
uses: actions/checkout@v2
with:
repository: Project-Catcher/core-service-kusto
ref: main
token: ${{ env.GITHUB_TOKEN }}
path: core-service-kusto
- name: Update Kustomize image
run: |
if [ "${{ env.DEPLOY_ENV }}" == "PROD" ]; then
KUSTOMIZE_PATH="core-service-kusto/overlays/prd" && cd $KUSTOMIZE_PATH
kustomize edit set image app-core-img="${{ env.AWS_PRD_CORE_ECR }}:${{ github.sha }}"
else
KUSTOMIZE_PATH="core-service-kusto/overlays/dev" && cd $KUSTOMIZE_PATH
kustomize edit set image app-core-img="${{ env.AWS_DEV_CORE_ECR }}:${{ github.sha }}"
fi
kustomize build .
- name: Commit minifest files
run: |
cd core-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-core \
--server argocd.dev-alltimecatcher.com \
--auth-token ${{ secrets.ARGOCD_TOKEN }} --insecure