Skip to content

Commit

Permalink
chore: 서버 ncp -> aws로 이전 (#257)
Browse files Browse the repository at this point in the history
* chore: test

* chore: test

* chore: StoredCredential 삭제

* chore: Dockerfile 수정

* chore: aws-cicd yml 수정

* chore: docker compose 변경(Docker-dev, prod 분리)

* chore: docker compose 변경(Docker-dev, prod 분리)

* chore: build 부분 수정

* chore: docker build 부분 수정

* chore: docker build 부분 수정

* chore: docker build 부분 수정

* chore: cicd-prod.ym ldocker build 부분 수정

* chore: cicd-prod.yml 오타 수정

* chore: prod > deploy.sh 작성

* chore: prod > blue,green 추가

* chore: prod > blue,green 추가

* chore: prod > blue,green 추가

* chore: docker-compose depends_on 수정

* chore: deploy 수정

* chore: docker-compse 테스트

* chore: docker-compse 테스트

* chore: docker-compse 테스트

* chore: docker-compse 테스트

* chore: docker-compse 테스트

* chore: docker-compse 테스트

* chore: docker-compse 테스트

* chore: docker-compse 테스트

* chore: docker-compse 테스트

* chore: docker-compse 테스트

* chore: dev test

* chore: dev test

* chore: prod test

* chore: prod nginx conf 변경

* chore: prod nginx conf 변경

* chore: github actionsa 파일 브랜치 명 변경

* chore: batch db 엔드포인트 변경

* chore: 포트번호 변경

* chore: depends on 변경

* chore: 포트 변경

* chore: 포트 변경

* chore: blue green sh 수정

* chore: blue green sh 수정

* chore: docker compose 수정

* chore: sh 수정

* chore: 포트 수정

* chore: 포트 수정

* chore: dns 수정

* chore: localhost로 수정

* chore: 배치 로그 추가

* chore: Dockefile 수정

* chore: 크론 임시 변경

* chore: 도커 파일 변경

* chore: 도커 파일 이름 지정

* chore: batch yml 추가

* chore: no-cache 추가

* chore: Dockerfile 이름 변경

* chore: deploy.sh 변경

* chore: 2분마다로 변경 테스트

* chore: now 로그 추가

* chore: 스케줄러 1시간 단위로 변경
  • Loading branch information
clean2001 authored Nov 12, 2024
1 parent ebacc05 commit 8e0d17a
Show file tree
Hide file tree
Showing 26 changed files with 652 additions and 72 deletions.
164 changes: 164 additions & 0 deletions .github/workflows/aws-cicd-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
name: deploy action

on:
push:
branches:
- develop

env:
REGISTRY: "docker.io"
NAMESPACE: "clean01"
IMAGE_NAME: "layer-server"

jobs:
setup:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
deploy_target: ${{ steps.set-env.outputs.DEPLOY_TARGET }}
steps:
- name: Setup Env
id: set-env
run: |
echo "DEPLOY_TARGET=development" >> $GITHUB_OUTPUT
build:
name: build
needs: [ setup ]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

env:
DEPLOY_TARGET: ${{ needs.setup.outputs.deploy_target }}
REGISTRY: "docker.io"
NAMESPACE: "clean01"
APPLICATION_SECRET_PROPERTIES: ${{ secrets.AWS_APPLICATION_SECRET_PROPERTIES }}
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}

steps:
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'

- name: Checkout sources
uses: actions/checkout@v4

- name: Setup Gradle
uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0

- name: Create application-secret.properties
run: |
echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-api/src/main/resources/application-secret.properties
echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-batch/src/main/resources/application-secret.properties
- name: Build layer-api module
run: ./gradlew :layer-api:build

- name: Test layer-api module
run: ./gradlew :layer-api:test

- name: Build layer-batch module
run: ./gradlew :layer-batch:build

- name: Test layer-batch module
run: ./gradlew :layer-batch:test

