Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean-creative committed Dec 31, 2023
1 parent 81f8cd7 commit 0aeb10f
Showing 1 changed file with 36 additions and 25 deletions.
61 changes: 36 additions & 25 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,47 @@
name: jsvill CICD
run-name: Running
on:
push:
branches:
- main


env:
AWS_REGION: ap-northeast-2
AWS_S3_BUCKET: cicd-sean-bucket
AWS_CODE_DEPLOY_APPLICATION: cicd-test-cd
AWS_CODE_DEPLOY_GROUP: cicd-test-cd-group

#job의 3분할
#환경 설정(Job: setup-environment): JDK 설치, AWS Credential 설정 등 환경 설정 관련 단계를 모두 포함합니다.
#빌드(Job: build): 코드 체크아웃, 프로젝트 빌드 등 실제 애플리케이션 빌드를 처리합니다.
#배포(Job: deploy): 빌드된 애플리케이션을 AWS S3에 업로드하고 EC2에 배포합니다.

jobs:
build-with-gradle:
setup-environment:
runs-on: ubuntu-22.04
steps:
- name: checkout
uses: actions/checkout@v3

- name: JDK 16 설치
uses: actions/setup-java@v3
with:
java-version: '16'
distribution: 'corretto'
- name: AWS credential 설정
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: ${{ env.AWS_REGION }}
aws-access-key-id: ${{ secrets.CICD_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.CICD_SECRET_KEY }}

build:
needs: setup-environment
runs-on: ubuntu-22.04
steps:
- name: application.properties 파일 생성
run: touch ./src/main/resources/application.properties
run: |
# mkdir -p ./src/main/resources/ # 디렉토리가 없을 경우를 대비하여 생성
cd ./src/main/resources/
touch ./src/main/resources/application.properties
- name: application.properties에 작성
run: echo "${{ secrets.APPLICATION }}" > ./src/main/resources/application.properties
- name: application.properties 내용 표시
Expand All @@ -37,25 +52,21 @@ jobs:
- name: 프로젝트 빌드
run: ./gradlew clean build -x test

- name: AWS credential 설정
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: ${{ env.AWS_REGION }}
aws-access-key-id: ${{ secrets.CICD_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.CICD_SECRET_KEY }}

deploy:
needs: build
runs-on: ubuntu-22.04
steps:
- name: S3에 업로드
run:
aws deploy push
--application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }}
--ignore-hidden-files
--s3-location s3://$AWS_S3_BUCKET/cicdtest/$GITHUB_SHA.zip
--source .

run: |
aws deploy push
--application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }}
--ignore-hidden-files
--s3-location s3://$AWS_S3_BUCKET/cicdtest/$GITHUB_SHA.zip
--source .
- name: EC2에 배포
run:
aws deploy create-deployment
--application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }}
--deployment-config-name CodeDeployDefault.AllAtOnce
--deployment-group-name ${{ env.AWS_CODE_DEPLOY_GROUP }}
--s3-location bucket=$AWS_S3_BUCKET,key=cicdtest/$GITHUB_SHA.zip,bundleType=zip
run: |
aws deploy create-deployment
--application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }}
--deployment-config-name CodeDeployDefault.AllAtOnce
--deployment-group-name ${{ env.AWS_CODE_DEPLOY_GROUP }}
--s3-location bucket=$AWS_S3_BUCKET,key=cicdtest/$GITHUB_SHA.zip,bundleType=zip

0 comments on commit 0aeb10f

Please sign in to comment.