Skip to content

Merge pull request #25 from WonderWoman-Team/scroll/xloyeon #30

Merge pull request #25 from WonderWoman-Team/scroll/xloyeon

Merge pull request #25 from WonderWoman-Team/scroll/xloyeon #30

Workflow file for this run

# This is a basic workflow to help you get started with Actions
name: Java CI with Gradle & Deploy to EC2
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "master" branch
push:
branches: [ "master" ]
pull_request:
types: closed
branches: [ "master" ]
env:
AWS_REGION: ap-northeast-2
S3_BUCKET_NAME: wonder-github-actions-s3-bucket
CODE_DEPLOY_APPLICATION_NAME: wonder-codedeploy-app
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: wonder-codedeploy-deployment-group
permissions:
contents: read
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
deploy:
# The type of runner that the job will run on
name: Deploy
runs-on: ubuntu-latest
environment: production
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
# 1) 기본 체크아웃
- name: Checkout
uses: actions/checkout@v3
# Runs a single command using the runners shell
# 2) JDK 17 세팅
# Runs a single command using the runners shell
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- run: mkdir -p ./src/main/resources
- run: touch ./src/main/resources/application.properties
- run: echo "${{ secrets.APPLICATION }}" > ./src/main/resources/application.properties
- run: cat ./src/main/resources/application.properties
# 3) gradlew 권한 설정
- name: Grant execute permission for gradlew
run: chmod +x gradlew
working-directory: ${{ env.working-directory }}
# 4) gradlew 빌드
- name: Build with Gradle
uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee
with:
arguments: clean build -x test
# 5) AWS 인증
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
# AWS S3에 업로드
- name: Upload to AWS S3
run: |
aws deploy push \
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \
--ignore-hidden-files \
--s3-location s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip \
--source .
# AWS EC2에 deploy
- name: Deploy to AWS EC2 from S3
run: |
aws deploy create-deployment \
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--deployment-group-name ${{ env.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \
--s3-location bucket=$S3_BUCKET_NAME,key=$GITHUB_SHA.zip,bundleType=zip