This repository has been archived by the owner on Mar 28, 2020. It is now read-only.
Docker support #6 #17
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e8012f4
Docker support #6
sergeytrasko e1cc251
Docker support #6
sergeytrasko b328787
Docker support #6
sergeytrasko ac28988
Docker support #6
sergeytrasko 54397a7
Docker support #6
sergeytrasko 595cab2
Docker support #6
sergeytrasko 3565fd5
Docker support #6
sergeytrasko 1c70d74
Docker support #6
sergeytrasko File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.idea | ||
*.iml | ||
.git | ||
build | ||
cloud |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Building the image | ||
FROM gradle:4.1-jdk8-alpine as build | ||
|
||
# Gradle image creates a 'gradle' user, so fallback to 'root' to do initial setup | ||
USER root | ||
|
||
RUN mkdir -p /opt/app | ||
WORKDIR /opt/app | ||
|
||
COPY settings.gradle . | ||
COPY api ./api | ||
|
||
# Assemble artifact | ||
RUN gradle clean build | ||
|
||
|
||
# Run the application in a small container | ||
FROM openjdk:8-jre-alpine as runtime | ||
|
||
RUN mkdir -p /opt/app | ||
|
||
WORKDIR /opt/app | ||
|
||
# Take artifact from previous step | ||
COPY --from=build /opt/app/api/build/libs/api.jar . | ||
|
||
# Create new user to run application on behalf of | ||
RUN addgroup -S -g 1001 app \ | ||
&& adduser -D -S -G app -u 1001 -s /bin/ash app \ | ||
&& chown -R app:app /opt/app | ||
|
||
USER app | ||
|
||
EXPOSE 8080 | ||
|
||
# Run as plain jar file | ||
CMD ["java", "-jar", "api.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM gradle:4.1-jdk8-alpine | ||
|
||
# Gradle image creates a 'gradle' user, so fallback to 'root' to do initial setup | ||
USER root | ||
|
||
ENV GRADLE_USER_HOME /opt | ||
|
||
RUN mkdir -p /opt/app | ||
WORKDIR /opt/app | ||
|
||
# Copy gradle build scripts | ||
COPY .env settings.gradle ./ | ||
COPY api/build.gradle api/dotenv.gradle ./api/ | ||
|
||
# Fetch dependencies - do it before copying the source code to cache the layer | ||
RUN ["gradle", "--no-daemon"] | ||
|
||
COPY api api | ||
|
||
ENTRYPOINT ["gradle", "--no-daemon"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ buildscript { | |
ext { | ||
springBootVersion = '1.5.4.RELEASE' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
@@ -15,7 +15,7 @@ buildscript { | |
repositories { | ||
mavenCentral() | ||
} | ||
|
||
apply plugin: 'java' | ||
sourceCompatibility = 1.8 | ||
targetCompatibility = 1.8 | ||
|
@@ -26,6 +26,7 @@ apply from: 'dotenv.gradle' | |
|
||
bootRun() { | ||
environment << dotenv | ||
jvmArgs = ['-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005'] | ||
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. Can we extract this to Dockerfile or docker-compose ? 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. As discussed, there is a option to run the application using gradle from CLI and attach remote debugger from IDE. |
||
} | ||
|
||
dependencies { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: "3" | ||
services: | ||
spring-boot-graphql-template-test: | ||
command: clean test | ||
build: | ||
context: . | ||
dockerfile: Dockerfile.dev | ||
volumes: | ||
- ${PWD}/api:/opt/app/api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: "3" | ||
services: | ||
spring-boot-graphql-template: | ||
command: bootRun | ||
build: | ||
context: . | ||
dockerfile: Dockerfile.dev | ||
volumes: | ||
- ${PWD}/api:/opt/app/api | ||
ports: | ||
- "8080:8080" | ||
- "5005:5005" |
Empty file.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Let's think how we could sync build image specification with production Dockerfile
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.
Any ideas on this?
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.
No idea yet, a head scratcher for me as well!
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.
Ideal case would be to have some kind of includes (see moby/moby#735), however it is not supported by Docker (and not clear if it will be supported).
Other solutions were using e.g. C pre-processors or similar tools to manipulate text files that also seems to be more a workaround.
For sure another alternative is KISS - the less moving parts we have in Dockerfile the less things to keep in sync.
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.
I agree, it’s not that big of a deal, code reviews should help keeping things in sync between the two Dockerfiles