Skip to content

Commit

Permalink
Merge pull request #92 from georg-schwarz/travis-ci
Browse files Browse the repository at this point in the history
Dockerization and TravisCI
  • Loading branch information
dirkriehle authored Oct 14, 2019
2 parents 4906b54 + 47c7545 commit e9c8d47
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 18 deletions.
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
language: bash

services:
- docker

env:
global:
- IMAGE_NAME=${DOCKERHUB_USER}/wahlzeit
- IMAGE_NAME_TAGGED=${DOCKERHUB_USER}/wahlzeit:${TRAVIS_TAG}

script:
- docker build -t ${IMAGE_NAME} .

deploy:
- provider: script
script:
docker login -u ${DOCKERHUB_USER} -p ${DOCKERHUB_PW} && docker push ${IMAGE_NAME}
on:
branch: master

- provider: script
script: docker login -u ${DOCKERHUB_USER} -p ${DOCKERHUB_PW} && docker tag ${IMAGE_NAME} ${IMAGE_NAME_TAGGED} && docker push ${IMAGE_NAME_TAGGED}
on:
tags: true
42 changes: 42 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#########################################################
# First stage: image to build the application #
#########################################################
FROM adoptopenjdk/openjdk8-openj9:alpine-slim as builder

WORKDIR /builder

# Copy Gradle file
COPY *.gradle /builder/

# Copy sources
COPY src /builder/src

# Copy Gradle resources
COPY gradle /builder/gradle
COPY gradlew /builder/gradlew

# Test project
RUN ./gradlew test

# Build project (downloads Appengine SDK + builds + explode WAR)
RUN ./gradlew appengineExplodeApp

#########################################################
# Second stage: image to run the application #
#########################################################
FROM adoptopenjdk/openjdk8-openj9:alpine-slim

RUN mkdir /app
WORKDIR /app

# Pull the built files from the builder container
COPY --from=builder /builder/build /app/build

# Pull the Appengine SDK from the builder container
COPY --from=builder /root/.gradle/appengine-sdk/appengine-java-sdk-1.9.76/ /root/.gradle/appengine-sdk/appengine-java-sdk-1.9.76/

# Expose port
EXPOSE 8080

# Do the same as ./gradlew appengineRun for starting the dev server
ENTRYPOINT ["/opt/java/openjdk/bin/java", "-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000", "-Dfile.encoding=UTF-8", "-classpath", "/root/.gradle/wrapper/dists/gradle-4.10-bin/bg6py687nqv2mbe6e1hdtk57h/gradle-4.10/lib/gradle-launcher-4.10.jar:/root/.gradle/appengine-sdk/appengine-java-sdk-1.9.76/lib/appengine-tools-api.jar", "com.google.appengine.tools.development.DevAppServerMain", "--property=kickstart.user.dir=/app", "--no_java_agent", "--port=8080", "--address=localhost", "--allow_remote_shutdown", "/app/build/exploded-app"]
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@ For more information, please see http://github.com/dirkriehle/wahlzeit and http:


### Run Wahlzeit inside a Docker container
1. Run ```./runInDocker.sh appengineRun```
2. Or with another Gradle task as argument, e.g. ```./runInDocker.sh test```
1. Build the Docker image ``docker-compose build`` or ``docker build -t wahlzeit .``
2. Run the Docker container ``docker-compose up`` or ``docker run --network=host -p 8080:8080 wahlzeit``
3. Open [``http://localhost:8080``](http://localhost:8080) to try out Wahlzeit inside a Docker container


### Activate Travis CI
1. Sign in to Travis CI
2. Activate the repository
3. Add the following environment variables: `DOCKERHUB_USER` and `DOCKERHUB_PW` matching your credentials for DockerHub

Every pushed commit on master will publish and overwrite the `wahlzeit:latest` image. Every tagged commit will publish and overwrite the `wahlzeit:{tag-name}` image.

### Deploy Wahlzeit to Google App Engine

**Create a Google App Engine instance:**
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3.7'

services:
wahlzeit:
image: wahlzeit
build:
context: .
ports:
- "8080:8080"
network_mode: host
15 changes: 0 additions & 15 deletions runInDocker.sh

This file was deleted.

22 changes: 22 additions & 0 deletions simple.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM adoptopenjdk/openjdk8-openj9:alpine-slim as builder

# Copy Gradle file
COPY *.gradle /app/

# Copy sources
COPY src /app/src

# Copy Gradle resources
COPY gradle /app/gradle
COPY gradlew /app/gradlew

WORKDIR /app

# Test project
RUN ./gradlew test

# Expose port
EXPOSE 8080

# Build & Run project (downloads Appengine SDK + builds + starts Dev Server)
CMD ./gradlew appengineRun

0 comments on commit e9c8d47

Please sign in to comment.