Skip to content

Commit

Permalink
Merge pull request #564 from sopt-makers/develop
Browse files Browse the repository at this point in the history
* feat: coffee chat 최신순 정렬 추가 (#558)

related issue #557

* [Feat] update dev server deploy script (#562)

* feat: update dev server deploy script

related issue #561

* fix: aws access key 수정

related issue #561

* fix: ecr login command

related issue #561

* fix: remove 'amd64' tag

related issue #561

* fix: remove 'amd64' tag

related issue #561

* fix: ECR_REPO env를 사용하도록 수정

related issue #561

* fix: env 할당 방식 변경

related issue #561

* fix: env 할당 방식 변경

related issue #561

* fix: change platform

related issue #561

* fix: ECR_REPO env 추가

related issue #561

* chore: ecr repo rollback

* fix: ECR_HOST, ECR_REPO env 변경

* fix: ECR_HOST, ECR_REPO env 변경

* fix: cli만 사용하도록 변경

* fix: directory 명시

* fix: scp debugging

- directory 수정

* fix: env 수정

* fix: docker -> docker-compose로 수정

* fix: docker -> docker-compose로 수정

- scp debug mode off

related issue #561

* feat: port switching 추가

related issue #561

* fix: add health check sleep

related issue #561

* refactor: script 공통 로직 function으로 최소화

related issue #561

* refactor: script 파일 분리

related issue #561

* fix: health check error

related issue #561

* chore: test용 trigger 제거

related issue #561

* feat: apply to production workflow

related issue #561

* chore: remove appspec.yml, code deploy script

related issue #561

* chore: workflow name rollback

related issue #561

* chore: region 'ap-northeast-2'로 변경

related issue #561

* chore: add end line

related issue #561

* test: trigger 추가

related issue #561

* fix: ap-northeast-2 -> us-east-1 로 변경

related issue #561

* chore: remove trigger for test

related issue #561
  • Loading branch information
jun02160 authored Dec 15, 2024
2 parents e141b4e + 8529719 commit b41f217
Show file tree
Hide file tree
Showing 15 changed files with 298 additions and 104 deletions.
84 changes: 56 additions & 28 deletions .github/workflows/cd-to-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ on:
push:
branches: [ develop ]

env:
SPRING_PROFILES_ACTIVE: dev
ECR_APP_NAME: ${{ secrets.ECR_APP_NAME }}-dev
ECR_REPO: ${{ secrets.ECR_HOST }}/${{ secrets.ECR_APP_NAME }}-dev
ECR_HOST: ${{ secrets.ECR_HOST }}

jobs:
build:
name: CD Pipeline
Expand All @@ -35,12 +41,13 @@ jobs:
- name: 'Check Java Version'
run: |
java --version
echo 'ecr repo is $ECR_REPO'
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
- name: 'Configure AWS credentials'
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID__TEAM_PLAYGROUND }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY__TEAM_PLAYGROUND }}
aws-region: ap-northeast-2

- name: 'Get application.yml from AWS S3'
Expand All @@ -54,37 +61,58 @@ jobs:
aws s3 cp \
--region ap-northeast-2 \
s3://sopt-makers-internal/dev/deploy/${{ secrets.APPLE_KEY }} src/main/resources/static/${{ secrets.APPLE_KEY }}
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash
- name: Build with Gradle
run: ./gradlew clean build -x test
- name: 'Build with Gradle'
run: |
chmod +x ./gradlew
./gradlew clean build -x test
shell: bash

- name: Get current time
- name: 'Login to ECR'
run: |
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin $ECR_HOST
- name: 'Docker Image Build & Push'
run: |
docker build -t $ECR_APP_NAME .
docker tag $ECR_APP_NAME:latest $ECR_REPO
docker push $ECR_REPO
- name: 'Send docker-compose.yml to EC2 Instance'
uses: appleboy/scp-action@master
with:
host: ${{ secrets.DEV_RELEASE_SERVER_IP }}
username: ${{ secrets.RELEASE_SERVER_USER }}
key: ${{ secrets.DEV_RELEASE_SERVER_KEY }}
source: "./docker-compose.yml"
target: "/home/ec2-user/app/"

- name: 'Send deploy script to EC2 Instance'
uses: appleboy/scp-action@master
with:
host: ${{ secrets.DEV_RELEASE_SERVER_IP }}
username: ${{ secrets.RELEASE_SERVER_USER }}
key: ${{ secrets.DEV_RELEASE_SERVER_KEY }}
source: "./scripts/"
target: "/home/ec2-user/app/"

- name: 'Get current time'
uses: 1466587594/get-current-time@v2
id: current-time
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00"

- name: Spring Boot env setting
run: sudo sed -i 's/-Dspring.profiles.active=dev/-Dspring.profiles.active=dev/g' ./aws/start.sh

- name: Check env profile
run: cat ./aws/start.sh
- name: 'Docker Container Run'
uses: appleboy/ssh-action@master

- name: Make zip file
run: zip -qq -r ./$GITHUB_SHA.zip .
shell: bash

- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://sopt-makers-internal/dev/deploy/jar/$GITHUB_SHA.zip

