Update .gitignore #33
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: Deploy to Dev Server | |
on: | |
push: | |
branches: [ "develop" ] | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
environment: Dev | |
env: | |
DEPLOY_DIR: ${{ secrets.DEPLOY_DIR }} | |
AWS_ECR_URI: ${{ secrets.AWS_ECR_URI }} | |
AWS_OIDC_ROLE_ARN: ${{ secrets.AWS_OIDC_ROLE_ARN }} # Github용 OIDC IAM ARN | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }} # S3 버킷 이름 | |
AWS_CODEDEPLOY_APPNAME: ${{ secrets.AWS_CODEDEPLOY_APPNAME }} # CodeDeploy 애플리케이션 이름 | |
AWS_CODEDEPLOY_GROUP: ${{ secrets.AWS_CODEDEPLOY_GROUP }} # CodeDeploy 배포 그룹 이름 | |
NEW_IMAGE_NAME: ${{ secrets.AWS_ECR_URI }}:latest #TODO: 버저닝 추가 | |
SUBMODULE_TOKEN: ${{ secrets.SUBMODULE_TOKEN }} | |
permissions: | |
id-token: write # This is required for requesting the JWT | |
contents: read # This is required for actions/checkout | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup submodule | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ env.SUBMODULE_TOKEN }} | |
submodules: recursive | |
- name: set JDK | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'corretto' | |
java-version: '17' | |
cache: 'gradle' | |
- name: Run chmod to make gradlew executable | |
run: chmod +x gradlew | |
- name: Gradle Build | |
uses: gradle/gradle-build-action@v2 | |
with: | |
arguments: build | |
- name: Docker build | |
run: docker build -t ${{ env.NEW_IMAGE_NAME }} ./ | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v3 | |
with: | |
aws-region: ${{ env.AWS_REGION }} | |
role-session-name: GitHubActions | |
role-to-assume: ${{ env.AWS_OIDC_ROLE_ARN }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Publish Image to ECR | |
run: docker push ${{ env.NEW_IMAGE_NAME }} | |
- name: Copy files for CodeDeploy from submodule | |
run: | | |
cp -r config/* . | |
# Docker compose, ApplicationStart.sh에 새 이미지명 쓰기 | |
- name: Image name replace | |
run: | | |
export ESCAPED_REPLACE=$(echo '${{ env.NEW_IMAGE_NAME }}' | sed -e 's/[\/&\$&\"&]/\\&/g') | |
sed -i 's/_IMAGE_NAME_/'$ESCAPED_REPLACE'/g' docker-compose.yml | |
sed -i 's/_IMAGE_NAME_/'$ESCAPED_REPLACE'/g' codedeploy/scripts/ApplicationStart.sh | |
# 그 외 변수 쓰기 | |
- name: Variable replace | |
run: | | |
export AWS_REGION=$(echo '${{ env.AWS_REGION }}' | sed -e 's/[\/&\$&\"&]/\\&/g') | |
export AWS_ECR_URI=$(echo '${{ env.AWS_ECR_URI }}' | sed -e 's/[\/&\$&\"&]/\\&/g') | |
export DEPLOY_DIR=$(echo '${{ env.DEPLOY_DIR }}' | sed -e 's/[\/&\$&\"&]/\\&/g') | |
sed -i 's/_AWS_REGION_/'$AWS_REGION'/g' codedeploy/scripts/ApplicationStart.sh | |
sed -i 's/_AWS_ECR_URI_/'$AWS_ECR_URI'/g' codedeploy/scripts/ApplicationStart.sh | |
sed -i 's/_DEPLOY_DIR_/'$DEPLOY_DIR'/g' codedeploy/scripts/ApplicationStart.sh | |
sed -i 's/_DEPLOY_DIR_/'$DEPLOY_DIR'/g' appspec.yml | |
# CodeDeploy 배포를 위한 관련 파일 업로드용 디렉토리 생성 | |
- name: Create zip file for AWS CodeDeploy | |
run: mkdir ${{ env.AWS_CODEDEPLOY_APPNAME }} && cp -r appspec.yml docker-compose.yml codedeploy/scripts ${{ env.AWS_CODEDEPLOY_APPNAME }} | |
# AWS S3로 배포 관련 파일 압축 및 업로드 | |
- name: Upload to AWS S3 | |
run: | | |
aws deploy push \ | |
--application-name ${{ env.AWS_CODEDEPLOY_APPNAME }} \ | |
--s3-location s3://${{ env.AWS_S3_BUCKET_NAME }}/codedeploy/$GITHUB_SHA.zip \ | |
--ignore-hidden-files \ | |
--source ${{ env.AWS_CODEDEPLOY_APPNAME }} | |
# AWS EC2 CodeDeploy 배포 요청 | |
- name: Deploy to Dev Server | |
run: | | |
aws deploy create-deployment \ | |
--application-name ${{ env.AWS_CODEDEPLOY_APPNAME }} \ | |
--s3-location bucket=$AWS_S3_BUCKET_NAME,key=codedeploy/$GITHUB_SHA.zip,bundleType=zip \ | |
--deployment-group-name ${{ env.AWS_CODEDEPLOY_GROUP }} \ | |
--deployment-config-name CodeDeployDefault.OneAtATime \ | |
--description "Deploy Dev Server" |