Skip to content

Workflow file for this run

name: Java CI CD with Gradle
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
environment: production
steps:
- name: ✅Checkout branch
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
## create application.yml & application-dev.yml
- name: 🗂️Create application.yml
run: |
cd ./src/main/resources
## application.yml 파일 생성
touch application.yml
echo "${{ secrets.APPLICATION_YML }}" >> application.yml
## application-prod.yml 파일 생성
touch application-prod.yml
echo "${{ secrets.APPLICATION_PROD }}" >> application-prod.yml
shell: bash
## create appspec.yml
- name: 🗂️Create appspec.yml
run: |
touch appspec.yml
echo "{{ secrets.APPSPEC_YML }}" >> appspec.yml
shell: bash
## make scripts
- name: 🗂️Create scripts
run: |
mkdir scripts
touch scripts/start.sh
echo "{{ secrets.START_SH }}" >> scripts/start.sh
shell: bash
## ⚙️빌드
- name: Grant execute permission for gradlew & Build with Gradle
run: |
chmod +x ./gradlew
./gradlew build
shell: bash
## 소스코드 압축
- name: 📦 Zip project files
run: zip -r ./$GITHUB_SHA.zip .
shell: bash
## AWS 인증
- name: 🌎 Access to AWS
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ap-northeast-2
## Zip S3 업로드
- name: 🚛 Upload to S3
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://${{ secrets.S3_BUCKET_NAME }}/${{ secrets.S3_BUCKET_DIR_NAME }}/$GITHUB_SHA.zip
## CodeDeploy 배포 요청
- name: 🚀 Deploy to EC2 with CodeDeploy
run: aws deploy create-deployment
--application-name codedeploy-app
--deployment-config-name CodeDeployDefault.AllAtOnce
--deployment-group-name ${{ secrets.DEPLOYMENT_GROUP_NAME }}
--s3-location bucket=${{ secrets.S3_BUCKET_NAME }},bundleType=zip,key=${{ env.S3_BUCKET_DIR_NAME }}/$GITHUB_SHA.zip