Skip to content

Commit

Permalink
Merge branch 'develop' into feat/#9
Browse files Browse the repository at this point in the history
  • Loading branch information
gourderased authored Jun 10, 2024
2 parents 0d9aa95 + d8d8b62 commit 4094876
Show file tree
Hide file tree
Showing 16 changed files with 489 additions and 86 deletions.
103 changes: 103 additions & 0 deletions .github/workflows/ohhanahana-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# 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: Ohhanahana CD Pipeline

on:
push:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest

steps:
# Build를 위한 JDK 설치
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '17'

# 서브모듈을 포함하여 소스 코드 체크아웃
- name: Checkout submodule
uses: actions/checkout@v4
with:
submodules: true
token: ${{ secrets.ACTIONS_TOKEN }}

# 서브모듈을 업데이트
- name: Update submodule
run: |
git submodule update --remote --recursive
# 권한 부여
- name: Grant execute permission for gradlew
run: chmod +x gradlew

# 빌드
- name: Build with Gradle
run: ./gradlew clean build -x test

# Docker 이미지 빌드
- name: Docker image build
run: docker build --build-arg SPRING_PROFILE=main -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPO }}:latest .

# DockerHub 로그인
- name: DockerHub login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

# Docker Hub 이미지 푸시
- name: Docker Hub push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPO }}:latest

# Deploy to EC2
- name: Deploy to EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.SSH_KEY }}
script: |
sudo docker stop $(docker ps -a -q --filter "name=ohhanahana-app") || true
sudo docker rm $(docker ps -a -q --filter "name=ohhanahana-app") || true
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPO }}:latest
docker run -d --name ohhanahana-app -p 8080:8080 -e SPRING_PROFILE=main -e TZ=Asia/Seoul ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPO }}:latest
# # AWS CLI 설치
# - name: Install AWS CLI
# run: |
# sudo apt-get update
# sudo apt-get install -y awscli
#
# - name: Configure AWS credentials
# uses: aws-actions/configure-aws-credentials@v1
# with:
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# aws-region: ${{ secrets.AWS_REGION }}

# # CodeDeploy를 사용하여 EC2에 배포
# - name: Deploy to EC2 using CodeDeploy
# env:
# AWS_REGION: ${{ secrets.AWS_REGION }}
# APPLICATION_NAME: ${{ secrets.CODEDEPLOY_APP_NAME }}
# DEPLOYMENT_GROUP_NAME: ${{ secrets.CODEDEPLOY_GROUP_NAME }}
#
# run: |
# aws deploy create-deployment \
# --application-name $APPLICATION_NAME \
# --deployment-group-name $DEPLOYMENT_GROUP_NAME \
# --deployment-config-name CodeDeployDefault.OneAtATime \
# --description "Deploying the latest Docker image" \
# --region $AWS_REGION
# --revision location=GitHub,repository=${{ github.repository }},commitId=${{ github.sha }}


49 changes: 49 additions & 0 deletions .github/workflows/ohhanahana-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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: Ohhanahana CI Pipeline

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

jobs:
build:

runs-on: ubuntu-latest

steps:

- name: checkout
uses: actions/checkout@v4

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

- name: checkout submodule
uses: actions/checkout@v4
with:
submodules: true
token: ${{ secrets.ACTIONS_TOKEN }}

- name: Update submodule
run: |
git submodule update --remote --recursive
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew

- name: Build with Gradle
run: ./gradlew clean build -x test
env:
SPRING_PROFILES_ACTIVE: main

6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM openjdk:17

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

ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=${SPRING_PROFILE}", "/app.jar"]
14 changes: 14 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#version: 0.0
#os: linux
#files:
# - source: /
# destination: /home/ubuntu/deployment
#hooks:
# BeforeInstall:
# - location: scripts/env.sh
# timeout: 300
# runas: ubuntu
# AfterInstall:
# - location: scripts/deploy.sh
# timeout: 300
# runas: ubuntu
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@ tasks.register('copyGitSubmodule', Copy) {
from './config'
include '*.yml'
into 'src/main/resources'
}
}
//
//tasks.register('copyEnvScript', Copy) {
// from './config'
// include 'env.sh'
// into 'scripts'
//}
18 changes: 18 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
##!/bin/bash
#
## 환경변수 로드
#source /home/ubuntu/deployment/scripts/env.sh
#
#cd /home/ubuntu/deployment
#
## 기존에 실행 중인 컨테이너 중지
#sudo docker stop $(docker ps -a -q --filter "name=ohhanahana-app") || true
#
## 기존에 중지된 컨테이너 삭제
#sudo docker rm $(docker ps -a -q --filter "name=ohhanahana-app") || true
#
## 최신 Docker 이미지 가져오기
#sudo docker pull $DOCKERHUB_USERNAME/$DOCKERHUB_REPO:latest
#
## 새로운 컨테이너 실행
#docker run -d --name ohhanahana-app -p 8080:8080 -e SPRING_PROFILE=main -e TZ=Asia/Seoul $DOCKERHUB_USERNAME/$DOCKERHUB_REPO:latest
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.cloudcomputing.ohhanahana.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import java.nio.charset.StandardCharsets;

@Configuration
public class RestTemplateConfig {

@Bean
public RestTemplate restTemplate() {
RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory());
restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8));
return restTemplate;
}

