Skip to content

Commit

Permalink
Merge pull request #137 from kakao-tech-campus-2nd-step3/featcicd
Browse files Browse the repository at this point in the history
cicd ์Šคํฌ๋ฆฝํŠธ update
  • Loading branch information
yooookm authored Nov 14, 2024
2 parents e83ef54 + 3f63d2b commit e0a545a
Show file tree
Hide file tree
Showing 34 changed files with 1,039 additions and 60 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Java CI and Deploy to AWS EC2

on:
push:
branches: [ "Week10" ]
pull_request:
branches: [ "Week10" ]

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582

- name: Build with Gradle Wrapper
run: ./gradlew clean build

deploy:
runs-on: ubuntu-latest
needs: build
environment: production
permissions:
contents: read

steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Decode and save .pem file
env:
EC2_SSH_KEY_BASE64: ${{ secrets.EC2_SSH_KEY_BASE64 }}
run: |
echo "$EC2_SSH_KEY_BASE64" | base64 -d > ec2-key.pem
chmod 600 ec2-key.pem
- name: Upload JAR to EC2
env:
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_USER: ${{ secrets.EC2_USER }}
run: |
scp -i ec2-key.pem -o StrictHostKeyChecking=no ./build/libs/your-app.jar $EC2_USER@$EC2_HOST:~/app/your-app.jar
- name: Restart Application on EC2
env:
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_USER: ${{ secrets.EC2_USER }}
run: |
ssh -i ec2-key.pem -o StrictHostKeyChecking=no $EC2_USER@$EC2_HOST << 'EOF'
# ํ˜„์žฌ ์‹คํ–‰ ์ค‘์ธ Java ํ”„๋กœ์„ธ์Šค ์ข…๋ฃŒ
echo "ํ˜„์žฌ ์‹คํ–‰ ์ค‘์ธ Java ํ”„๋กœ์„ธ์Šค ์ข…๋ฃŒ ์ค‘..."
pkill -f 'java' || echo "์ข…๋ฃŒํ•  Java ํ”„๋กœ์„ธ์Šค ์—†์Œ"
# ์ƒˆ๋กœ์šด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰
JAR_FILE="dbdr-0.0.1-SNAPSHOT.jar"
echo "์ƒˆ๋กœ์šด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค: $JAR_FILE"
nohup java -jar ~/app/$JAR_FILE --server.port=8080 > ~/app/app.log 2>&1 &
# ์‹คํ–‰ ํ™•์ธ
sleep 10
echo "์ƒˆ๋กœ ์‹คํ–‰๋œ Java ํ”„๋กœ์„ธ์Šค:"
pgrep -f 'java'
EOF
43 changes: 2 additions & 41 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ dependencies {
// ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'mysql:mysql-connector-java:8.0.33' // MySQL ์˜์กด์„ฑ ์ถ”๊ฐ€ (MySQL JDBC ๋“œ๋ผ์ด๋ฒ„)
runtimeOnly 'com.h2database:h2'

// ๋ณด์•ˆ
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-security'
//implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
//implementation 'org.springframework.boot:spring-boot-starter-security'

// JWT ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ถ”๊ฐ€
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
Expand All @@ -46,49 +45,11 @@ dependencies {
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

// SpringDoc OpenAPI (Swagger UI ํฌํ•จ)
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0'

// ํ…Œ์ŠคํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'com.h2database:h2' // H2๋Š” ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ์—์„œ ์ฃผ๋กœ ์‚ฌ์šฉ

// Line-messaging-api ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
implementation 'com.linecorp.bot:line-bot-spring-boot:4.7.0'


// MapStruct
implementation 'org.mapstruct:mapstruct:1.4.2.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'

//POI
implementation 'org.apache.poi:poi-ooxml:5.3.0'
implementation 'org.apache.commons:commons-compress:1.27.1'

// Redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'

// Amazon SQS
implementation platform("io.awspring.cloud:spring-cloud-aws-dependencies:3.0.1")
implementation 'io.awspring.cloud:spring-cloud-aws-starter-sqs'

// CoolSMS
implementation 'net.nurigo:sdk:4.3.0'

// AWS S3
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'

// Naver Clova OCR API
implementation 'org.springframework.boot:spring-boot-starter-webflux' // WebClient ์‚ฌ์šฉ์„ ์œ„ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

// Health check
implementation 'org.springframework.boot:spring-boot-starter-actuator'
}

tasks.named('test') {
useJUnitPlatform()
}

tasks.withType(JavaCompile) {
options.compilerArgs += ['-parameters']
}
14 changes: 3 additions & 11 deletions src/main/java/dbdr/DbdrApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.TimeZone;

@SpringBootApplication
@EnableJpaAuditing
@EnableScheduling
public class DbdrApplication {

static {
// ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‹œ์ž‘๋˜๊ธฐ ์ „์— ์„œ์šธ ์‹œ๊ฐ„์œผ๋กœ ํƒ€์ž„์กด์„ ์„ค์ •
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
}
public static void main(String[] args) {
SpringApplication.run(DbdrApplication.class, args);
}

public static void main(String[] args) {
SpringApplication.run(DbdrApplication.class, args);
}
}
61 changes: 61 additions & 0 deletions src/main/java/dbdr/controller/AdminGuardiansController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package dbdr.controller;

import dbdr.dto.request.GuardiansRequest;
import dbdr.dto.response.GuardiansResponse;
import dbdr.service.GuardiansService;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/v1/admin/guardians")
@RequiredArgsConstructor
public class AdminGuardiansController {

private final GuardiansService guardiansService;

@GetMapping
public ResponseEntity<List<GuardiansResponse>> showAllGuardians() {
List<GuardiansResponse> guardiansResponseList = guardiansService.getAllGuardians();
return ResponseEntity.ok(guardiansResponseList);
}

@GetMapping("/{guardianId}")
public ResponseEntity<GuardiansResponse> showOneGuardian(
@PathVariable("guardianId") Long guardianId) {
GuardiansResponse guardiansResponse = guardiansService.getGuardianById(guardianId);
return ResponseEntity.ok(guardiansResponse);
}

@PostMapping
public ResponseEntity<GuardiansResponse> addGuardian(
@Valid @RequestBody GuardiansRequest guardiansRequest) {
GuardiansResponse guardiansResponse = guardiansService.addGuardian(guardiansRequest);
return ResponseEntity.status(HttpStatus.CREATED).body(guardiansResponse);
}

@PutMapping("/{guardianId}/update")
public ResponseEntity<GuardiansResponse> updateGuardianAuth(
@PathVariable("guardianId") Long guardianId,
@Valid @RequestBody GuardiansRequest guardiansRequest) {
GuardiansResponse guardiansResponse = guardiansService.updateGuardianById(guardianId,
guardiansRequest);
return ResponseEntity.ok(guardiansResponse);
}

@PutMapping("/{guardianId}/delete")
public ResponseEntity<Void> deleteGuardianAuth(
@PathVariable("guardianId") Long guardianId) {
guardiansService.deleteGuardianById(guardianId);
return ResponseEntity.noContent().build();
}
}
59 changes: 59 additions & 0 deletions src/main/java/dbdr/controller/CareworkerController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package dbdr.controller;

import dbdr.dto.request.CareworkerRequestDTO;
import dbdr.dto.response.CareworkerResponseDTO;
import dbdr.service.CareworkerService;
import jakarta.validation.Valid;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.net.URI;
import java.util.List;

@RestController
@RequestMapping("/v1/careworkers")
public class CareworkerController {

private final CareworkerService careworkerService;

public CareworkerController(CareworkerService careworkerService) {
this.careworkerService = careworkerService;
}

@GetMapping
public ResponseEntity<List<CareworkerResponseDTO>> getAllCareworkers(
@RequestParam(value = "institutionId", required = false) Long institutionId) {
List<CareworkerResponseDTO> careworkers;
if (institutionId != null) {
careworkers = careworkerService.getCareworkersByInstitution(institutionId);
} else {
careworkers = careworkerService.getAllCareworkers();
}
return ResponseEntity.ok(careworkers);
}

@GetMapping("/{id}")
public ResponseEntity<CareworkerResponseDTO> getCareworkerById(@PathVariable Long id) {
CareworkerResponseDTO careworker = careworkerService.getCareworkerById(id);
return ResponseEntity.ok(careworker);
}

@PostMapping
public ResponseEntity<CareworkerResponseDTO> createCareworker(@Valid @RequestBody CareworkerRequestDTO careworkerDTO) {
CareworkerResponseDTO newCareworker = careworkerService.createCareworker(careworkerDTO);
return ResponseEntity.created(URI.create("/v1/careworkers/" + newCareworker.getId()))
.body(newCareworker);
}

@PutMapping("/{id}")
public ResponseEntity<CareworkerResponseDTO> updateCareworker(@PathVariable Long id, @Valid @RequestBody CareworkerRequestDTO careworkerDTO) {
CareworkerResponseDTO updatedCareworker = careworkerService.updateCareworker(id, careworkerDTO);
return ResponseEntity.ok(updatedCareworker);
}

@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteCareworker(@PathVariable Long id) {
careworkerService.deleteCareworker(id);
return ResponseEntity.noContent().build();
}
}
38 changes: 38 additions & 0 deletions src/main/java/dbdr/controller/GuardiansController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package dbdr.controller;

import dbdr.dto.request.GuardiansRequest;
import dbdr.dto.response.GuardiansResponse;
import dbdr.service.GuardiansService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/v1/guardians")
@RequiredArgsConstructor
public class GuardiansController {

private final GuardiansService guardiansService;

@GetMapping("/{guardianId}")
public ResponseEntity<GuardiansResponse> showGuardianInfo(
@PathVariable("guardianId") Long guardianId) {
GuardiansResponse guardiansResponse = guardiansService.getGuardianById(guardianId);
return ResponseEntity.ok(guardiansResponse);
}

@PutMapping("/{guardianId}")
public ResponseEntity<GuardiansResponse> updateGuardianInfo(
@PathVariable("guardianId") Long guardianId,
@Valid @RequestBody GuardiansRequest guardiansRequest) {
GuardiansResponse guardiansResponse = guardiansService.updateGuardianById(guardianId,
guardiansRequest);
return ResponseEntity.ok(guardiansResponse);
}
}
53 changes: 53 additions & 0 deletions src/main/java/dbdr/controller/RecipientController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package dbdr.controller;

import dbdr.dto.request.RecipientRequestDTO;
import dbdr.dto.response.RecipientResponseDTO;
import dbdr.service.RecipientService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

import java.net.URI;
import java.util.List;

@RestController
@RequestMapping("/v1/recipients")
public class RecipientController {

private final RecipientService recipientService;

public RecipientController(RecipientService recipientService) {
this.recipientService = recipientService;
}

@GetMapping
public ResponseEntity<List<RecipientResponseDTO>> getAllRecipients() {
List<RecipientResponseDTO> recipients = recipientService.getAllRecipients();
return ResponseEntity.ok(recipients);
}

@GetMapping("/{id}")
public ResponseEntity<RecipientResponseDTO> getRecipientById(@PathVariable Long id) {
RecipientResponseDTO recipient = recipientService.getRecipientById(id);
return ResponseEntity.ok(recipient);
}

@PostMapping
public ResponseEntity<RecipientResponseDTO> createRecipient(@Valid @RequestBody RecipientRequestDTO recipientDTO) {
RecipientResponseDTO newRecipient = recipientService.createRecipient(recipientDTO);
return ResponseEntity.created(URI.create("/v1/recipients/" + newRecipient.getId()))
.body(newRecipient);
}

@PutMapping("/{id}")
public ResponseEntity<RecipientResponseDTO> updateRecipient(@PathVariable Long id, @RequestBody RecipientRequestDTO recipientDTO) {
RecipientResponseDTO updatedRecipient = recipientService.updateRecipient(id, recipientDTO);
return ResponseEntity.ok(updatedRecipient);
}

@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteRecipient(@PathVariable Long id) {
recipientService.deleteRecipient(id);
return ResponseEntity.noContent().build();
}
}
Loading

0 comments on commit e0a545a

Please sign in to comment.