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

Commit

Permalink
Docker support #6 (#17)
Browse files Browse the repository at this point in the history
closes #6
  • Loading branch information
sergeytrasko authored and trioletas committed Oct 5, 2017
1 parent 4bfe507 commit afc04ea
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
@@ -0,0 +1,5 @@
.idea
*.iml
.git
build
cloud
37 changes: 37 additions & 0 deletions Dockerfile
@@ -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"]
20 changes: 20 additions & 0 deletions Dockerfile.dev
@@ -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"]
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
1 change: 1 addition & 0 deletions api/build.gradle
Expand Up @@ -26,6 +26,7 @@ apply from: 'dotenv.gradle'

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

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:
command: clean test
build:
context: .
dockerfile: Dockerfile.dev
volumes:
- ${PWD}/api:/opt/app/api
12 changes: 12 additions & 0 deletions docker-compose.yml
@@ -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 modified gradlew 100644 → 100755
Empty file.

0 comments on commit afc04ea

Please sign in to comment.