-
Notifications
You must be signed in to change notification settings - Fork 0
[ON-96] EC2 환경 Docker 세팅 #20
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
base: develop
Are you sure you want to change the base?
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 | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| # Build stage | ||||||||||||||||||||||||||||||||||||||||||||||||||
| FROM gradle:8.5-jdk17 AS builder | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| WORKDIR /app | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # Copy gradle files | ||||||||||||||||||||||||||||||||||||||||||||||||||
| COPY server/build.gradle server/settings.gradle server/gradlew ./ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| COPY server/gradle ./gradle | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # Copy source code | ||||||||||||||||||||||||||||||||||||||||||||||||||
| COPY server/src ./src | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # Make gradlew executable | ||||||||||||||||||||||||||||||||||||||||||||||||||
| RUN chmod +x ./gradlew | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # Build the application | ||||||||||||||||||||||||||||||||||||||||||||||||||
| RUN ./gradlew bootJar --no-daemon | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # Runtime stage | ||||||||||||||||||||||||||||||||||||||||||||||||||
| FROM eclipse-temurin:17-jre | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| WORKDIR /app | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # Copy the built jar from builder stage | ||||||||||||||||||||||||||||||||||||||||||||||||||
| COPY --from=builder /app/build/libs/*.jar app.jar | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| EXPOSE 8080 | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| ENTRYPOINT ["java", "-jar", "app.jar"] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+20
to
+29
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. 컨테이너가 root 사용자로 실행됩니다 런타임 스테이지에서 non-root 사용자를 지정하지 않아 컨테이너가 root로 실행됩니다. 컨테이너 탈출 취약점 발생 시 호스트에 대한 권한 상승 위험이 있습니다. 🔒 non-root 사용자 추가 제안 FROM eclipse-temurin:17-jre
WORKDIR /app
+RUN addgroup --system appgroup && adduser --system --ingroup appgroup appuser
+
# Copy the built jar from builder stage
COPY --from=builder /app/build/libs/*.jar app.jar
+USER appuser
+
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
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.
🧩 Analysis chain
🏁 Script executed:
Repository: OneBiteArticle/oba_backend
Length of output: 240
🏁 Script executed:
Repository: OneBiteArticle/oba_backend
Length of output: 240
🏁 Script executed:
Repository: OneBiteArticle/oba_backend
Length of output: 240
🏁 Script executed:
Repository: OneBiteArticle/oba_backend
Length of output: 89
🏁 Script executed:
Repository: OneBiteArticle/oba_backend
Length of output: 80
🏁 Script executed:
Repository: OneBiteArticle/oba_backend
Length of output: 802
🏁 Script executed:
Repository: OneBiteArticle/oba_backend
Length of output: 2037
🌐 Web query:
Spring Boot gradle plugin plain jar generation default behavior💡 Result:
bootJaris configured, the plugin disables the standardjartask by default, so a “plain” jar is not produced unless you re-enablejar. [1]jarenabled, but configures it as a separate “plain” artifact by giving it the default classifierplain(so you typically getapp-plain.jaralongside the executablebootJar). You can disable the plain jar by disablingjar, or change classifiers if you don’t want theplainsuffix. [2][3]Common knobs
tasks.named("jar") { enabled = false }[3]plainclassifier (so the plain jar is justapp.jar): setarchiveClassifier = ""onjar(and optionally move a classifier tobootJar). [2][3]Sources: Spring Boot Gradle Plugin reference (2.4) for “jar disabled by default”; Spring Boot Gradle Plugin reference (2.5 / 3.x) for “plain archive” behavior and how to disable or reclassify. [1][2][3]
🌐 Web query:
Docker COPY command multiple files wildcard pattern behavior💡 Result:
<src>inCOPY <src>... <dest>may include wildcards matched using Go’sfilepath.Matchrules (e.g.*,?,[]). This is relative to the build context. [1]<dest>must be a directory and must end with/(e.g.COPY *.png /dest/). [1]<dest>ends with/, Docker treats it as a directory and writes the file as<dest>/<basename(src)>(i.e., it uses the source file’s basename). [1]/” rule, so the same Dockerfile can behave differently across builders. [2]COPY --parents ..., including examples using wildcards (and even**in that mode). [3]Sources:
[1] Dockerfile reference (COPY / pattern matching / multi-source dest rules) — Docker Docs (docs.docker.com)
[2] Buildah issue discussing divergence from Docker’s trailing-slash rule for multi-source COPY (github.com)
[3] Docker blog: Dockerfile v1.7.0 capabilities (
COPY --parents, wildcards,**) (docker.com)Citations:
Docker 빌드 실패: 와일드카드로 인한 다중 JAR 매칭 문제
Spring Boot 3.5.4에서는 기본적으로
bootJar외에도*-plain.jar파일을 생성합니다.COPY --from=builder /app/build/libs/*.jar app.jar명령은 두 개의 JAR 파일과 매칭되는데, 목적지(app.jar)가 디렉토리가 아니므로 Docker 빌드가 실패합니다.server/build.gradle에 다음을 추가하여 plain JAR 생성을 비활성화하거나, Dockerfile의 경로를 더 구체적으로 지정하세요:♻️ build.gradle에 plain JAR 비활성화 추가
🤖 Prompt for AI Agents