-
Notifications
You must be signed in to change notification settings - Fork 0
cicd: 로컬 실행 개선 #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cicd: 로컬 실행 개선 #42
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,26 @@ | ||
| # Java 17 | ||
| FROM eclipse-temurin:17-jre | ||
| # Build stage | ||
| FROM eclipse-temurin:17-jdk AS builder | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Gradle wrapper 복사 | ||
| COPY gradlew . | ||
| COPY gradle gradle | ||
| RUN chmod +x gradlew | ||
|
|
||
| # 의존성 캐싱을 위해 build 파일 먼저 복사 | ||
| COPY build.gradle settings.gradle ./ | ||
| RUN ./gradlew dependencies --no-daemon | ||
|
|
||
| # 소스 복사 및 빌드 | ||
| COPY src src | ||
| RUN ./gradlew bootJar --no-daemon | ||
|
|
||
| # Run stage | ||
| FROM eclipse-temurin:17-jre | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY build/libs/batch-0.0.1-SNAPSHOT.jar app.jar | ||
| COPY --from=builder /app/build/libs/*.jar app.jar | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| ENTRYPOINT ["java","-jar","app.jar"] | ||
| ENTRYPOINT ["java", "-jar", "app.jar"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| services: | ||
| batch: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
batch:
build: .
depends_on:
postgres:
condition: service_healthy
mongodb:
condition: service_healthy
... |
||
| build: . | ||
| env_file: | ||
| - path: .env | ||
| required: false | ||
| environment: | ||
| SPRING_PROFILES_ACTIVE: ${SPRING_PROFILES_ACTIVE:-local} | ||
| POSTGRES_HOST: ${POSTGRES_HOST:-postgres} | ||
| POSTGRES_PORT: ${POSTGRES_PORT:-5432} | ||
| POSTGRES_DATABASE: ${POSTGRES_DATABASE:-app} | ||
| POSTGRES_USER: ${POSTGRES_USER:-postgres} | ||
| POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres} | ||
| MONGO_URI: ${MONGO_URI:-mongodb://mongo:mongo@mongodb:27017} | ||
| MONGO_DATABASE: ${MONGO_DATABASE:-app} | ||
| MONGO_USER_NAME: ${MONGO_USER_NAME:-mongo} | ||
| MONGO_PASSWORD: ${MONGO_PASSWORD:-mongo} | ||
| SLACK_WEBHOOK_URL: ${SLACK_WEBHOOK_URL:-} | ||
| entrypoint: ["/bin/sh", "-c", "java -jar app.jar $(date -u +'%Y-%m-%dT%H:%M:%SZ')"] | ||
|
|
||
| # 로컬 DB 컨테이너 (--profile local 옵션 사용 시에만 실행) | ||
| postgres: | ||
| profiles: [local] | ||
| image: postgres:17 | ||
| ports: | ||
| - "5432:5432" | ||
| environment: | ||
| POSTGRES_DB: app | ||
| POSTGRES_USER: postgres | ||
| POSTGRES_PASSWORD: postgres | ||
|
Comment on lines
+27
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
environment:
POSTGRES_DB: ${POSTGRES_DATABASE:-app}
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres} |
||
| volumes: | ||
| - postgres_data:/var/lib/postgresql/data | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready -U postgres"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 5 | ||
|
|
||
| mongodb: | ||
| profiles: [local] | ||
| image: mongo:8.0 | ||
| ports: | ||
| - "27017:27017" | ||
| environment: | ||
| MONGO_INITDB_ROOT_USERNAME: mongo | ||
| MONGO_INITDB_ROOT_PASSWORD: mongo | ||
| MONGO_INITDB_DATABASE: app | ||
|
Comment on lines
+44
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER_NAME:-mongo}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD:-mongo}
MONGO_INITDB_DATABASE: ${MONGO_DATABASE:-app} |
||
| volumes: | ||
| - mongodb_data:/data/db | ||
| healthcheck: | ||
| test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 5 | ||
|
|
||
| volumes: | ||
| postgres_data: | ||
| mongodb_data: | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
빌드 컨텍스트에 불필요한 파일(예:
.gradle,build, IDE 설정 파일)이 포함되지 않도록 프로젝트 루트에.dockerignore파일을 추가하는 것을 강력히 권장합니다. 이렇게 하면 도커 이미지 빌드 시 불필요한 파일들이 Docker 데몬으로 전송되는 것을 막아 빌드 속도를 높이고, 로컬 빌드 결과물이 이미지에 포함되는 것을 방지하여 보다 깔끔하고 예측 가능한 빌드를 보장할 수 있습니다.예시
.dockerignore파일 내용입니다: