Skip to content

Commit

Permalink
Merge pull request #40 from DDD-Community/feature/ITDS-63-discord-web…
Browse files Browse the repository at this point in the history
…hook

Feature/itds-63 discord webhook
  • Loading branch information
kikingki authored Nov 19, 2024
2 parents a96e892 + 4c4afd2 commit abf1ecd
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 58 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ jobs:
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
# 배포 시작 알림 전송
- name: Start Deployment
continue-on-error: true
run: |
curl -X POST -H "Content-Type: application/json" --data '{"content":"Deployment started!"}' ${{ secrets.DISCORD_WEBHOOK }}
# ssh로 접속해 재배포
- name: Deploy
uses: appleboy/ssh-action@master
Expand All @@ -79,7 +85,18 @@ jobs:
docker-compose pull
docker-compose up -d
# 배포 완료 알림 전송
- name: Notify Deployment Completed
if: success()
run: |
curl -X POST -H "Content-Type: application/json" --data '{"content":"Deployment completed successfully!"}' ${{ secrets.DISCORD_WEBHOOK }}
- name: Notify Deployment Failed
if: failure()
run: |
curl -X POST -H "Content-Type: application/json" --data '{"content":"Deployment failed!"}' ${{ secrets.DISCORD_WEBHOOK }}
# 배포 후 보안 그룹에서 github ip 삭제
- name: Remove Github Actions IP From Security Group
if: always()
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ configurations {

repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}

