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
139 changes: 139 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: Deploy to Amazon EC2 using Docker

on:
push:
branches:
- docker

# 본인이 설정한 값을 여기서 채워넣습니다.
# 리전, 버킷 이름, CodeDeploy 앱 이름, CodeDeploy 배포 그룹 이름
env:
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
REPO: chadda-repo

permissions:
contents: read

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production

steps:
# (1) 기본 체크아웃
- name: Checkout
uses: actions/checkout@v3

# (2) JDK 11 세팅
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'

# (3) properties 생성
- name: make application-secret.properties
run: |
echo "ls -a . & pwd"
pwd
ls -a .
echo "mkdir & touch"
mkdir -p ./src/main/resources
cd ./src/main/resources
touch ./application-secret.properties
pwd
ls -a .
echo "copy properties"
echo $DEV_PROP >> ./application-secret.properties
cat application-secret.properties
shell: bash
env:
DEV_PROP: ${{ secrets.JWT_SECRET }}

- name: make application-db-username.properties
run: |
echo "ls -a . & pwd"
pwd
ls -a .
echo "mkdir & touch"
mkdir -p ./src/main/resources
cd ./src/main/resources
touch ./application-db-username.properties
pwd
ls -a .
echo "copy properties"
echo $DEV_PROP >> ./application-db-username.properties
cat application-db-username.properties
env:
DEV_PROP: ${{ secrets.DB_USERNAME }}

- name: make application-db-password.properties
run: |
echo "ls -a . & pwd"
pwd
ls -a .
echo "mkdir & touch"
mkdir -p ./src/main/resources
cd ./src/main/resources
touch ./application-db-password.properties
pwd
ls -a .
echo "copy properties"
echo $DEV_PROP >> ./application-db-password.properties
cat application-db-password.properties
shell: bash
env:
DEV_PROP: ${{ secrets.DB_PASSWORD }}

- name: make application-db-url.properties
run: |
echo "ls -a . & pwd"
pwd
ls -a .
echo "mkdir & touch"
mkdir -p ./src/main/resources
cd ./src/main/resources
touch ./application-db-url.properties
pwd
ls -a .
echo "copy properties"
echo $DEV_PROP >> ./application-db-url.properties
cat application-db-url.properties
shell: bash
env:
DEV_PROP: ${{ secrets.DB_URL }}

# (4) Gradle build (Test 제외)
- name: Build with Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-version: 7.5
arguments: clean build -x test

#(5) Docker Login
- name: Docker Login
run:
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD

#(6) Docker Push
- name: Docker Push
run: |
docker build -t $REPO .
docker tag $REPO:latest $DOCKER_USER/$REPO:latest
docker push $DOCKER_USER/$REPO

#{7} Docker Pull & Run From Hub
- name: Docker Pull & Run From Hub
uses: appleboy/ssh-action@master
with:
host: 3.36.109.80
username: ubuntu
key: ${{secrets.EC2_PRIVATE_KEY}}
envs: GITHUB_SHA
script: |
docker login -u ${{secrets.DOCKER_USER}} -p ${{secrets.DOCKER_PASSWORD}}
docker pull ${{secrets.DOCKER_USER}}/chadda-repo
docker stop chadda_server
docker rm chadda_server
docker run --detach --name chadda_server -p 80:8080 ${{secrets.DOCKER_USER}}/chadda-repo
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM adoptopenjdk/openjdk11
MAINTAINER search363
CMD ["./gradlew","clearn","package"]
ARG JAR_FILE=./build/libs/instagram-searching-0.0.1-SNAPSHOT.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,27 @@ public class RedisConfig {
@Value("${spring.redis.host}")
public String host;

@Value("${spring.redis.password}")
public String password;

@Autowired
public ObjectMapper objectMapper;

@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
redisTemplate.setConnectionFactory(connectionFactory);
return redisTemplate;
}
// @Bean
// public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
// RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
// redisTemplate.setKeySerializer(new StringRedisSerializer());
// redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
// redisTemplate.setConnectionFactory(connectionFactory);
// return redisTemplate;
// }

@Bean
public RedisConnectionFactory redisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName(host);
redisStandaloneConfiguration.setPort(port);
redisStandaloneConfiguration.setPassword(password);
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(redisStandaloneConfiguration);
return connectionFactory;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ spring.jpa.show-sql=true
spring.batch.job.enabled=false

#redis
spring.redis.host=localhost
spring.redis.host=172.17.0.3
spring.redis.port=6379
spring.redis.password=redispw

102 changes: 51 additions & 51 deletions src/test/java/com/search/instagramsearching/PostsTest.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
package com.search.instagramsearching;

import com.search.instagramsearching.repository.PostsRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.util.StopWatch;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
public class PostsTest {
@Autowired
private PostsRepository postsRepository;

private String keyword;

@BeforeEach
void beforeAll(){keyword="dd";}

@Test
void testQuery(){
// given
StopWatch stopWatch = new StopWatch();
Pageable pageable = PageRequest.of(0, 10);

// when
stopWatch.start("검색 쿼리");
postsRepository.search(keyword,pageable);
stopWatch.stop();

// then
System.out.println(stopWatch.prettyPrint());
}

@Test
void testSearchViewQuery(){
// given
StopWatch stopWatch = new StopWatch();
Pageable pageable = PageRequest.of(0, 10);

// when
stopWatch.start("검색 쿼리");
postsRepository.searchView(keyword,pageable);
stopWatch.stop();

// then
System.out.println(stopWatch.prettyPrint());
}
}
//package com.search.instagramsearching;
//
//import com.search.instagramsearching.repository.PostsRepository;
//import org.junit.jupiter.api.BeforeEach;
//import org.junit.jupiter.api.Test;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.data.domain.PageRequest;
//import org.springframework.data.domain.Pageable;
//import org.springframework.util.StopWatch;
//
//@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
//public class PostsTest {
// @Autowired
// private PostsRepository postsRepository;
//
// private String keyword;
//
// @BeforeEach
// void beforeAll(){keyword="dd";}
//
// @Test
// void testQuery(){
// // given
// StopWatch stopWatch = new StopWatch();
// Pageable pageable = PageRequest.of(0, 10);
//
// // when
// stopWatch.start("검색 쿼리");
// postsRepository.search(keyword,pageable);
// stopWatch.stop();
//
// // then
// System.out.println(stopWatch.prettyPrint());
// }
//
// @Test
// void testSearchViewQuery(){
// // given
// StopWatch stopWatch = new StopWatch();
// Pageable pageable = PageRequest.of(0, 10);
//
// // when
// stopWatch.start("검색 쿼리");
// postsRepository.searchView(keyword,pageable);
// stopWatch.stop();
//
// // then
// System.out.println(stopWatch.prettyPrint());
// }
//}