Skip to content

Commit

Permalink
Merge branch 'main' into refactor/#317
Browse files Browse the repository at this point in the history
  • Loading branch information
chosim-dvlpr authored Aug 19, 2024
2 parents b931916 + e6f3409 commit 90547ae
Show file tree
Hide file tree
Showing 43 changed files with 573 additions and 294 deletions.
77 changes: 41 additions & 36 deletions .github/workflows/backend_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ on:
paths:
- backend/**

env:
ARTIFACT_NAME: develup-0.0.1-SNAPSHOT
ARTIFACT_DIRECTORY: ./backend/build/libs

jobs:
build:
name: 🏗️ Build Jar and Upload Artifact
name: 🏗️ Build Jar and Upload Docker Image
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend

steps:
- uses: actions/checkout@v4
with:
submodules: true
token: ${{ secrets.SUBMODULE_GITHUB_TOKEN }}

- name: 🏗️ Set up JDK 21
uses: actions/setup-java@v4
with:
Expand All @@ -29,47 +32,49 @@ jobs:
uses: gradle/actions/setup-gradle@v3

- name: 🏗️ Build with Gradle
run: |
cd backend
./gradlew clean bootJar
run: ./gradlew clean bootJar

- name: 🐳 Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: 📤 Upload Artifact File
uses: actions/upload-artifact@v4
- name: 🐳 Docker Image Build and Push
uses: docker/build-push-action@v6
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_DIRECTORY }}/${{ env.ARTIFACT_NAME }}.jar
context: ./backend
push: true
tags: ${{ secrets.DOCKER_REPOSITORY_NAME }}:${{ github.sha }}
platforms: linux/arm64

deploy:
name: 🚀 Server Deployment
needs: build
runs-on: [ self-hosted,develup ]
runs-on: [ self-hosted, develup ]
defaults:
run:
working-directory: backend

env:
BACKEND_APP_IMAGE_NAME: ${{ secrets.DOCKER_REPOSITORY_NAME }}:${{ github.sha }}

steps:
- name: 📥 Download Artifact File
uses: actions/download-artifact@v4
- uses: actions/checkout@v4
- name: 🐳 Login to Docker Hub
uses: docker/login-action@v3
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_DIRECTORY }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: 🔴 Stop Server
run: |
PID=$(sudo lsof -t -i:8080 || true)
if [ -n "$PID" ]; then
sudo kill -15 $PID
tail --pid=$PID -f /dev/null
echo "Server has been stopped. PID: $PID"
else
echo "No server is running."
fi
- name: 🟢 Start Server
run: |
sudo nohup java \
-Dauth.github.client-id=${{ secrets.CLIENT_ID_GITHUB }} \
-Dauth.github.client-secret=${{ secrets.CLIENT_SECRET_GITHUB }} \
-Dspring.profiles.active=dev \
-Dserver.port=8080 \
-jar ${{ env.ARTIFACT_DIRECTORY }}/${{ env.ARTIFACT_NAME }}.jar &
- name: 🐳 Pull Docker Image
run: docker pull ${{ env.BACKEND_APP_IMAGE_NAME }}

- name: 🐳 Docker Compose up
run: docker compose -f compose.yml up -d

- name: 🐳 Clean Unused Image
run: docker image prune -af

slack-notify_success:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "backend/secrets"]
path = backend/secrets
url = https://github.com/woowacourse-teams/2024-devel-up-secret.git
3 changes: 3 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ out/
/nbdist/
/.nb-gradle/

### submoduleyml ###
src/main/resources/application*.yml

### VS Code ###
.vscode/
9 changes: 9 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM openjdk:21

ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar

EXPOSE 8080

ENTRYPOINT ["java", "-Dspring.profiles.active=${SPRING_PROFILE}", \
"-jar", "/app.jar"]
8 changes: 8 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,11 @@ dependencies {
tasks.named('test') {
useJUnitPlatform()
}

processResources.dependsOn('copySecret')

tasks.register('copySecret', Copy) {
from './secrets'
include "application*.yml"
into './src/main/resources'
}
30 changes: 30 additions & 0 deletions backend/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
services:
nginx:
image: nginx
depends_on:
- application
networks:
- nginx-app-net
ports:
- "80:80"
- "443:443"
volumes:
- /home/ubuntu/custom.conf:/etc/nginx/conf.d/default.conf
- /etc/letsencrypt/live/api.devel-up.co.kr/fullchain.pem:/etc/letsencrypt/live/api.devel-up.co.kr/fullchain.pem
- /etc/letsencrypt/live/api.devel-up.co.kr/privkey.pem:/etc/letsencrypt/live/api.devel-up.co.kr/privkey.pem

application:
image: ${BACKEND_APP_IMAGE_NAME}
networks:
- nginx-app-net
ports:
- "8080:8080"
- "8082:8082"
environment:
TZ: "Asia/Seoul"
SPRING_PROFILE: dev
restart: always
container_name: develup-app

networks:
nginx-app-net:
1 change: 1 addition & 0 deletions backend/secrets
Submodule secrets added at 8ad132
30 changes: 30 additions & 0 deletions backend/src/main/java/develup/api/HashTagApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package develup.api;

import java.util.List;
import develup.api.common.ApiResponse;
import develup.application.hashtag.HashTagResponse;
import develup.application.hashtag.HashTagService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Tag(name = "해시태그 API")
class HashTagApi {

private final HashTagService hashTagService;

public HashTagApi(HashTagService hashTagService) {
this.hashTagService = hashTagService;
}

@GetMapping("/hash-tags")
@Operation(summary = "해시태그 목록 조회 API", description = "해시태그 목록을 조회합니다.")
public ResponseEntity<ApiResponse<List<HashTagResponse>>> getHashTags() {
List<HashTagResponse> responses = hashTagService.getHashTags();

return ResponseEntity.ok(new ApiResponse<>(responses));
}
}
7 changes: 5 additions & 2 deletions backend/src/main/java/develup/api/MissionApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand All @@ -26,8 +27,10 @@ public MissionApi(MissionService missionService) {

@GetMapping("/missions")
@Operation(summary = "미션 목록 조회 API", description = "미션 목록을 조회합니다.")
public ResponseEntity<ApiResponse<List<MissionResponse>>> getMissions() {
List<MissionResponse> responses = missionService.getMissions();
public ResponseEntity<ApiResponse<List<MissionResponse>>> getMissions(
@RequestParam(defaultValue = "all") String hashTag
) {
List<MissionResponse> responses = missionService.getMissions(hashTag);

return ResponseEntity.ok(new ApiResponse<>(responses));
}
Expand Down
9 changes: 6 additions & 3 deletions backend/src/main/java/develup/api/SolutionApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand Down Expand Up @@ -53,9 +54,11 @@ public ResponseEntity<ApiResponse<SolutionResponse>> submitSolution(
}

@GetMapping("/solutions")
@Operation(summary = "솔루션 조회 목록 API", description = "솔루션 목록을 조회합니다.")
public ResponseEntity<ApiResponse<List<SummarizedSolutionResponse>>> getSolutions() {
List<SummarizedSolutionResponse> responses = solutionService.getCompletedSummaries();
@Operation(summary = "솔루션 목록 조회 API", description = "솔루션 목록을 조회합니다.")
public ResponseEntity<ApiResponse<List<SummarizedSolutionResponse>>> getSolutions(
@RequestParam(defaultValue = "all") String hashTag
) {
List<SummarizedSolutionResponse> responses = solutionService.getCompletedSummaries(hashTag);

return ResponseEntity.ok(new ApiResponse<>(responses));
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/java/develup/api/SolutionCommentApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import develup.api.common.ApiResponse;
import develup.application.auth.Accessor;
import develup.application.solution.comment.CreateSolutionCommentResponse;
import develup.application.solution.comment.SolutionCommentRepliesResponse;
import develup.application.solution.comment.SolutionCommentRequest;
import develup.application.solution.comment.SolutionCommentService;
import develup.application.solution.comment.SolutionCommentRepliesResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package develup.application.hashtag;

import java.util.List;
import develup.domain.hashtag.HashTagRepository;
import org.springframework.stereotype.Service;

@Service
public class HashTagService {

private final HashTagRepository hashTagRepository;

public HashTagService(HashTagRepository hashTagRepository) {
this.hashTagRepository = hashTagRepository;
}

public List<HashTagResponse> getHashTags() {
return hashTagRepository.findAll().stream()
.map(HashTagResponse::from)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public MissionService(MissionRepository missionRepository, SolutionRepository so
this.solutionRepository = solutionRepository;
}

public List<MissionResponse> getMissions() {
return missionRepository.findAllHashTaggedMission().stream()
public List<MissionResponse> getMissions(String hashTagName) {
return missionRepository.findAllByHashTagName(hashTagName).stream()
.map(MissionResponse::from)
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public SolutionResponse getById(Long id) {
return SolutionResponse.from(solution);
}

public List<SummarizedSolutionResponse> getCompletedSummaries() {
return solutionRepository.findAllCompletedSolution().stream()
public List<SummarizedSolutionResponse> getCompletedSummaries(String hashTagName) {
return solutionRepository.findAllCompletedSolutionByHashTagName(hashTagName).stream()
.map(SummarizedSolutionResponse::from)
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public boolean equals(Object o) {
return false;
}
IdentifiableEntity that = (IdentifiableEntity) o;
return Objects.equals(getId(), that.getId());
return this.getId() != null && Objects.equals(getId(), that.getId());
}

@Override
Expand Down
34 changes: 3 additions & 31 deletions backend/src/main/java/develup/domain/hashtag/HashTag.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
package develup.domain.hashtag;

import java.util.Objects;
import develup.domain.IdentifiableEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;

@Entity
public class HashTag {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
public class HashTag extends IdentifiableEntity {

@Column(nullable = false)
private String name;
Expand All @@ -25,32 +18,11 @@ public HashTag(String name) {
}

public HashTag(Long id, String name) {
this.id = id;
super(id);
this.name = name;
}

public Long getId() {
return id;
}

public String getName() {
return name;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof HashTag hashTag)) {
return false;
}

return this.getId() != null && Objects.equals(getId(), hashTag.getId());
}

@Override
public int hashCode() {
return Objects.hash(getId());
}
}
Loading

0 comments on commit 90547ae

Please sign in to comment.