diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 930a2e0..5629902 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -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 @@ -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 \ No newline at end of file diff --git a/build.gradle b/build.gradle index 11ccf5e..418e6e2 100644 --- a/build.gradle +++ b/build.gradle @@ -37,6 +37,7 @@ configurations { repositories { mavenCentral() + maven { url 'https://jitpack.io' } } dependencies { @@ -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 = [] diff --git a/src/main/java/com/dissonance/itit/common/exception/GlobalExceptionHandler.java b/src/main/java/com/dissonance/itit/common/exception/GlobalExceptionHandler.java index 8ec0d84..a2c29c3 100644 --- a/src/main/java/com/dissonance/itit/common/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/dissonance/itit/common/exception/GlobalExceptionHandler.java @@ -16,24 +16,27 @@ public class GlobalExceptionHandler { @ExceptionHandler(CustomException.class) protected ResponseEntity> 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> 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> 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())); } } diff --git a/src/main/java/com/dissonance/itit/domain/entity/InfoPost.java b/src/main/java/com/dissonance/itit/domain/entity/InfoPost.java index 5533bc1..b3809c1 100644 --- a/src/main/java/com/dissonance/itit/domain/entity/InfoPost.java +++ b/src/main/java/com/dissonance/itit/domain/entity/InfoPost.java @@ -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; diff --git a/src/main/resources/Logback.xml b/src/main/resources/Logback.xml new file mode 100644 index 0000000..1ff0373 --- /dev/null +++ b/src/main/resources/Logback.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + ${DISCORD_WEBHOOK_URL} + + %d{HH:mm:ss} [%thread] [%-5level] %logger{36} - %msg%n```%ex{full}``` + + 🚨에러 알림🚨 + + https://img1.daumcdn.net/thumb/R1280x0.fjpg/?fname=http://t1.daumcdn.net/brunch/service/user/cnoC/image/vuyIRQbt6-tQGfW80jNaVS5zjTw + + false + + + + + ${CONSOLE_LOG_PATTERN} + utf8 + + + + + + + ERROR + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 0000000..5af8e2e --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -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} \ No newline at end of file diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml new file mode 100644 index 0000000..97aabc9 --- /dev/null +++ b/src/main/resources/application-local.yml @@ -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} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 1c03b94..11fff70 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -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} \ No newline at end of file + include: oauth \ No newline at end of file