Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Docker support #6 #17

Merged
merged 8 commits into from Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .dockerignore
@@ -0,0 +1,5 @@
.idea
*.iml
.git
build
cloud
21 changes: 21 additions & 0 deletions Dockerfile
@@ -0,0 +1,21 @@
FROM gradle:4.1-jdk8
Copy link
Contributor

@trioletas trioletas Sep 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use gradle:4.1-jdk8-alpine instead ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can. Adjusted.


ENV HOME /home/gradle
Copy link
Contributor

@trioletas trioletas Sep 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is supposed to be a root directory for our application I would use something like /opt/app instead, /home/gradle is a bit misleading because it's not just gradle which is copied there

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted


RUN mkdir -p $HOME/app \
&& cd $HOME/app
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same is achieved with WORKDIR $HOME/app

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed


WORKDIR $HOME/app

USER root
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docker engine runs containers as root by default, is this required?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'gradle' image creates own 'gradle' user and sets it as current user. Therefore switch back to 'root' to do all pre-cooking is required.
Added comment to Dockerfile.dev


COPY settings.gradle .
COPY api ./api

RUN chown -R gradle $HOME/app

USER gradle

EXPOSE 8080

CMD ["gradle", "bootRun"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is gradle really required to run our application? To minimize the image size and reduce the amount of processes running in a container I would suggest that we compile that app first, create an executable jar, then start over from a blank base JDK image and copy only the jar there. This is quite easily achieved with https://docs.docker.com/engine/userguide/eng-image/multistage-build/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted

12 changes: 12 additions & 0 deletions Dockerfile.dev
@@ -0,0 +1,12 @@
FROM gradle:4.1-jdk8

ENV HOME /home/gradle

RUN mkdir -p $HOME/app \
&& cd $HOME/app
WORKDIR $HOME/app

COPY .env .
COPY settings.gradle .

CMD ["gradle", "bootRun"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using ENTRYPOINT instead of CMD to use the same Dockerfile for dev and test, see https://github.com/ctco-dev/nodejs-graphql-template/blob/issue-11-docker/Dockerfile.dev

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, adjusted

12 changes: 12 additions & 0 deletions Dockerfile.test
@@ -0,0 +1,12 @@
FROM gradle:4.1-jdk8

ENV HOME /home/gradle

RUN mkdir -p $HOME/app \
&& cd $HOME/app
WORKDIR $HOME/app

COPY .env .
COPY settings.gradle .

CMD ["gradle", "clean", "test"]
30 changes: 26 additions & 4 deletions README.md
Expand Up @@ -10,9 +10,12 @@ Spring Boot, GraphQL template project with batteries included.
 - Logging level, e.g. `LOGGING_LEVEL_feign=DEBUG`
- App properties, e.g. `APP_DEPENDENCY_API_HOST=example.com`
- See [Spring Boot documentation on relaxed property binding](https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-relaxed-binding)
- Docker :whale: configuration for production deployment, development and test
- Remote debugging for development mode

## Required Software
- JDK 1.8
- Or docker + docker-compose

### Lombok

Expand All @@ -31,23 +34,40 @@ Spring Boot, GraphQL template project with batteries included.

## Develop

1. Create top level `.env` file and add required [key-values](https://docs.oracle.com/cd/E23095_01/Platform.93/ATGProgGuide/html/s0204propertiesfileformat01.html)
1. Create `.env` file

Create top level `.env` file and add required [key-values](https://docs.oracle.com/cd/E23095_01/Platform.93/ATGProgGuide/html/s0204propertiesfileformat01.html)

e.g.:
```
APP_ICNDB_URL=https://api.icndb.com
LOGGING_LEVEL_feign=DEBUG
```

2. `$ gradlew bootRun`
2.1. Run

- Gradle: `$ gradlew bootRun`
- Docker: `$ docker-compose up` (or `$ docker-compose up --build` if image should be rebuilt)

2.2. Debug

Run remote debugger from IDE. Debug port is 5005

## Test

`$ gradlew test`
- Gradle: `$ gradlew test`
- Docker: `$ docker-compose -f docker-compose.test.yml up --build`

## Build

`$ gradlew buld`
- Gradle: `$ gradlew buld`
- Docker: `$ docker build -t spring-boot-graphql-template .`

## Run productive

Assuming that the Docker image is already built on the previous step

- Docker (add `-d` to run in daemon mode): `$ docker run -e 'APP_ICNDB_URL=https://api.icndb.com' -p 8080:8080 spring-boot-graphql-template`

## Tech Stack
- [Spring Boot](https://projects.spring.io/spring-boot/) : Application framework
Expand All @@ -56,6 +76,8 @@ LOGGING_LEVEL_feign=DEBUG
- [GraphQL](http://graphql.org/learn/) : API query runtime
- [GraphQL and GraphiQL Spring Framework Boot Starters](https://github.com/graphql-java/graphql-spring-boot)
- [GraphQL Java Tools](https://github.com/graphql-java/graphql-java-tools)
- Docker
- [Home Page](https://www.docker.com)

## Cloud Deployment

Expand Down
5 changes: 3 additions & 2 deletions api/build.gradle
Expand Up @@ -2,7 +2,7 @@ buildscript {
ext {
springBootVersion = '1.5.4.RELEASE'
}

repositories {
mavenCentral()
}
Expand All @@ -15,7 +15,7 @@ buildscript {
repositories {
mavenCentral()
}

apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand All @@ -26,6 +26,7 @@ apply from: 'dotenv.gradle'

bootRun() {
environment << dotenv
jvmArgs = ['-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we extract this to Dockerfile or docker-compose ?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.
Agree, that it is not very realistic case, but let's keep door open unless we have better solution

}

dependencies {
Expand Down
9 changes: 9 additions & 0 deletions docker-compose.test.yml
@@ -0,0 +1,9 @@
version: "3"
services:
spring-boot-graphql-template-test:
build:
context: .
dockerfile: Dockerfile.test
volumes:
- $HOME/.gradle/caches:/home/gradle/.gradle/caches
- ${PWD}/api:/home/gradle/app/api
12 changes: 12 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,12 @@
version: "3"
services:
spring-boot-graphql-template:
build:
context: .
dockerfile: Dockerfile.dev
volumes:
- $HOME/.gradle/caches:/home/gradle/.gradle/caches
- ${PWD}/api:/home/gradle/app/api
ports:
- "8080:8080"
- "5005:5005"