Running #324
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: CICD | |
run-name: Running | |
on: | |
push: | |
branches: | |
- deploy | |
pull_request: | |
branches: | |
- deploy | |
env: | |
AWS_REGION: ap-northeast-2 | |
AWS_S3_BUCKET: app-release-files | |
AWS_CODE_BUCKET_NAME: funding-cicd | |
AWS_CODE_DEPLOY_APPLICATION: funding-cd | |
AWS_CODE_DEPLOY_GROUP: funding-publish | |
DOCKER_HUB_REPOSITORY: yeachan05/application | |
jobs: | |
build-with-gradle: | |
runs-on: ubuntu-20.04 # ubuntu ver | |
steps: | |
- name: deploy 브랜치로 이동 | |
uses: actions/checkout@v3 | |
with: | |
ref: deploy | |
- name: JDK 17 설치 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'corretto' | |
- name: gradlew에 실행 권한 부여 | |
run: chmod +x ./gradlew | |
- name: 설정파일 디코딩 및 저장 | |
run: | | |
mkdir -p src/main/resources | |
echo "${{ secrets.APPLICATION_YML }}" | base64 --decode > src/main/resources/application-prod.yml | |
find src | |
- name: 프로젝트 빌드 | |
run: ./gradlew build -x test | |
- name: Docker 이미지 빌드 | |
run: docker build -t ${{ env.DOCKER_HUB_REPOSITORY }}:latest . | |
- name: Docker Hub 로그인 | |
run: echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_HUB_USERNAME }}" --password-stdin | |
- name: Docker 이미지 푸시 | |
run: docker push ${{ env.DOCKER_HUB_REPOSITORY }}:latest | |
- 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 }} | |
- name: S3에 업로드 | |
run: | | |
aws deploy push \ | |
--application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }} \ | |
--ignore-hidden-files \ | |
--s3-location s3://${{ env.AWS_CODE_BUCKET_NAME }}/cicdDir/$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=${{ env.AWS_CODE_BUCKET_NAME }},key=cicdDir/$GITHUB_SHA.zip,bundleType=zip |