- name: Code Deploy
run: aws deploy create-deployment --application-name internal
--deployment-config-name CodeDeployDefault.OneAtATime
--deployment-group-name dev
--s3-location bucket=sopt-makers-internal,bundleType=zip,key=dev/deploy/jar/$GITHUB_SHA.zip
with:
host: ${{ secrets.DEV_RELEASE_SERVER_IP }}
username: ${{ secrets.RELEASE_SERVER_USER }}
key: ${{ secrets.DEV_RELEASE_SERVER_KEY }}
script: |
cd ~
sudo docker pull $ECR_REPO
sudo chmod +x ./app/scripts/*.sh
./app/scripts/deploy.sh
docker image prune -f
81 changes: 54 additions & 27 deletions .github/workflows/cd-to-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ on:
push:
branches: [ main ]

env:
SPRING_PROFILES_ACTIVE: prod
ECR_APP_NAME: ${{ secrets.ECR_APP_NAME }}-prod
ECR_REPO: ${{ secrets.ECR_HOST }}/${{ secrets.ECR_APP_NAME }}-prod
ECR_HOST: ${{ secrets.ECR_HOST }}

jobs:
build:
name: CD Pipeline
Expand All @@ -36,11 +42,11 @@ jobs:
run: |
java --version
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
- name: 'Configure AWS credentials'
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID__TEAM_PLAYGROUND }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY__TEAM_PLAYGROUND }}
aws-region: ap-northeast-2

- name: 'Get application.yml from AWS S3'
Expand All @@ -55,36 +61,57 @@ jobs:
--region ap-northeast-2 \
s3://sopt-makers-internal/prod/deploy/${{ secrets.APPLE_KEY }} src/main/resources/static/${{ secrets.APPLE_KEY }}
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
- name: 'Build with Gradle'
run: |
chmod +x ./gradlew
./gradlew clean build -x test
shell: bash

- name: Build with Gradle
run: ./gradlew clean build -x test
shell: bash
- name: 'Login to ECR'
run: |
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin $ECR_HOST
- name: 'Docker Image Build & Push'
run: |
docker build -t $ECR_APP_NAME .
docker tag $ECR_APP_NAME:latest $ECR_REPO
docker push $ECR_REPO
- name: 'Send docker-compose.yml to EC2 Instance'
uses: appleboy/scp-action@master
with:
host: ${{ secrets.PROD_RELEASE_SERVER_IP }}
username: ${{ secrets.RELEASE_SERVER_USER }}
key: ${{ secrets.PROD_RELEASE_SERVER_KEY }}
source: "./docker-compose.yml"
target: "/home/ec2-user/app/"

- name: 'Send deploy script to EC2 Instance'
uses: appleboy/scp-action@master
with:
host: ${{ secrets.PROD_RELEASE_SERVER_IP }}
username: ${{ secrets.RELEASE_SERVER_USER }}
key: ${{ secrets.PROD_RELEASE_SERVER_KEY }}
source: "./scripts/"
target: "/home/ec2-user/app/"

- name: Get current time
- name: 'Get current time'
uses: 1466587594/get-current-time@v2
id: current-time
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00"

- name: Spring Boot env setting
run: sudo sed -i 's/-Dspring.profiles.active=dev/-Dspring.profiles.active=prod/g' ./aws/start.sh
- name: 'Docker Container Run'
uses: appleboy/ssh-action@master

- name: Check env profile
run: cat ./aws/start.sh

- name: Make zip file
run: zip -qq -r ./$GITHUB_SHA.zip .
shell: bash

- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://sopt-makers-internal/prod/deploy/jar/$GITHUB_SHA.zip

- name: Code Deploy
run: aws deploy create-deployment --application-name internal
--deployment-config-name CodeDeployDefault.OneAtATime
--deployment-group-name prod
--s3-location bucket=sopt-makers-internal,bundleType=zip,key=prod/deploy/jar/$GITHUB_SHA.zip
with:
host: ${{ secrets.PROD_RELEASE_SERVER_IP }}
username: ${{ secrets.RELEASE_SERVER_USER }}
key: ${{ secrets.PROD_RELEASE_SERVER_KEY }}
script: |
cd ~
sudo docker pull $ECR_REPO
sudo chmod +x ./app/scripts/*.sh
./app/scripts/deploy.sh
docker image prune -f
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ jobs:

steps:
- name: 'Checkout'
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: 'Set up JDK 17'
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: 17

- name: 'Grant execute permission for gradlew'
Expand Down
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM amazoncorretto:17
WORKDIR /app
COPY ./build/libs/internal-0.0.1-SNAPSHOT.jar /app/APPLICATION.jar

ENV SPRING_PROFILES_ACTIVE=dev

CMD ["java", "-Duser.timezone=Asia/Seoul", "-jar", "-Dspring.profiles.active=${SPRING_PROFILES_ACTIVE}", "APPLICATION.jar"]
19 changes: 0 additions & 19 deletions appspec.yml

This file was deleted.

8 changes: 0 additions & 8 deletions aws/start.sh

This file was deleted.

3 changes: 0 additions & 3 deletions aws/stop.sh

This file was deleted.

17 changes: 0 additions & 17 deletions aws/valid.sh

This file was deleted.

21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: '3.8'
services:
playground-blue:
image: ${ECR_REPO}
expose:
- 8080
ports:
- "8080:8080"
environment:
- TZ=Asia/Seoul
- SPRING_PROFILES_ACTIVE=${SPRING_PROFILES_ACTIVE}

playground-green:
image: ${ECR_REPO}
expose:
- 8080
ports:
- "8081:8080"
environment:
- TZ=Asia/Seoul
- SPRING_PROFILES_ACTIVE=${SPRING_PROFILES_ACTIVE}
Loading

0 comments on commit b41f217

Please sign in to comment.