Skip to content

Commit

Permalink
Merge pull request #70 from Kookmin-Contest/prepare-to-change-this-re…
Browse files Browse the repository at this point in the history
…pository-public

환경변수 주입으로 민감정보 가리기
  • Loading branch information
sukjuhong authored Sep 24, 2023
2 parents 88bc410 + d1d4d90 commit a5c650e
Show file tree
Hide file tree
Showing 88 changed files with 639 additions and 430 deletions.
11 changes: 11 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
MYSQL_DATABASE=
MYSQL_USERNAME=
MYSQL_PASSWORD=
JWT_ACCESS_SECRET_KEY=
JWT_REFRESH_SECRET_KEY=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
NAVER_CLIENT_ID=
NAVER_CLIENT_SECRET=
KAKAO_CLIENT_ID=
KAKAO_CLIENT_SECRET=
12 changes: 5 additions & 7 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,25 @@ jobs:
uses: docker/build-push-action@v4
with:
context: .
file: ./dev.Dockerfile
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/tdwork-api-server:latest
tags: hsukju00/towork-api

- name: Upload docker-compose.dev.yml
uses: actions/upload-artifact@v3
with:
name: docker-artifact
path: |
docker-compose.dev.yml
.platform
docker-compose.yml
deploy:
needs:
- build

runs-on: ubuntu-latest

steps:
- name: Download docker-compose.dev.yml
- name: Download docker-compose.yml
uses: actions/download-artifact@v3
with:
name: docker-artifact
Expand All @@ -71,7 +70,6 @@ jobs:
scp ./docker-compose.dev.yml ${{ secrets.SSH_USER }}@${{ secrets.SERVER_IP }}:~/docker-compose.yml
scp -r .platform ${{ secrets.SSH_USER }}@${{ secrets.SERVER_IP }}:~/
- name: Execute remote commands
run: |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SERVER_IP }} "sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/tdwork-api-server"
Expand Down
28 changes: 0 additions & 28 deletions .github/workflows/test.yml

This file was deleted.

3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ build/
!**/src/main/**/build/
!**/src/test/**/build/
src/main/generated
.env
.volumes
.secret