dependencies {
Expand Down Expand Up @@ -64,6 +65,7 @@ dependencies {

implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation('com.github.napstr:logback-discord-appender:1.0.0')
}

def QDomains = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,27 @@ public class GlobalExceptionHandler {
@ExceptionHandler(CustomException.class)
protected ResponseEntity<ApiResponse<?>> handleCustomException(CustomException e) {
int statusCode = e.getErrorCode().getHttpStatus().value();
log.error("CustomException : {}", e.getMessage());
return new ResponseEntity<>(ApiResponse.error(statusCode, e.getMessage()),
e.getErrorCode().getHttpStatus());
log.error("CustomException: {}", e.getMessage(), e);
return ResponseEntity
.status(e.getErrorCode().getHttpStatus())
.body(ApiResponse.error(statusCode, e.getMessage()));
}

@ExceptionHandler(Exception.class)
public ResponseEntity<ApiResponse<?>> handleAllException(final Exception e) {
int statusCode = HttpStatus.INTERNAL_SERVER_ERROR.value();
log.error("handleAllException {}", e.getMessage());
return new ResponseEntity<>(ApiResponse.error(statusCode, e.getMessage()),
HttpStatus.INTERNAL_SERVER_ERROR);
log.error("handleAllException: {}", e.getMessage(), e);
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(ApiResponse.error(statusCode, e.getMessage()));
}

@ExceptionHandler(MaxUploadSizeExceededException.class)
public ResponseEntity<ApiResponse<?>> handleMaxSizeException(MaxUploadSizeExceededException e) {
int statusCode = e.getStatusCode().value();
log.error("MaxUploadSizeExceededException {}", e.getMessage());
return new ResponseEntity<>(ApiResponse.error(statusCode, e.getMessage()),
HttpStatus.PAYLOAD_TOO_LARGE);
log.error("MaxUploadSizeExceededException: {}", e.getMessage(), e);
return ResponseEntity
.status(HttpStatus.PAYLOAD_TOO_LARGE)
.body(ApiResponse.error(statusCode, e.getMessage()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class InfoPost extends BaseTime {
@Column(name = "recruitment_start_date")
private LocalDate recruitmentStartDate;

@NotNull
@Column(name = "recruitment_end_date")
private LocalDate recruitmentEndDate;

Expand Down
45 changes: 45 additions & 0 deletions src/main/resources/Logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>

<springProfile name="dev">
<property resource="application-dev.yml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<root level="INFO">
<appender-ref ref="CONSOLE"/>
</root>
</springProfile>
<springProfile name="local">
<property resource="application-local.yml"/>
<springProperty name="DISCORD_WEBHOOK_URL" source="logging.discord.webhook-url"/>
<appender name="DISCORD" class="com.github.napstr.logback.DiscordAppender">
<webhookUri>${DISCORD_WEBHOOK_URL}</webhookUri>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{HH:mm:ss} [%thread] [%-5level] %logger{36} - %msg%n```%ex{full}```</pattern>
</layout>
<username>🚨에러 알림🚨</username>
<avatarUrl>
https://img1.daumcdn.net/thumb/R1280x0.fjpg/?fname=http://t1.daumcdn.net/brunch/service/user/cnoC/image/vuyIRQbt6-tQGfW80jNaVS5zjTw
</avatarUrl>
<tts>false</tts>
</appender>

<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
<charset>utf8</charset>
</encoder>
</appender>

<appender name="ASYNC_DISCORD" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="DISCORD"/>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
</appender>

<root level="INFO">
<appender-ref ref="ASYNC_DISCORD"/>
<appender-ref ref="Console"/>
</root>
</springProfile>
</configuration>
52 changes: 52 additions & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
spring:
datasource:
url: ${DB_URL}
username: ${DB_USER}
password: ${DB_PASSWORD}
hikari:
connection-timeout: 2000
maximum-pool-size: 10
driver-class-name: org.mariadb.jdbc.Driver
jpa:
hibernate:
ddl-auto: validate
show-sql: true
properties:
hibernate:
format_sql: true
dialect: com.dissonance.itit.config.MariaDBFullTextDialect
defer-datasource-initialization: false
servlet:
multipart:
max-request-size: 10MB
max-file-size: 10MB
data:
redis:
port: ${REDIS_PORT}
host: ${REDIS_HOST}

jwt:
token:
secret-key: ${JWT_SECRET}

logging:
level:
org:
hibernate:
type: debug
stat: debug
discord:
webhook-url: ${DISCORD_WEBHOOK_URL}
config: classpath:logback.xml

cloud:
aws:
s3:
bucket: itit-bucket
region:
static: ap-northeast-2
stack:
auto: false
credentials:
access-key: ${AWS_ACCESS_KEY}
secret-key: ${AWS_SECRET_KEY}
52 changes: 52 additions & 0 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
spring:
datasource:
url: ${DB_URL}
username: ${DB_USER}
password: ${DB_PASSWORD}
hikari:
connection-timeout: 2000
maximum-pool-size: 5
driver-class-name: org.mariadb.jdbc.Driver
jpa:
hibernate:
ddl-auto: update
show-sql: true
properties:
hibernate:
format_sql: true
dialect: com.dissonance.itit.config.MariaDBFullTextDialect
defer-datasource-initialization: true
servlet:
multipart:
max-request-size: 10MB
max-file-size: 10MB
data:
redis:
port: ${REDIS_PORT}
host: ${REDIS_HOST}

jwt:
token:
secret-key: ${JWT_SECRET}

logging:
level:
org:
hibernate:
type: trace
stat: debug
discord:
webhook-url: ${DISCORD_WEBHOOK_URL}
config: classpath:logback.xml

cloud:
aws:
s3:
bucket: itit-bucket
region:
static: ap-northeast-2
stack:
auto: false
credentials:
access-key: ${AWS_ACCESS_KEY}
secret-key: ${AWS_SECRET_KEY}
50 changes: 1 addition & 49 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,5 @@ server:
context-path: /api/v1

spring:
datasource:
url: ${DB_URL}
username: ${DB_USER}
password: ${DB_PASSWORD}
hikari:
connection-timeout: 2000
maximum-pool-size: ${POOL_SIZE:5}
driver-class-name: org.mariadb.jdbc.Driver
jpa:
hibernate:
ddl-auto: ${DDL_AUTO:update}
show-sql: true
properties:
hibernate:
format_sql: true
dialect: com.dissonance.itit.config.MariaDBFullTextDialect
defer-datasource-initialization: ${DEFER_INIT:true}
profiles:
include: oauth
servlet:
multipart:
max-request-size: 10MB
max-file-size: 10MB
data:
redis:
port: ${REDIS_PORT}
host: ${REDIS_HOST}

jwt:
token:
secret-key: ${JWT_SECRET}

logging:
level:
org:
hibernate:
type: ${LOG_LEVEL:trace}
stat: debug

cloud:
aws:
s3:
bucket: itit-bucket
region:
static: ap-northeast-2
stack:
auto: false
credentials:
access-key: ${AWS_ACCESS_KEY}
secret-key: ${AWS_SECRET_KEY}
include: oauth

0 comments on commit abf1ecd

Please sign in to comment.