Skip to content
Merged
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
93 changes: 93 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: CI / CD

on:
push:
branches: [main]

jobs:
CI:
runs-on: ubuntu-latest

env:
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
IMAGE_NAME: opendata
IMAGE_TAG: ${{ github.sha }}


steps:
- name: Checkout
uses: actions/checkout@v4

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

- name: Google Cloud SDK 설정
uses: "google-github-actions/auth@v2"
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}

- name: Docker를 위한 gcloud 인증 설정
run: gcloud auth configure-docker --quiet

- name: Grant execute permission for gradlew
run: chmod +x gradlew

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

- name: Build with Gradle(Test 제외)
run: ./gradlew build --exclude-task test

- name: Verify JAR file
run: ls -la build/libs/

- name: Docker 인증 구성
run: gcloud auth configure-docker us-central1-docker.pkg.dev --quiet

- name: Docker 이미지 빌드 및 푸시
run: |
docker build --build-arg SPRING_PROFILE=prod -t us-central1-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/docker/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} .
docker push us-central1-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/docker/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
CD:
runs-on: ubuntu-latest
needs: CI

env:
IMAGE_NAME: opendata
IMAGE_TAG: ${{ github.sha }}
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}

steps:
- name: 서버에 SSH 접속하여 Docker 실행
uses: appleboy/[email protected]
with:
host: ${{ secrets.DEPLOY_SERVER_HOST }}
username: ${{ secrets.DEPLOY_SERVER_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
script: |
IMAGE_NAME=opendata
IMAGE_TAG=${{ github.sha }}
GCP_PROJECT_ID=${{ secrets.GCP_PROJECT_ID }}

sudo docker network create --driver bridge app-network || true

sudo docker stop $IMAGE_NAME || true
sudo docker rm $IMAGE_NAME || true

echo "${{ secrets.GCP_SA_KEY }}" | sudo docker login -u _json_key --password-stdin https://us-central1-docker.pkg.dev
sudo docker pull us-central1-docker.pkg.dev/$GCP_PROJECT_ID/docker/$IMAGE_NAME:$IMAGE_TAG

sudo docker run -d \
--name $IMAGE_NAME \
--network app-network \
-p 8080:8080 \
-e MYSQL_HOST=${{ secrets.MYSQL_HOST }} \
-e MYSQL_DB=${{ secrets.MYSQL_DB }} \
-e MYSQL_USER=${{ secrets.MYSQL_USER }} \
-e MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }} \
-e SEOUL_CITY_DATA_KEY=${{ secrets.SEOUL_CITY_DATA_KEY }} \
-e TOUR_API_TOURSPOT_KEY=${{ secrets.TOUR_API_TOURSPOT_KEY }} \
us-central1-docker.pkg.dev/$GCP_PROJECT_ID/docker/$IMAGE_NAME:$IMAGE_TAG
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM openjdk:21-jdk-slim
COPY ./build/libs/opendata-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app.jar"]
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.opendata.domain.course.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mysql.cj.util.TimeUtil;

import com.opendata.domain.course.entity.CourseComponent;
import com.opendata.domain.tourspot.entity.TourSpot;
import com.opendata.global.util.DateUtil;
import com.opendata.domain.tourspot.entity.enums.CongestionLevel;


import java.time.LocalDateTime;

public record CourseComponentResponse(String tourspotNm,
public record CourseComponentResponse(String tourspotNm, String congestionLevel,
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
LocalDateTime time, Double lat, Double lon) {
public static CourseComponentResponse from(CourseComponent c) {
public static CourseComponentResponse from(CourseComponent c, CongestionLevel level) {
TourSpot tourSpot = c.getTourSpot();
return new CourseComponentResponse(tourSpot.getTourspotNm(), c.getTourspotTm(),
return new CourseComponentResponse(tourSpot.getTourspotNm(),level.getCongestionLabel() ,c.getTourspotTm(),
tourSpot.getAddress().getLatitude(), tourSpot.getAddress().getLongitude());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import com.opendata.domain.course.repository.CourseRepository;
import com.opendata.domain.course.util.CourseUtil;
import com.opendata.domain.tourspot.entity.TourSpot;
import com.opendata.domain.tourspot.entity.TourSpotFutureCongestion;
import com.opendata.domain.tourspot.entity.enums.CongestionLevel;
import com.opendata.domain.tourspot.repository.FutureCongestionRepository;
import com.opendata.domain.tourspot.repository.TourSpotRepository;

import com.opendata.domain.user.repository.UserRepository;
Expand All @@ -30,6 +32,7 @@ public class CourseService {
private final CourseRepository courseRepository;
private final CourseMapper courseMapper;
private final TourSpotRepository tourSpotRepository;
private final FutureCongestionRepository futureCongestionRepository;
private final UserRepository userRepository;


Expand All @@ -54,7 +57,18 @@ public List<List<CourseComponentResponse>> recommendCourses(double userLat, doub

return resultCourses.stream()
.map(course -> course.stream()
.map(CourseComponentResponse::from)
.map(component -> {
Long spotId = component.getTourSpot().getTourspotId();
LocalDateTime time = component.getTourspotTm();

// 혼잡도 조회
Optional<TourSpotFutureCongestion> congestion =
futureCongestionRepository.findByTourSpotIdAndFcstTime(spotId, time.format(formatter));

CongestionLevel level = congestion.get().getCongestionLvl();;

return CourseComponentResponse.from(component, level);
})
.toList())
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class TourSpotFutureCongestion extends TourSpotAssociated {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long futureCongestionId;
private Long realTimeCongestionId;

private String fcstTime;

Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
spring:
datasource:
url: jdbc:mysql://localhost:3306/opendata
username: root
password: keypass
url: jdbc:mysql://${MYSQL_HOST}:3306/${MYSQL_DB}
username: ${MYSQL_USER}
password: ${MYSQL_PASSWORD}
driver-class-name: com.mysql.cj.jdbc.Driver

jpa:
Expand Down Expand Up @@ -42,8 +42,8 @@ server:


api:
seoul_city_data_key: 65727076703838343130386d59744e75
tour_api_tourspot_key: C%2BZxoazvjZCUicHi%2BY4x7w4Q1GE9RUKUKiHCkZhYMEdbdqiiHnRV%2F2%2F3%2BhggbEfMSL4R4qgGeSR1BdLrPMmjAw%3D%3D
seoul_city_data_key: ${SEOUL_CITY_DATA_KEY}
tour_api_tourspot_key: ${TOUR_API_TOURSPOT_KEY}
tour_api_congestion_key: B4FraEdNAEHerMG6ZQUi5OXCzio%2FQJ4IRx9rOOz7%2BeiPBh4L8pX4XAygutNaYnOoL%2BD8vS%2F3qZ53efN6daHZ%2Fg%3D%3D
zz: wabF%2F2ep3dqrmXQcTNupVTpQXrL3wBuOK1TSRhAo8mwZ9Wqop4GCNUXkqSdf4%2Bwxa1%2FdOCkfmbBXYQL13wlwKQ%3D%3D
xx: J28I%2B2X%2FLQ8vHJaw2Yorr492RFOq2%2FRBGCkl1hVMJCu65fNG5xDvDi7GazJpx3ZKa9xb4fYhq14vtXjWSaHrSw%3D%3D
Expand Down