Skip to content

Commit fecf949

Browse files
authored
[REFACTOR] profile 설정 및 Github Actions 적용 (#12)
* [REFACTOR] profile 에 따라 properties 파일 분리 * [CHORE] Dockerfile 설정 추가 * [CHORE] Github Actions 파일 작성 * [CHORE] 프로젝트 기본 설정 추가 * [CHORE] Github Actions 폴더 공백 제거 * [CHORE] Github Actions 시 Maven 빌드로 수정 * [CHORE] Github Actions 시 sudo 권한 추가 * [CHORE] Github Actions 시 push 브랜치 변경
1 parent cb09376 commit fecf949

File tree

5 files changed

+91
-3
lines changed

5 files changed

+91
-3
lines changed

.github/workflows/gradle.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Build and Deploy
2+
3+
on:
4+
push:
5+
branches: [ develop ]
6+
7+
jobs:
8+
build-and-deploy:
9+
runs-on: ubuntu-22.04
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v2
14+
15+
- name: Set up JDK 11
16+
uses: actions/setup-java@v3
17+
with:
18+
java-version: '11'
19+
distribution: 'corretto'
20+
21+
- name: Create application.properties
22+
run: |
23+
echo "${{ secrets.APPLICATION_TEST }}" > src/main/resources/application-test.properties
24+
echo "${{ secrets.APPLICATION_LOCAL }}" > src/main/resources/application-local.properties
25+
echo "${{ secrets.APPLICATION_DEV }}" > src/main/resources/application-dev.properties
26+
27+
- name: Build with Maven
28+
run: mvn -e clean package -DskipTests
29+
30+
- name: Docker build and push
31+
run: |
32+
sudo docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }} .
33+
sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
34+
sudo docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }}
35+
36+
- name: Deploy
37+
uses: appleboy/ssh-action@master
38+
with:
39+
host: ${{ secrets.HOST }}
40+
username: ubuntu
41+
key: ${{ secrets.PRIVATE_KEY }}
42+
script: |
43+
# Stop and remove the existing container
44+
sudo docker stop ${{ secrets.DOCKER_CONTAINER_NAME }}
45+
sudo docker rm ${{ secrets.DOCKER_CONTAINER_NAME }}
46+
47+
# Remove the existing image
48+
sudo docker rmi ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }}
49+
50+
# Login
51+
sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
52+
53+
# Pull and run the application container
54+
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_CONTAINER_NAME }}
55+
sudo docker run -d -p 8080:8080 --name ${{ secrets.DOCKER_CONTAINER_NAME }} ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ target
33

44
src/main/resources/secret
55

6-
application.properties
6+
application-*.properties

Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
FROM maven:3.6-jdk-11 as build
3+
4+
# Copy the project files into the container
5+
COPY src /home/app/src
6+
COPY pom.xml /home/app
7+
8+
9+
WORKDIR /home/app
10+
11+
# WAR 파일로 빌드 하면서 테스트 스킵
12+
RUN mvn -e clean package -DskipTests
13+
14+
15+
FROM tomcat:9.0-jdk11-openjdk
16+
17+
# TimeZone 변경
18+
ENV TZ=Asia/Seoul
19+
20+
21+
RUN rm -rf /usr/local/tomcat/webapps/*
22+
23+
24+
ENV WAR_FILE "ROOT.war"
25+
ENV SPRING_PROFILE "dev"
26+
27+
COPY --from=build /home/app/target/*.war /usr/local/tomcat/webapps/${WAR_FILE}
28+
29+
30+
EXPOSE 8080
31+
32+
ENV JAVA_OPTS="-Dspring.profiles.active=${SPRING_PROFILE}"

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
<org.spring-security-version>5.0.6.RELEASE</org.spring-security-version>
1414
<org.aspectj-version>1.9.0</org.aspectj-version>
1515
<org.slf4j-version>1.6.6</org.slf4j-version>
16+
<failOnMissingWebXml>false</failOnMissingWebXml>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1618
</properties>
1719
<dependencies>
1820

src/main/java/com/oya/kr/global/config/RootConfig.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.springframework.context.annotation.PropertySource;
1313
import org.springframework.core.Ordered;
1414
import org.springframework.core.annotation.Order;
15-
import org.springframework.web.client.RestTemplate;
1615
import org.springframework.web.filter.CharacterEncodingFilter;
1716
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
1817

@@ -27,7 +26,7 @@
2726
*/
2827
@Configuration
2928
@ComponentScan(basePackages = {"com.oya.kr"})
30-
@PropertySource("classpath:application.properties")
29+
@PropertySource("classpath:application-${spring.profiles.active}.properties")
3130
@MapperScan(basePackages = {"com.oya.kr"})
3231
@Log
3332
public class RootConfig {

0 commit comments

Comments
 (0)