- name: Docker Hub Login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_EMAIL }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: |
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-api
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-batch
- name: Push layer-api Docker Image
uses: docker/build-push-action@v4
with:
context: ./layer-api
file: ./layer-api/Dockerfile-dev # Dockerfile 이름 지정
platforms: linux/amd64
push: true
tags: |
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-api:latest
- name: Push layer-batch Docker Image
uses: docker/build-push-action@v4
with:
context: ./layer-batch
platforms: linux/amd64
push: true
tags: |
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-batch:latest
deploy:
name: Deploy
needs: [ build, setup ]
runs-on: ubuntu-latest
env:
DEPLOY_TARGET: ${{ needs.setup.outputs.deploy_target }}

steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Create application-secret.properties file
run: |
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./layer-api/infra/${{ env.DEPLOY_TARGET }}/application-secret.properties
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./layer-batch/src/main/resources/application-secret.properties
- name: Archive Files
run: |
tar -cvzf layer-api.tar.gz ./layer-api/infra/${{ env.DEPLOY_TARGET }}/
- name: Send Docker Compose
uses: appleboy/scp-action@master
with:
host: ${{ secrets.AWS_DEV_INSTANCE_HOST }}
username: ubuntu
key: ${{ secrets.AWS_INSTANCE_PEM }}
port: 22
source: "layer-api.tar.gz"
target: "/home/ubuntu"

- name: Extract Files on Server and Set Permissions
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.AWS_DEV_INSTANCE_HOST }}
username: ubuntu
key: ${{ secrets.AWS_INSTANCE_PEM }}
port: 22
script: |
cd /home/ubuntu
tar -xvzf layer-api.tar.gz
sudo chmod -R 755 /home/ubuntu/layer-api/infra/${{ env.DEPLOY_TARGET }}
sudo chown -R ubuntu:ubuntu /home/ubuntu/layer-api/infra/${{ env.DEPLOY_TARGET }}
- name: Deploy with Docker Compose
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.AWS_DEV_INSTANCE_HOST }}
username: ubuntu
key: ${{ secrets.AWS_INSTANCE_PEM }}
port: 22
script: |
sudo apt update
sudo apt install docker-ce
sudo apt install docker-compose
sudo docker login --username ${{ secrets.DOCKER_EMAIL }} --password ${{ secrets.DOCKER_PASSWORD }}
cd /home/ubuntu/layer-api/infra/${{ env.DEPLOY_TARGET }}
sudo docker-compose pull && sudo docker-compose up -d
sudo docker image prune -a -f
179 changes: 179 additions & 0 deletions .github/workflows/aws-cicd-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
name: deploy action

on:
push:
branches:
- main
- chore/migration

env:
REGISTRY: "docker.io"
NAMESPACE: "clean01"
IMAGE_NAME: "layer-server"

jobs:
setup:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
deploy_target: ${{ steps.set-env.outputs.DEPLOY_TARGET }}
steps:
- name: Setup Env
id: set-env
run: |
echo "DEPLOY_TARGET=production" >> $GITHUB_OUTPUT
build:
name: build
needs: [ setup ]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

env:
DEPLOY_TARGET: ${{ needs.setup.outputs.deploy_target }}
REGISTRY: "docker.io"
NAMESPACE: "clean01"
APPLICATION_SECRET_PROPERTIES: ${{ secrets.AWS_APPLICATION_SECRET_PROPERTIES }}
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}

steps:
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'

- name: Checkout sources
uses: actions/checkout@v4

- name: Setup Gradle
uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0

- name: Create application-secret.properties
run: |
echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-api/src/main/resources/application-secret.properties
echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-batch/src/main/resources/application-secret.properties
- name: Build layer-api module
run: ./gradlew :layer-api:build

- name: Test layer-api module
run: ./gradlew :layer-api:test

- name: Build layer-batch module
run: ./gradlew :layer-batch:build

- name: Test layer-batch module
run: ./gradlew :layer-batch:test

- name: Docker Hub Login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_EMAIL }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: |
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-api
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-batch
- name: Push layer-api Docker Image
uses: docker/build-push-action@v4
with:
context: ./layer-api
file: ./layer-api/Dockerfile-prod # Dockerfile 이름 지정
platforms: linux/amd64
push: true
tags: |
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-api:latest
no-cache: true

- name: Push layer-batch Docker Image
uses: docker/build-push-action@v4
with:
context: ./layer-batch
file: ./layer-batch/Dockerfile-batch # Dockerfile 이름 지정
platforms: linux/amd64
push: true
tags: |
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-batch:latest
no-cache: true