### STS ###
.apt_generated
Expand Down
26 changes: 21 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
FROM openjdk:17-jdk-slim
WORKDIR /app
ARG JAR_FILE=build/libs/*.jar
COPY $JAR_FILE ./app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]
# syntax=docker/dockerfile:1
FROM eclipse-temurin:17-jdk-alpine AS build
WORKDIR /workspace/app

COPY . .

RUN chmod +x ./gradlew
RUN --mount=type=cache,target=/root/.gradle ./gradlew --no-daemon clean bootJar
RUN mkdir -p build/dependency && (cd build/dependency; jar -xf ../libs/*-SNAPSHOT.jar)

FROM eclipse-temurin:17-jdk-alpine
VOLUME /tmp
ARG DEPENDENCY=/workspace/app/build/dependency
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app

COPY ./scripts/docker-spring-entrypoint.sh /scripts/docker-spring-entrypoint.sh
RUN chmod +x /scripts/docker-spring-entrypoint.sh

ENTRYPOINT ["java","-cp","app:app/lib/*","com.towork.api.ApiApplication"]
9 changes: 2 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ plugins {

group = 'com.backend'
version = '0.0.1-SNAPSHOT'
jar.enabled = false

java {
sourceCompatibility = '17'
Expand All @@ -29,19 +28,15 @@ dependencies {
// WebFlux: MVC와 다른 방식으로 요청을 처리
implementation 'org.springframework.boot:spring-boot-starter-webflux'

// application.yml 자동완성
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'

// security
implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.security:spring-security-test'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'

// validation
implementation 'org.springframework.boot:spring-boot-starter-validation'

// debug
implementation 'org.springframework.boot:spring-boot-starter-actuator'
developmentOnly "org.springframework.boot:spring-boot-devtools"

// docs
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0'
Expand Down Expand Up @@ -72,10 +67,10 @@ dependencies {

// test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation "org.junit.jupiter:junit-jupiter:5.8.1"
testImplementation "org.testcontainers:junit-jupiter:1.18.3"
testImplementation 'org.testcontainers:testcontainers:1.18.3'
testImplementation "org.testcontainers:mysql:1.18.3"

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ server {
listen 80;

location / {
proxy_pass http://api-server:8080;
proxy_pass http://spring:8080;
}
}
14 changes: 0 additions & 14 deletions dev.Dockerfile

This file was deleted.

48 changes: 0 additions & 48 deletions docker-compose.dev.yml

This file was deleted.

43 changes: 34 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@ services:

mysql:
container_name: mysql
image: mysql:latest
image: mysql:8.1.0
ports:
- "3306:3306"
networks:
- towork-api-network
restart: unless-stopped
volumes:
- mysql_data:/var/lib/mysql
environment:
TZ: Asia/Seoul
LC_ALL: C.UTF-8
LANG: C.UTF-8
MYSQL_ROOT_PASSWORD: 12345678@
MYSQL_DATABASE: backend
TZ: Asia/Seoul"
MYSQL_USER: ${MYSQL_USERNAME}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_RANDOM_ROOT_PASSWORD: yes
command:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
interval: 5s
Expand All @@ -21,25 +29,42 @@ services:

redis:
container_name: redis
image: redis:latest
image: redis:7.2.0-alpine
ports:
- "6379:6379"
networks:
- towork-api-network
restart: unless-stopped
volumes:
- redis_data:/data
healthcheck:
test: ["CMD-SHELL", "redis-cli ping | grep PONG"]
interval: 5s
timeout: 3s
retries: 10


api-server:
container_name: api-server
spring:
container_name: spring
build:
context: .
dockerfile: ./Dockerfile
image: hsukju00/towork-api
env_file:
- .env
ports:
- "8080:8080"
networks:
- towork-api-network
depends_on:
mysql:
condition: service_healthy
redis:
condition: service_healthy

networks:
towork-api-network:

volumes:
mysql_data:
redis_data:
Empty file modified gradlew
100755 → 100644
Empty file.
11 changes: 6 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# 로컬 실행 방법
# 오늘의 출근 Backend

## 빌드

먼저 `.env.template`를 복사하여 `.env`를 생성한 뒤 환경변수를 적어 넣는다.

```shell
./gradlew bootJar
docker-compose up --build -d
```
gradlew를 이용하여 build하고
docker를 이용해 mysql, redis와 함께 서버를 올린다.
```
5 changes: 5 additions & 0 deletions scripts/docker-spring-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ENV_FILE=".env"

if test -f "$ENV_FILE"; then
export "$(grep -v '^#' .env | xargs -d '\n')"
fi
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.backend.towork;
package com.towork.api;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@EnableJpaAuditing
@SpringBootApplication
public class ToworkApplication {
public class ApiApplication {

public static void main(String[] args) {
SpringApplication.run(ToworkApplication.class, args);
SpringApplication.run(ApiApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.backend.towork.auth.controller;
package com.towork.api.auth.controller;

import com.backend.towork.global.error.ErrorResponse;
import com.backend.towork.auth.domain.dto.request.DuplicateEmailRequestDto;
import com.backend.towork.auth.domain.dto.request.LoginRequestDto;
import com.backend.towork.member.domain.dto.request.MemberRequestDto;
import com.backend.towork.auth.domain.dto.request.ReissueRequestDto;
import com.backend.towork.auth.domain.dto.response.TokenResponseDto;
import com.backend.towork.auth.service.AuthService;
import com.towork.api.global.error.ErrorResponse;
import com.towork.api.auth.domain.dto.request.DuplicateEmailRequestDto;
import com.towork.api.auth.domain.dto.request.LoginRequestDto;
import com.towork.api.member.domain.dto.request.MemberRequestDto;
import com.towork.api.auth.domain.dto.request.ReissueRequestDto;
import com.towork.api.auth.domain.dto.response.TokenResponseDto;
import com.towork.api.auth.service.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.backend.towork.auth.domain.dto.request;
package com.towork.api.auth.domain.dto.request;

import jakarta.validation.constraints.Email;
import lombok.Getter;
Expand Down
Loading

0 comments on commit a5c650e

Please sign in to comment.