Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Deployment

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

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Build with Gradle
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
arguments: build
- uses: actions/upload-artifact@v3
with:
name: jar
path: build/libs

send-jar:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download jar
uses: actions/download-artifact@v3
with:
name: jar
- name: Send jar to remote server
uses: appleboy/scp-action@master
with:
host: 34.64.186.225
username: lth1283910
source: "real_coding_server-0.0.1-SNAPSHOT.jar"
target: "/home/lth1283910"
key: ${{ secrets.PRIVATE_KEY }}

run-app:
needs: send-jar
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Move deploy.sh
uses: appleboy/scp-action@master
with:
host: 34.64.186.225
username: lth1283910
source: "deploy.sh"
target: "/home/lth1283910"
key: ${{ secrets.PRIVATE_KEY }}
- name: Execute script
uses: appleboy/ssh-action@master
with:
username: lth1283910
host: 34.64.186.225
key: ${{ secrets.PRIVATE_KEY }}
script_stop: true
script: cd /home/lth1283910 && chmod +x deploy.sh && ./deploy.sh
13 changes: 13 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

SERVER_HOME=$(pwd)
APPLICATION=real_coding_server-0.0.1-SNAPSHOT.jar

if [ -f $SERVER_HOME/application.pid ];then
kill -9 $(cat $SERVER_HOME/application.pid)
rm $SERVER_HOME/application.pid
fi

sleep 1s

nohup java -jar $APPLICATION >> spring.out 2>&1 & echo $! > application.pid
1 change: 1 addition & 0 deletions devblog
Submodule devblog added at dee170
16 changes: 16 additions & 0 deletions post/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
bootJar {
enabled = true
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'

// db
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.h2database:h2'

// Resilience4j
implementation 'io.github.resilience4j:resilience4j-spring-boot3:2.0.2'
implementation 'org.springframework.boot:spring-boot-starter-aop'
}
9 changes: 9 additions & 0 deletions post/src/main/java/com/cnu/post/Advertisement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.cnu.post;

public record Advertisement(
String title,
String description,
String imageUrl,
String siteUrl
) {
}
15 changes: 15 additions & 0 deletions post/src/main/java/com/cnu/post/RealCodingServerApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.cnu.post;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@EnableJpaAuditing
@SpringBootApplication
public class RealCodingServerApplication {

public static void main(String[] args) {
SpringApplication.run(RealCodingServerApplication.class, args);
}

}
30 changes: 30 additions & 0 deletions post/src/main/java/com/cnu/post/client/AdvertisementClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.cnu.post.client;

import com.cnu.post.Advertisement;
import io.github.resilience4j.circuitbreaker.CallNotPermittedException;
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

@Component
public class AdvertisementClient {
RestTemplate restTemplate = new RestTemplate();
private static final Advertisement AD_FALLBACK = new Advertisement(
"Devblog로 개발 블로그를 만들어보자",
"Devblog는 개발자들을 위한 블로그 플랫폼입니다. Devblog로 개발 블로그를 만들어보세요!",
"https://devblog.com/images/og-image.png",
"https://devblog.com"
);

@CircuitBreaker(name = "ad", fallbackMethod = "fallback")
public Advertisement getAd() {
return restTemplate.getForObject(
"http://localhost:9090/ads",
Advertisement.class
);
}

private Advertisement fallback(CallNotPermittedException e) {
return AD_FALLBACK;
}
}
45 changes: 45 additions & 0 deletions post/src/main/java/com/cnu/post/controller/PostController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.cnu.post.controller;

