Skip to content

Chore: 과릿 1.1.10 (#359) #48

Chore: 과릿 1.1.10 (#359)

Chore: 과릿 1.1.10 (#359) #48

Workflow file for this run

name: Beanstalk Deploy
on:
push:
branches:
- release
jobs:
build:
# ubuntu 버전 지정
runs-on: ubuntu-22.04
steps:
# Checkout 진행
- uses: actions/checkout@v3
# JDK 11 설치
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
# Gradle 캐싱
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# Gradle 권한 부여
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# secret.yml 반영
- name: Make application-secret.yml
run: |
cd ./src/main/resources
touch ./application-secret.yml
echo "${{ secrets.APPLICATION_SECRET}}" > ./application-secret.yml
shell: bash
# release.yml 반영
- name: Make application-release.yml
run: |
cd ./src/main/resources
echo "${{ secrets.GCP_APPLICATION_RELEASE}}" > ./application-release.yml
shell: bash
# Gradle BootJar
- name: BootJar with Gradle
run: ./gradlew clean bootJar -Dspring.profiles.active=release
# Docker Image Push
- name: Docker Image push
run: |
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
docker build -t ${{ secrets.DOCKERHUB_USERNAME}}/${{ secrets.DOCKERHUB_REPOSITORY}} ./
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY}}
# Docker Compose
- name: Docker Compose
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.GCP_SERVER_IP }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
envs: GITHUB_SHA
script: |
sudo docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
sudo docker-compose stop ${{ secrets.DOCKER_SERVICE_NAME }}
sudo docker-compose rm -f ${{ secrets.DOCKER_SERVICE_NAME }}
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY}}
sudo docker tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY}} ${{ secrets.DOCKER_IMAGE_NAME }}
sudo docker-compose up -d
#name: Beanstalk Deploy
#
#on:
# push:
# branches:
# - release
#
#jobs:
# build:
# # ubuntu 버전 지정
# runs-on: ubuntu-22.04
# steps:
# # Checkout 진행
# - uses: actions/checkout@v3
#
# # JDK 11 설치
# - name: Set up JDK 11
# uses: actions/setup-java@v3
# with:
# java-version: '11'
# distribution: 'temurin'
#
# # Gradle 캐싱
# - name: Gradle Caching
# uses: actions/cache@v3
# with:
# path: |
# ~/.gradle/caches
# ~/.gradle/wrapper
# key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
# restore-keys: |
# ${{ runner.os }}-gradle-
#
# # Gradle 권한 부여
# - name: Grant execute permission for gradlew
# run: chmod +x gradlew
#
# # secret.yml 반영
# - name: Make application-secret.yml
# run: |
# cd ./src/main/resources
# touch ./application-secret.yml
# echo "${{ secrets.APPLICATION_SECRET}}" > ./application-secret.yml
# shell: bash
#
# # release.yml 반영
# - name: Make application-release.yml
# run: |
# cd ./src/main/resources
# echo "${{ secrets.APPLICATION_RELEASE}}" > ./application-release.yml
# shell: bash
#
#
## # makeFiles.config 반영
## - name: Make 00-makeFiles.config
## run: |
## cd ./.ebextensions
## touch ./00-makeFiles.config
## echo "${{ secrets.RELEASE_MAKEFILES}}" > ./00-makeFiles.config
## shell: bash
#
# # Gradle BootJar
# - name: BootJar with Gradle
# run: ./gradlew clean bootJar -Dspring.profiles.active=release
#
# # 현재 시간 반영
# - name: Get current time
# uses: 1466587594/get-current-time@v2
# id: current-time
# with:
# format: YYYY-MM-DDTHH-mm-ss
# utcOffset: "+09:00"
#
# # grandle build를 통해 만들어진 jar를 beanstalk에 배포하기 위한 zip 파일로 만드는 것
# - name: Generate deployment package
# run: |
# mkdir -p deploy
# cp build/libs/*.jar deploy/application.jar
# cp Procfile deploy/Procfile
# cp -r .ebextensions deploy/.ebextensions
# cp -r .platform deploy/.platform
# cd deploy && zip -r deploy.zip .
#
# # Beanstalk Deploy 플러그인 사용
# - name: Beanstalk Deploy
# uses: einaregilsson/beanstalk-deploy@v14
# with:
# aws_access_key: ${{ secrets.AWS_ACCESS_KEY }} # github secrets로 등록한 값 사용
# aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} # github secrets로 등록한 값 사용
# application_name: Gwalit-release # EB application 이름
# environment_name: Gwalit-release-env # EB environment 이름
# version_label: Github Action-${{steps.current-time.outputs.formattedTime}} # 배포 버전은 타임스탬프를 이용하여 구분
# region: ap-northeast-2
# deployment_package: deploy/deploy.zip
# wait_for_environment_recovery: 100 # default wait time은 30초이며, 필자의 EB가 느려서 180초로 지정했습니다(지정 안하면 간혹 timeout 발생).