Update README.md #38
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: Tweaver Docker Image CI | |
on: | |
push: | |
branches: [ "master" ] | |
pull_request: | |
branches: [ "master" ] | |
env: | |
REGISTRY: docker.io | |
IMAGE_NAME: ${{ secrets.DOCKERHUB_ID }}/tweaver | |
AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }} # S3 버킷 이름 | |
AWS_CODE_DEPLOY_NAME: valuewith-codedeploy # CodeDeploy 애플리케이션 이름 | |
AWS_CODE_DEPLOY_GROUP: valuewith-codedeploy-group # CodeDeploy 배포 그룹 이름 | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: My First Checkout | |
uses: actions/checkout@v3 | |
# 1. Java 17 세팅: | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# 2. application.yml 파일 생성 | |
- name: make application.yml | |
run: | | |
# application.yml 파일 생성 | |
# GitHub-Actions 에서 설정한 값을 application.yml 파일에 쓰기 | |
cd ./src/main/resources | |
touch ./application.yml | |
echo "${{ secrets.APPLICATION_PROD }}" >> ./application.yml | |
shell: bash | |
# 3. Gradle Build를 위한 권한 부여 | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
# 4. Tweaver 빌드하기 | |
- name: Build with Gradle | |
run: ./gradlew clean build --exclude-task test | |
# 5. Docker image 빌드하기 | |
- uses: actions/checkout@v3 | |
- name: Build the Docker image | |
run: docker build . --file Dockerfile --tag ${{ env.IMAGE_NAME }}:${{ secrets.MAJOR }}.${{ secrets.MINOR }} | |
# 6. Docker 로그인 하기 | |
- name: Docker login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_ID }} | |
password: ${{ secrets.DOCKERHUB_PW }} | |
# 7. Docker 푸시하기 | |
- name: docker Hub push | |
run: docker push ${{ env.IMAGE_NAME }}:${{ secrets.MAJOR }}.${{ secrets.MINOR }} | |
##### 배포 | |
# 8. Docker 이미지 이름을 image.txt 파일에 쓰기 | |
- name: Write Docker image name to txt file | |
run: echo "${{ env.IMAGE_NAME }}:${{ secrets.MAJOR }}.${{ secrets.MINOR }}" > image.txt | |
# 9. CodeDeploy 배포를 위한 관련 파일 압축 | |
- name: Create zip file for AWS CodeDeploy | |
run: mkdir ${{ env.AWS_CODE_DEPLOY_NAME }} && cp -r appspec.yml image.txt scripts ${{ env.AWS_CODE_DEPLOY_NAME }} | |
# 10. AWS 설정 | |
- name: AWS Configure | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.IAM_ACCESS }} | |
aws-secret-access-key: ${{ secrets.IAM_SECRET_ACCESS }} | |
aws-region: ap-northeast-2 | |
# 11. AWS S3로 배포 파일 업로드 | |
- name: Upload to AWS S3 | |
run: | | |
aws deploy push \ | |
--application-name ${{ env.AWS_CODE_DEPLOY_NAME }} \ | |
--s3-location s3://${{ env.AWS_S3_BUCKET_NAME }}/codedeploy/$GITHUB_SHA.zip \ | |
--ignore-hidden-files \ | |
--source ${{ env.AWS_CODE_DEPLOY_NAME }} | |
# 12. AWS EC2 CodeDeploy 배포 요청 | |
- name: Delpoy to AWS EC2 | |
run: | | |
aws deploy create-deployment \ | |
--application-name ${{ env.AWS_CODE_DEPLOY_NAME }} \ | |
--deployment-config-name CodeDeployDefault.OneAtATime \ | |
--deployment-group-name ${{ env.AWS_CODE_DEPLOY_GROUP }} \ | |
--description "Deploy artscope" \ | |
--s3-location bucket=$AWS_S3_BUCKET_NAME,key=codedeploy/$GITHUB_SHA.zip,bundleType=zip | |
# 13. 자동 버전 관리 | |
- name: Autoincrement a new minor version | |
run: | | |
echo "NEW_MINOR_VERSION=$((${{ secrets.MINOR }}+1))" >> $GITHUB_ENV | |
# 14. 마이너 버전 업데이트 | |
- name: Update Minor version | |
uses: hmanzur/actions-set-secret@v2.0.0 | |
with: | |
name: 'MINOR' | |
value: ${{ env.NEW_MINOR_VERSION }} | |
repository: ${{ secrets.REPO }} | |
token: ${{ secrets.REPO_ACCESS_TOKEN }} |