Skip to content

Commit

Permalink
[FEAT] CICD를 구성한다. (#24)
Browse files Browse the repository at this point in the history
* [FEAT]: ci.yml 기능 추가 (#23)

* [FEAT]: cd.yml 생성(#23)

* [FIX]: Klint 수정 (#23)

* [FEAT]: ContextTest 임시 삭제 (#23)

* [FEAT]: Docker File 생성 (#23)

* [FIX]: ci.yml configuration files 생성 bad substitution 오류 수정(#23)

* [FIX]: 직접 파일을 생성하는 것에서 환경변수로 치환하는 것으로 변경 (#23)

* [DOCS]: git ignore 수정 (#23)

* [DOCS]: yml 파일을 개발자 공통으로 관리 할 수 있도록 Ignore에서 제외, 부분 환경변수로 암호화 (#23)

* [FEAT]: 도커 잉여 이미지 제거 스크립트 추가 (#23)
  • Loading branch information
hojinida authored Jul 29, 2024
1 parent 54498c2 commit 3decba2
Show file tree
Hide file tree
Showing 15 changed files with 1,632 additions and 22 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: CD

on:
workflow_dispatch:
pull_request:
types: [closed]
branches: [develop]

jobs:
deploy:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

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

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

- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/dev:latest

- name: Add SSH key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Deploy to server
run: |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << 'EOF'
docker pull ${{ secrets.DOCKER_USERNAME }}/dev:latest
docker stop app || true
docker rm app || true
docker run -d --name app -p 80:80 ${{ secrets.DOCKER_USERNAME }}/dev:latest
docker image prune -f
EOF
38 changes: 32 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,56 @@
name: CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
branches: [ "develop" ]
workflow_dispatch:

permissions:
contents: read

jobs:
build:
build-and-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'adopt'

- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Set environment variables
env:
KAKAO_ADMIN_KEY: ${{ secrets.KAKAO_ADMIN_KEY }}
JWT_ACCESS_TOKEN_SECRET: ${{ secrets.JWT_ACCESS_TOKEN_SECRET }}
JWT_REFRESH_TOKEN_SECRET: ${{ secrets.JWT_REFRESH_TOKEN_SECRET }}
STORAGE_DATABASE_CORE_DB_URL: ${{ secrets.STORAGE_DATABASE_CORE_DB_URL }}
STORAGE_DATABASE_CORE_DB_USERNAME: ${{ secrets.STORAGE_DATABASE_CORE_DB_USERNAME }}
STORAGE_DATABASE_CORE_DB_PASSWORD: ${{ secrets.STORAGE_DATABASE_CORE_DB_PASSWORD }}
AWS_IOT_ENDPOINT: ${{ secrets.AWS_IOT_ENDPOINT }}
AWS_IOT_CLIENTID: ${{ secrets.AWS_IOT_CLIENTID }}
AWS_IOT_CERTIFICATE: ${{ secrets.AWS_IOT_CERTIFICATE }}
AWS_IOT_PRIVATE_KEY: ${{ secrets.AWS_IOT_PRIVATE_KEY }}
run: echo "Environment variables are set"

- name: Lint
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
uses: gradle/gradle-build-action@v2
with:
arguments: ktlintCheck

- name: Test
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
uses: gradle/gradle-build-action@v2
with:
arguments: test
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ build/
*.iml
*.ipr
out/
**/resources/*.yml
/certs/
7 changes: 7 additions & 0 deletions DockerFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM openjdk:21-jdk-slim

WORKDIR /app

COPY build/libs/MyongjiWay.jar app.jar

ENTRYPOINT ["java", "-jar", "app.jar"]
36 changes: 36 additions & 0 deletions clients/client-kakao/src/main/resources/client-kakao.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
kakao:
url: https://kapi.kakao.com
admin-key: ${KAKAO_ADMIN_KEY}

spring.cloud.openfeign:
client:
config:
example-api:
connectTimeout: 2100
readTimeout: 5000
loggerLevel: full
compression:
response:
enabled: false
httpclient:
max-connections: 2000
max-connections-per-route: 500

---
spring.config.activate.on-profile: local

---
spring.config.activate.on-profile:
- local-dev
- dev

---
spring.config.activate.on-profile:
- staging
- live

example:
api:
url: https://live.example.example


6 changes: 6 additions & 0 deletions clients/client-kakao/src/test/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
spring.application.name: client-kakao-test

spring:
config:
import:
- client-kakao.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.springframework.context.annotation.Configuration

@Configuration
class MqttClientConfig(
private val busLocationService: BusLocationService
private val busLocationService: BusLocationService,
) {

@Value("\${aws.iot.endpoint}")
Expand All @@ -42,7 +42,7 @@ class MqttClientConfig(
fun iotTopicListener(client: AWSIotMqttClient): List<AWSIotTopic> {
val topics = listOf(
MqttTopic("864636062186602/data", AWSIotQos.QOS0),
MqttTopic("test/data", AWSIotQos.QOS0)
MqttTopic("test/data", AWSIotQos.QOS0),

)
return topics.map { createTopicListener(client, it) }
Expand Down Expand Up @@ -71,7 +71,7 @@ class MqttClientConfig(
busId = topic,
latitude = latitude,
longitude = longitude,
timestamp = System.currentTimeMillis()
timestamp = System.currentTimeMillis(),
)
}
}
6 changes: 6 additions & 0 deletions clients/client-mqtt/src/main/resources/client-mqtt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
aws:
iot:
endpoint: ${AWS_IOT_ENDPOINT}
clientId: ${AWS_IOT_CLIENTID}
certificateFile: ${AWS_IOT_CERTIFICATE}
privateKeyFile: ${AWS_IOT_PRIVATE_KEY}
46 changes: 46 additions & 0 deletions core/core-api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
spring.application.name: core-api
spring.profiles.active: local

spring:
config:
import:
- monitoring.yml
- logging.yml
- db-core.yml
- client-kakao.yml
- client-mqtt.yml
web.resources.add-mappings: false

server:
tomcat:
max-connections: 20000
threads:
max: 600
min-spare: 100

jwt:
access-token:
secret: ${JWT_ACCESS_TOKEN_SECRET}
expiration: 3600000
refresh-token:
secret: ${JWT_REFRESH_TOKEN_SECRET}
expiration: 1209600000

---
spring.config.activate.on-profile: local


---
spring.config.activate.on-profile: local-dev


---
spring.config.activate.on-profile: dev


---
spring.config.activate.on-profile: staging


---
spring.config.activate.on-profile: live
Loading

0 comments on commit 3decba2

Please sign in to comment.