private ClientHttpRequestFactory clientHttpRequestFactory() {
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
factory.setConnectTimeout(3000);
factory.setReadTimeout(3000);
return factory;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cloudcomputing.ohhanahana.controller;

import com.cloudcomputing.ohhanahana.dto.response.BusResponse;
import com.cloudcomputing.ohhanahana.dto.response.RecommendResponse;
import com.cloudcomputing.ohhanahana.dto.response.ShuttleResponse;
import com.cloudcomputing.ohhanahana.service.BusService;
Expand Down Expand Up @@ -34,4 +35,24 @@ public ResponseEntity<ShuttleResponse> shuttleBus() {
.orElseGet(() -> ResponseEntity.ok(null));
}

@GetMapping
public ResponseEntity<BusResponse> findAllBus() {
try {
BusResponse response = busService.getAllBus(); // 인스턴스를 통해 메서드 호출
return ResponseEntity.ok(response);
} catch (JAXBException e) {
return ResponseEntity.status(500).body(null);
}
}

@GetMapping("/511")
public ResponseEntity<RecommendResponse.Bus> get511Bus() {
try {
RecommendResponse.Bus response = busService.get511Bus();
return ResponseEntity.ok(response);
} catch (JAXBException e) {
return ResponseEntity.status(500).body(null);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.cloudcomputing.ohhanahana.dto.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class BusResponse {
// 셔틀버스
private BusStop shuttle;
// 독정이고개
private BusStop ddg;
// 용현고가교
private BusStop yg;
// 인하대정문
private BusStop inhaFrontGate;


@Getter
@AllArgsConstructor
@NoArgsConstructor
public static class BusStop {
private String busStopName;
private String busStopNumber;
private String busNumber;
private int remainTime;
private int remainBusStop;
private int congestion;
private String des;
private int estimatedTime;
private Boolean isTransfer;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cloudcomputing.ohhanahana.dto.response;

import com.cloudcomputing.ohhanahana.enums.Bus;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
31 changes: 19 additions & 12 deletions src/main/java/com/cloudcomputing/ohhanahana/enums/Bus.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,27 @@
@Getter
@RequiredArgsConstructor
public enum Bus {
B_511("165000073", "511"),
B_13("165000016", "13"),
B_1601("165000154", "1601"),
B_38("165000006", "38"),
B_5_1("165000006", "5-1"),
B_512("165000074", "512"),
B_516("165000078", "516"),
B_519("165000081", "519"),
B_8("165000012", "8"),
B_801("169000027", "801"),
B_8A("165000364", "8A"),
B_31("168000040", "인천e음31")
B_511("165000073", "511", BusStop.YONGHYUN, Destination.JUAN, 20, false),
// B_27("", "27", BusStop.YONGHYUN, Destination.JUAN, 25, true),

B_13("165000016", "13", BusStop.DGG_1, Destination.JUAN, 22, false),
B_38("165000006", "38", BusStop.DGG_1, Destination.JUAN, 16, false),
// B_28_1("", "28-1", BusStop.DGG_2, Destination.JUAN, 15, false),

B_5_1("165000006", "5-1", BusStop.INHA_FRONT_GATE_1, Destination.JUAN, 25, false),
B_516("165000078", "516", BusStop.INHA_FRONT_GATE_1, Destination.JUAN, 30, false),
B_8("165000012", "8", BusStop.INHA_FRONT_GATE_1, Destination.SIMINGONGONE, 20, false),
B_8A("165000364", "8A", BusStop.INHA_FRONT_GATE_1, Destination.SIMINGONGONE, 20, false),

// B_517("", "517", BusStop.INHA_FRONT_GATE_2, Destination.JEMULPO, 20, false),
B_519("165000081", "519", BusStop.INHA_FRONT_GATE_2, Destination.JEMULPO, 20, false),
;
private final String busRouteId;
private final String busNumber;
private final BusStop src;
private final Destination des;
private final int time;
// 환승 여부
private final Boolean isTransfer;

}
12 changes: 5 additions & 7 deletions src/main/java/com/cloudcomputing/ohhanahana/enums/BusStop.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
@RequiredArgsConstructor
public enum BusStop {
INHA_BACK_GATE("163000165", "37165", "인하대후문"),
INHA_FRONT_GATE("163000099", "37099", "인하대정문"),
INHA_SUBWAY_4TH("163000122", "37122", "인하대역4번출구"),
INHA_SUBWAY_7TH("163000091", "37091", "인하대역7번출구"),
DGG("163000234", "37234", "독정이고개"),
YONGHYUN1("163000611", "37611", "용현고가교"),
YONGHYUN2("163000550", "37550", "용현고가교")

INHA_FRONT_GATE_1("163000099", "37099", "인하대정문(1생활관 앞)"),
INHA_FRONT_GATE_2("", "37104", "인하대정문(1생활관 건너편)"),
DGG_1("163000234", "37234", "독정이고개"),
DGG_2("", "37238", "독정이고개"),
YONGHYUN("163000611", "37611", "용현고가교"),
;

private final String busStopId;
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/cloudcomputing/ohhanahana/enums/Destination.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.cloudcomputing.ohhanahana.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum Destination {
JUAN("주안역"),
JEMULPO("제물포역"),
SIMINGONGONE("시민공원역")
;
private final String toKorean;
}
Loading

0 comments on commit 4094876

Please sign in to comment.