[feat] DB I/O 및 응답 속도 개선을 위한 캐싱을 적용한다 (#28) #50
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: Backend CD | |
on: | |
push: | |
branches: | |
- main | |
env: | |
SUBMODULE_TOKEN: ${{ secrets.SUBMODULE_TOKEN }} | |
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }} | |
AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }} | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
ZIP_FILE: spring-build-${{ github.run_number }}.zip | |
S3_BUCKET: ${{ secrets.S3_BUCKET }} | |
S3_DEPLOY_RESOURCE_FOLDER: ${{ secrets.S3_DEPLOY_RESOURCE_FOLDER }} | |
AWS_DEPLOY_APP_NAME: ${{ secrets.AWS_DEPLOY_APP_NAME }} | |
AWS_DEPLOY_GROUP: ${{ secrets.AWS_DEPLOY_GROUP }} | |
AWS_DEPLOY_CONFIG: ${{ secrets.AWS_DEPLOY_CONFIG }} | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }} | |
DOCKER_IMAGE_NAME: sjiwon/study-with-me-be | |
DOCKER_IMAGE_TAG: ${{ github.run_number }} | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Repository를 가져온다 | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ env.SUBMODULE_TOKEN }} | |
submodules: true | |
- name: JDK 17을 설정한다 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
java-version: 17 | |
- name: Gradle 정보를 캐싱한다 | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Timezone을 Asia/Seoul로 설정한다 | |
uses: zcong1993/setup-timezone@master | |
with: | |
timezone: Asia/Seoul | |
- name: Gradle 명령 실행을 위한 권한을 부여한다 | |
run: chmod +x gradlew | |
- name: Gradle build를 수행한다 | |
run: ./gradlew bootJar | |
- name: Docker에 로그인한다 | |
uses: docker/#-action@v3 | |
with: | |
username: ${{ env.DOCKER_USERNAME }} | |
password: ${{ env.DOCKER_PASSWORD }} | |
- name: Docker Image를 빌드하고 DockerHub에 Push한다 | |
run: | | |
docker build -t ${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_IMAGE_TAG }} . | |
docker push ${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_IMAGE_TAG }} | |
echo "${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_IMAGE_TAG }}" > DockerImage.txt | |
- name: S3에 보낼 Resource Zip File을 생성한다 | |
run: | | |
mkdir -p deploy | |
cp ./DockerImage.txt ./deploy/ | |
cp ./appspec.yml ./deploy/ | |
cp ./Dockerfile ./deploy/ | |
cp ./scripts/*.sh ./deploy/ | |
cp ./build/libs/*.jar ./deploy/ | |
zip -r -qq -j ./${{ env.ZIP_FILE }} ./deploy | |
- name: AWS 인증을 진행한다 | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ env.AWS_ACCESS_KEY }} | |
aws-secret-access-key: ${{ env.AWS_SECRET_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Resource Zip File을 S3로 전송한다 | |
run: | | |
aws s3 cp \ | |
--region ${{ env.AWS_REGION }} \ | |
./${{ env.ZIP_FILE }} s3://${{ env.S3_BUCKET }}/${{ env.S3_DEPLOY_RESOURCE_FOLDER }}/${{ env.ZIP_FILE }} | |
- name: AWS CodeDeploy를 통한 배포를 진행한다 | |
id: deploy | |
run: | | |
aws deploy create-deployment \ | |
--application-name ${{ env.AWS_DEPLOY_APP_NAME }} \ | |
--deployment-group-name ${{ env.AWS_DEPLOY_GROUP }} \ | |
--deployment-config-name ${{ env.AWS_DEPLOY_CONFIG }} \ | |
--s3-location bucket=${{ env.S3_BUCKET }},bundleType=zip,key=${{ env.S3_DEPLOY_RESOURCE_FOLDER }}/${{ env.ZIP_FILE }} |