import com.cnu.post.entity.Post;
import com.cnu.post.model.request.PostRequest;
import com.cnu.post.model.response.PostResponse;
import com.cnu.post.service.PostService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/posts")
@RequiredArgsConstructor
public class PostController {
private final PostService postService;

@PostMapping
public ResponseEntity<Post> createPost(@RequestBody PostRequest postRequest) {
return ResponseEntity.ok(postService.createPost(postRequest));
}

@GetMapping
public ResponseEntity<List<Post>> getPosts() {
return ResponseEntity.ok(postService.getPosts());
}
@GetMapping("/{postId}")
public ResponseEntity<PostResponse> getPost(@PathVariable("postId") Integer postId) {
return ResponseEntity.ok(postService.getPost(postId).orElse(null));
}

@PutMapping("/{postId}")
public ResponseEntity<Post> updatePost(@PathVariable("postId") Integer postId,
@RequestBody PostRequest postRequest) {
return ResponseEntity.ok(postService.updatePost(postId, postRequest).orElse(null));
}

@DeleteMapping("/{postId}")
public ResponseEntity<Void> deletePost(@PathVariable("postId") Integer postId) {
postService.deletePost(postId);

return ResponseEntity.noContent().build();
}
}
24 changes: 24 additions & 0 deletions post/src/main/java/com/cnu/post/entity/BaseEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.cnu.post.entity;

import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class BaseEntity {
@Column
@CreatedDate
private LocalDateTime createdAt;

@Column
@LastModifiedDate
private LocalDateTime updatedAt;
}
33 changes: 33 additions & 0 deletions post/src/main/java/com/cnu/post/entity/Post.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.cnu.post.entity;

import com.cnu.post.model.type.Tag;
import jakarta.persistence.*;
import lombok.*;

@Getter
@Entity(name = "posts")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Post extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

@Column
@Setter
private String title;

@Column
@Setter
private String contents;

@Enumerated(EnumType.STRING)
@Setter
private Tag tag;

@Builder
public Post(String title, String contents, Tag tag) {
this.title = title;
this.contents = contents;
this.tag = tag;
}
}
54 changes: 54 additions & 0 deletions post/src/main/java/com/cnu/post/entity/Project.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.cnu.post.entity;

import jakarta.persistence.*;
import lombok.*;

import java.time.LocalDateTime;

@Getter
@Entity(name = "projects")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Project extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

@Column
@Setter
private String title;

@Column
@Setter
private String summary;

@Column
@Setter
private String description;

@Column
@Setter
private LocalDateTime startDate;

@Column
@Setter
private LocalDateTime endDate;

@Column
@Setter
private Boolean isInProgress;

@Builder
private Project(String title,
String summary,
String description,
LocalDateTime startDate,
LocalDateTime endDate,
Boolean isInProgress) {
this.title = title;
this.summary = summary;
this.description = description;
this.startDate = startDate;
this.endDate = endDate;
this.isInProgress = isInProgress;
}
}
24 changes: 24 additions & 0 deletions post/src/main/java/com/cnu/post/model/request/PostRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.cnu.post.model.request;


import com.cnu.post.entity.Post;
import com.cnu.post.model.type.Tag;
import jakarta.validation.Valid;
import lombok.Getter;

@Getter
public class PostRequest {
@Valid
private String title;
private String contents;

private Tag tag;

public Post toEntity() {
return Post.builder()
.title(title)
.contents(contents)
.tag(tag)
.build();
}
}
32 changes: 32 additions & 0 deletions post/src/main/java/com/cnu/post/model/request/ProjectRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.cnu.post.model.request;

import com.cnu.post.entity.Project;
import lombok.Getter;

import java.time.LocalDateTime;

@Getter
public class ProjectRequest {
private String title;

private String summary;

private String description;

private LocalDateTime startDate;

private LocalDateTime endDate;

private Boolean isInProgress;

public Project toEntity() {
return Project.builder()
.title(title)
.summary(summary)
.description(description)
.startDate(startDate)
.endDate(endDate)
.isInProgress(isInProgress)
.build();
}
}
10 changes: 10 additions & 0 deletions post/src/main/java/com/cnu/post/model/response/PostResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.cnu.post.model.response;

import com.cnu.post.Advertisement;
import com.cnu.post.entity.Post;

public record PostResponse(
Post post,
Advertisement advertisement
) {
}
Loading