deploy:
name: Deploy
needs: [ build, setup ]
runs-on: ubuntu-latest
env:
DEPLOY_TARGET: ${{ needs.setup.outputs.deploy_target }}

steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Create application-secret.properties file
run: |
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./layer-api/infra/${{ env.DEPLOY_TARGET }}/application-secret.properties
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./layer-batch/src/main/resources/application-secret.properties
- name: Archive Files
run: |
tar -cvzf layer-api.tar.gz ./layer-api/infra/${{ env.DEPLOY_TARGET }}/
- name: Send Docker Compose
uses: appleboy/scp-action@master
with:
host: ${{ secrets.AWS_PROD_INSTANCE_HOST }}
username: ubuntu
key: ${{ secrets.AWS_INSTANCE_PEM }}
port: 22
source: "layer-api.tar.gz"
target: "/home/ubuntu"

- name: Extract Files on Server and Set Permissions
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.AWS_PROD_INSTANCE_HOST }}
username: ubuntu
key: ${{ secrets.AWS_INSTANCE_PEM }}
port: 22
script: |
cd /home/ubuntu
tar -xvzf layer-api.tar.gz
sudo chmod -R 755 /home/ubuntu/layer-api/infra/${{ env.DEPLOY_TARGET }}
sudo chown -R ubuntu:ubuntu /home/ubuntu/layer-api/infra/${{ env.DEPLOY_TARGET }}
- name: Set Permissions on Transferred Files
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.AWS_PROD_INSTANCE_HOST }}
username: ubuntu
key: ${{ secrets.AWS_INSTANCE_PEM }}
port: 22
script: |
sudo chmod -R 755 /home/ubuntu/layer-api/infra/${{ env.DEPLOY_TARGET }}
sudo chown -R ubuntu:ubuntu /home/ubuntu/layer-api/infra/${{ env.DEPLOY_TARGET }}
- name: Deploy with Docker Compose
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.AWS_PROD_INSTANCE_HOST }}
username: ubuntu
key: ${{ secrets.AWS_INSTANCE_PEM }}
port: 22
script: |
sudo apt update
sudo apt install docker-ce
sudo apt install docker-compose
sudo docker login --username ${{ secrets.DOCKER_EMAIL }} --password ${{ secrets.DOCKER_PASSWORD }}
cd /home/ubuntu/layer-api/infra/${{ env.DEPLOY_TARGET }}
chmod 777 ./deploy.sh
./deploy.sh
sudo docker image prune -a -f
2 changes: 1 addition & 1 deletion .github/workflows/k3s-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Spring Boot Multi-module K3s Deployment
on:
push:
branches:
- develop
- develop-test # 실행되지 않도록 브랜치 명 변경

env:
REGISTRY: "ghcr.io"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/k3s-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Spring Boot Multi-module K3s Deployment
on:
push:
branches:
- main
- main-test # 실행되지 않도록 브랜치 명 변경

env:
REGISTRY: "ghcr.io"
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ log/
credentials.json


layer-api/src/main/resources/tokens/StoredCredential
layer-batch/src/main/resources/application-secret.properties
8 changes: 1 addition & 7 deletions layer-api/Dockerfile → layer-api/Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
FROM openjdk:17

ARG JAR_FILE=./build/libs/*.jar
ARG SPRING_PROFILE

COPY ${JAR_FILE} layer-server.jar

ENV SPRING_PROFILE=${SPRING_PROFILE}

ENTRYPOINT ["java", "-Duser.timezone=Asia/Seoul","-Dspring.profiles.active=${SPRING_PROFILE}" ,"-jar" ,"layer-server.jar"]
ENTRYPOINT ["java", "-Duser.timezone=Asia/Seoul","-Dspring.profiles.active=dev" ,"-jar" ,"layer-server.jar"]
4 changes: 4 additions & 0 deletions layer-api/Dockerfile-prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM openjdk:17
ARG JAR_FILE=./build/libs/*.jar
COPY ${JAR_FILE} layer-server.jar
ENTRYPOINT ["java", "-Duser.timezone=Asia/Seoul","-Dspring.profiles.active=prod" ,"-jar" ,"layer-server.jar"]
Loading

0 comments on commit 8e0d17a

Please sign in to comment.