Skip to content

Chore: AWS EC2 Deploy Test (#428) #61

Chore: AWS EC2 Deploy Test (#428)

Chore: AWS EC2 Deploy Test (#428) #61

Workflow file for this run

name: Deploy release version
on:
push:
branches:
- release
env:
AWS_REGION: ap-northeast-2
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
GITHUB_SHA: ${{ github.sha }}
jobs:
build:
# ubuntu 버전 지정
runs-on: ubuntu-22.04
steps:
# Checkout 진행

Check failure on line 18 in .github/workflows/release-CD.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/release-CD.yml

Invalid workflow file

You have an error in your yaml syntax on line 18
- 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
# Gradle BootJar
- name: BootJar with Gradle
run: ./gradlew clean bootJar -Dspring.profiles.active=release
# Configure AWS Credentials by using IAM inform
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} # 나의 ECR 정보
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
# Login to ECR
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
# Docker Image Push to ECR and Run container with Image pull from ECR
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ env.GITHUB_SHA }}
run: |
# Build a docker container and push it to ECR so that it can be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
# Docker Compose
}
- name: Docker Compose
uses: appleboy/ssh-action@master
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ env.GITHUB_SHA }}
with:
host: ${{ secrets.AWS_SERVER_IP }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
docker-compose stop ${{ secrets.DOCKER_SERVICE_NAME }}
docker-compose rm -f ${{ secrets.DOCKER_SERVICE_NAME }}
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY}}
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY}} ${{ secrets.DOCKER_IMAGE_NAME }}
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 발생).