Skip to content

Commit

Permalink
Merge pull request #46 from anxi01/cicd/무중단-배포-구축
Browse files Browse the repository at this point in the history
CICD : 무중단 배포 구축
  • Loading branch information
anxi01 authored Apr 25, 2024
2 parents 1865bed + ee66eda commit 91d5e68
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 76 deletions.
42 changes: 14 additions & 28 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ name: Zerozero Server CICD
on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
Expand All @@ -25,27 +30,21 @@ jobs:
- name: Build with Gradle
run: ./gradlew clean build

- name: Build Docker Image
uses: docker/build-push-action@v2
with:
context: .
dockerfile: Dockerfile
push: false
tags: ${{secrets.DOCKER_USERNAME}}/zerozero:latest

- name: Login to Docker
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{secrets.DOCKER_USERNAME}}
password: ${{secrets.DOCKER_ACCESS_TOKEN}}

- name: Push to Docker
uses: docker/build-push-action@v2
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
dockerfile: Dockerfile
push: true
tags: ${{secrets.DOCKER_USERNAME}}/zerozero:latest
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Deploy
uses: appleboy/ssh-action@master
Expand All @@ -54,19 +53,6 @@ jobs:
username: ubuntu
key: ${{secrets.PEM_KEY}}
script: |
sudo docker pull ${{secrets.DOCKER_USERNAME}}/zerozero:latest
EXISTING_CONTAINER_ID=$(sudo docker ps -q -f "publish=8080" -f "status=running")
if [ ! -z "$EXISTING_CONTAINER_ID" ]; then
sudo docker stop $EXISTING_CONTAINER_ID
sudo docker rm $EXISTING_CONTAINER_ID
fi
EXISTING_CONTAINER_ID=$(sudo docker ps -q -f "publish=8080" -f "status=exited")
if [ ! -z "$EXISTING_CONTAINER_ID" ]; then
sudo docker rm $EXISTING_CONTAINER_ID
fi

sudo docker rm $(sudo docker ps --filter 'status=exited' -a -q)
sudo docker run -d --log-driver=syslog -p 8080:8080 -e JAVA_OPTS=-Djasypt.encryptor.password=${{secrets.JASYPT_ENCRYPTOR_PASSWORD}} ${{secrets.DOCKER_USERNAME}}/zerozero:latest
sudo docker image prune -a -f
sudo chmod 777 /home/ubuntu/docker/deploy.sh
/home/ubuntu/docker/deploy.sh
docker image prune -f
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM openjdk:17-jdk
FROM openjdk:17-jdk-alpine

ARG PROFILES
ARG ENCRYPTOR

COPY build/libs/*.jar zerozero.jar

ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /zerozero.jar"]
ENTRYPOINT ["java", "-Dspring.profiles.active=${PROFILES}", "-Djasypt.encryptor.password=${ENCRYPTOR}", "-jar", "/zerozero.jar"]
7 changes: 7 additions & 0 deletions src/main/resources/application-dev-blue.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
spring:
config:
activate:
on-profile: dev-blue

server:
port: 8081
7 changes: 7 additions & 0 deletions src/main/resources/application-dev-green.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
spring:
config:
activate:
on-profile: dev-green

server:
port: 8080
44 changes: 0 additions & 44 deletions src/main/resources/application-dev.yaml

This file was deleted.

42 changes: 40 additions & 2 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
spring:
profiles:
default: dev
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: ENC(vFKt3bUbkwBRwX6JB/mt68kZ9vybavoACZd6L2+aPchLywg9g+8zvWbASCrsFJ8t/A44qXXIsXuz1lMgF8TLHS1SZAKCkXbxQLL1oENS0cLMclctjTy47qDY8WUeRINx)
username: ENC(4HB0kiECCrTDYoLAu+ZFWg==)
password: ENC(SS+vlSCU22M19cs6pYMT9gSglt+jBJzr)
jpa:
hibernate:
ddl-auto: update
properties:
hibernate:
show_sql: true
format_sql: true

servlet:
multipart:
max-file-size: 5MB # 파일 하나당 크기
max-request-size: 15MB # 전송하려는 총 파일 크기

jwt:
secretKey: ENC(bUGcue0lkiShbjCUGQWvlDs/bBNBWX/dT9LM5CuHg6iyfgiEhgyeT9ZQFEt8vgbpHI7+waQ4GdnkSTqZApygZrfxVvRj1tpTjp5Tqk4sRgvcSXg0SvEChLWPAzxzqylUrkf0pwG4JBdamojvNzENjHijYmXOai3tU4p4Nava3YDecMQOus41f7VRWOFHRBi6HsUvkUg2BqJzovPbLc8dwU5fo0L1mvR+al6IeO4+Xow=)

naver:
url:
search:
local: https://openapi.naver.com/v1/search/local.json
client:
id: ENC(+360t44DgPZsqSUxThTfvgjE34sgxwfuKlSkCKVjq10=)
secret: ENC(Ed98V/o2RX3XhBYyxPMkvyt9jzj2O/xR)

cloud:
aws:
credentials:
accessKey: ENC(uUN+tzVSwP0qiEunRG5TFIv/wcm2EG312EmrcIj5rmc=)
secretKey: ENC(uPaC8CgR7qRn6K4GH9OpFISRgJaFa85u8b46yUXwPEVFMhBSEb7DUu7azEnZdnM54i9m/aE/raQ=)
s3:
bucket: zerozero-cicd-bucket/images
region:
static: ap-northeast-2
stack:
auto: false

0 comments on commit 91d5e68

Please sign in to comment.