Skip to content

Commit

Permalink
Merge pull request #45 from one-dream-us/dev
Browse files Browse the repository at this point in the history
뉴스 콘텐츠 상세 조회 에러 수정 & GIthubActions CI/CD 추가
  • Loading branch information
JuJaeng2 authored Jan 16, 2025
2 parents 32f0ee6 + 7eca370 commit 55d60f1
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 60 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Thisismoney deployment actions

on:
push:
branches: [ "main" ]

jobs:
build-project:

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'

# Configure Gradle for optimal use in GiHub Actions, including caching of downloaded dependencies.
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0

- name: Set config file
run: |
echo "${{secrets.APPLICATION_YML}}" | base64 --decode > src/main/resources/application.yml
- name: Build with Gradle Wrapper
run: ./gradlew build -x test
# - name: ls -al
# run: ls -al
# - name: check build file
# run: |
# cd build/libs/
# ls -al
- name: Build docker image
run: |
docker login -u ${{secrets.DOCKER_USER}} -p ${{secrets.DOCKER_PASSWORD}}
docker buildx build --platform linux/amd64 -t ${{secrets.DOCKER_USER}}/thisismoney-app .
docker push ${{secrets.DOCKER_USER}}/thisismoney-app:latest
- name: Excute remote ssh commands & Run App
uses: appleboy/ssh-action@v0.1.6 # ssh 접속하는 오픈소스
with:
host: ${{ secrets.EC2_HOST }} # 인스턴스 IP
username: ${{ secrets.EC2_USER_NAME}} # 우분투 아이디
key: ${{ secrets.PRIVATE_KEY }} # ec2 instance pem key
script: | # 실행할 스크립트
docker login -u ${{secrets.DOCKER_USER}} -p ${{secrets.DOCKER_PASSWORD}}
cd ~/thisismoney
docker-compose down
docker rmi ${{secrets.DOCKER_USER}}/thisismoney-app
docker-compose pull
docker-compose up -d
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ gradle-app.setting
.env

application-dev.yml
application-deploy.yml

Todo.md

Expand Down
9 changes: 5 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
services:
thisismoney-app:
platform: linux/amd64
image: loid3/thisismoney-app:latest
image: jaeyoungjoo/thisismoney-app:latest
container_name: thisismoney-app
expose:
- "8080"
restart: unless-stopped
env_file: .env
env_file: .env # 서버에 따로 .env파일 없으면 제거.
networks:
- app-network

nginx:
platform: linux/amd64
image: loid3/thisismoney-nginx:latest
image: jaeyoungjoo/thisismoney-nginx:latest
container_name: nginx
ports:
- "80:80"
Expand All @@ -22,7 +22,7 @@ services:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
- ./nginx/conf:/etc/nginx/conf.d
- ./certbot/conf:/etc/letsencrypt
- ./certbot/www:/var/www/certbot
- ./certbot/www:/var/www/certbot # 챌린지가 저장될 디렉토리
depends_on:
- thisismoney-app
restart: unless-stopped
Expand All @@ -32,6 +32,7 @@ services:
certbot:
image: certbot/certbot:latest
container_name: certbot
# command: certonly --webroot --webroot-path=/var/www/certbot --email jjy5230@gmail.com --agree-tos --no-eff-email -d api.thisismoney.site
volumes:
- ./certbot/conf:/etc/letsencrypt
- ./certbot/www:/var/www/certbot
Expand Down
4 changes: 2 additions & 2 deletions nginx/default.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
server {
listen 80;
server_name thisismoney.store;
server_name api.thisismoney.site;

location / {
proxy_pass http://thisismoney-app:8080;
Expand All @@ -9,4 +9,4 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ public class NewsDetailResponse {
private String title;
private String newsAgency; // 언론사
private String fullSentence; // 전체 내용 -> 각 문장들을 함친 내용
private String link; // 원문 링크
private List<DictionaryDescriptionDto> descriptions; // 각 문장에 대한 설명

public static NewsDetailResponse from(News news, String fullSentence, List<DictionaryDescriptionDto> descriptions) {
public static NewsDetailResponse from(News news, String fullSentence,
List<DictionaryDescriptionDto> descriptions) {
return NewsDetailResponse.builder()
.title(news.getTitle())
.newsAgency(news.getNewsAgency())
.fullSentence(fullSentence)
.descriptions(descriptions)
.build();
.title(news.getTitle())
.newsAgency(news.getNewsAgency())
.fullSentence(fullSentence)
.descriptions(descriptions)
.link(news.getLink())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ public class News {
private LocalDateTime createdAt;
private Boolean isDeleted;
private String newsAgency;
private String link;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.onedreamus.project.thisismoney.repository;

import com.onedreamus.project.thisismoney.model.entity.Dictionary;
import com.onedreamus.project.thisismoney.model.entity.DictionarySentence;
import com.onedreamus.project.thisismoney.model.entity.Sentence;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
Expand All @@ -12,4 +15,8 @@
public interface DictionarySentenceRepository extends JpaRepository<DictionarySentence, Integer> {

Optional<DictionarySentence> findBySentence(Sentence sentence);

@Query("SELECT ds.dictionary FROM DictionarySentence ds WHERE ds.sentence IN :sentences")
List<Dictionary> findDictionaryBySentenceIn(@Param("sentences") List<Sentence> sentences);

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,19 @@ public CursorResult<NewsListResponse> getNewList(Integer cursor, Integer size) {
}

private NewsListResponse convertToResponse(News news) {
List<String> tags = newsTagRepository.findByNews(news)
.stream()
.map(newsTag -> newsTag.getTag().getValue())
.collect(Collectors.toList());
List<String> tags = new ArrayList<>();

List<Sentence> sentences = sentenceRepository.findByNews(news);
List<Dictionary> dictionaries =
dictionarySentenceRepository.findDictionaryBySentenceIn(sentences);
for (Dictionary dictionary : dictionaries) {
tags.add(dictionary.getTerm()
);
}

Integer viewCount = newsViewRepository.findTotalViewCountByNews(news)
.orElse(0);

String formattedViewCount = NumberFormatter.format(viewCount);

return NewsListResponse.from(news, formattedViewCount, tags);
Expand Down
45 changes: 1 addition & 44 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,3 @@
spring:
application:
name: thisismoney

datasource:
url: ${DB_URL}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
driver-class-name: org.postgresql.Driver

jpa:
hibernate:
ddl-auto: update
# show-sql: true
# properties:
# hibernate:
# format_sql: true

security:
oauth2:
client:
provider:
kakao:
authorization-uri: ${KAKAO_AUTHORIZATION_URI} # 인가 코드 받기 URL
token-uri: ${KAKAO_TOKEN_URI} # 토큰 받기 URL
user-info-uri: ${KAKAO_USER_INFO_URI} # 유저 정보 받기 URL
user-name-attribute: id
registration:
kakao:
client-id: ${KAKAO_CLIENT_ID}
admin-key: 2eae9fe406f06f04c904c133737c7ff0
client-server: # seucurity id
client-authentication-method: ${KAKAO_CLIENT_AUTHENTICATION_METHOD}
redirect-uri: ${KAKAO_REDIRECT_URI}
authorization-grant-type: ${KAKAO_AUTHORIZATION_GRANT_TYPE}
client-name: kakao
scope:
- profile_nickname
- account_email

jwt:
secret-key: ${JWT_SECRET_KEY}
cookie:
domain:
server: thisismoney.site
local: localhost
project: name

0 comments on commit 55d60f1

Please sign in to comment.