github action #2
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: Java CI with Gradle | |
on: | |
push: | |
branches: [ "main" ] | |
env: | |
ECR_URL: ${{ secrets.ECR_REPO_DEV }} | |
ROLE_ARN: ${{ secrets.OIDC_ROLE }} | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
WEBHOOK_URL: ${{ secrets.WEBHOOK }} | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write # This is required for requesting the JWT | |
contents: read # This is required for actions/checkout | |
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 }} | |
role-session-name: GitHubActions | |
role-to-assume: ${{ env.ROLE_ARN }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Publish Image to ECR(BATCH-SERVICE) | |
run: | | |
docker tag batch-service:latest ${{ env.ECR_URL }}:batch-service | |
docker push ${{ env.ECR_URL }}:batch-service | |
- 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 }} | |