Skip to content

Instantly share code, notes, and snippets.

@krimple
Last active May 3, 2019 16:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krimple/1596994e570a54076bab061af5cbfd84 to your computer and use it in GitHub Desktop.
Save krimple/1596994e570a54076bab061af5cbfd84 to your computer and use it in GitHub Desktop.
A full-stack Docker configuration with Dockerfiles and docker-compose. Repo and multiple blog posts coming soon. Note - couldn't put directory names in file names, so underscores replace folders.
version: "3.7"
services:
apache:
container_name: quizzo-apache
build:
context: ./apache/
dockerfile: Dockerfile-apache
volumes:
- ${CONFIG_DIR}/apache/httpd.conf:/usr/local/apache2/conf/httpd.conf:ro
- ${CERTS_DIR}:/etc/ssl/crt:ro
networks:
- frontend
links:
- spring:spring
ports:
- 443:443
- 80:80
depends_on:
- player-app
- dashboard-app
- moderator-app
- spring
db:
image: postgres:11.2
restart: always
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB}
networks:
- backend
ports:
- "5432:5432"
volumes:
- type: volume
source: data
target: /var/lib/postgresql/data
- ${PG_BACKUP_DIR}:/var/lib/postgresql/backups
dbadmin:
image: dpage/pgadmin4
restart: always
environment:
- PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL}
- PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD}
networks:
- backend
- frontend
ports:
- "8088:80"
depends_on:
- db
flyway:
image: boxfuse/flyway:6.0.0-beta
command: migrate -X -connectRetries=300
networks:
- backend
volumes:
- ./quizzo-db/migrations:/flyway/sql
- ./quizzo-db/flyway-conf:/flyway/conf
depends_on:
- db
spring:
image: "spring-container"
build: servers/quizzo-graphql-java-server
volumes:
- ${CONFIG_DIR}/spring:/etc/quizzo/spring
ports:
- "8080:8080"
networks:
- backend
- frontend
links:
- db:db
depends_on:
- db
- flyway
moderator-app:
image: moderatorimage
build:
context: ./apps/moderator-app
dashboard-app:
image: dashboardimage
build:
context: ./apps/dashboard-app
player-app:
image: playerimage
build:
context: ./apps/player-app
volumes:
data:
networks:
frontend:
backend:
# This is kinda like Calculus - there are many different ways to do this, some better than this of course.
# In this image we aggregate built container image content from the three apps
# (apps/player-app, apps/moderator-app and apps/dashboard-app)
# and copy them into the Apache httpd image ready to run.
# note the FROM= pointing to other containers build in the docker-compose file for each SPA (playerimage, moderatorimage, dashboardimage)
FROM httpd:2.4.39
RUN mkdir /usr/local/apache2/htdocs/player
WORKDIR /usr/local/apache2/htdocs/player/
RUN mkdir ./static
RUN mkdir ./static/js
RUN mkdir ./static/css
COPY --from=playerimage /app/build/static/js ./static/js/
COPY --from=playerimage /app/build/static/css ./static/css/
COPY --from=playerimage /app/build/*.* ./
run mkdir /usr/local/apache2/htdocs/moderator
WORKDIR /usr/local/apache2/htdocs/moderator/
RUN mkdir ./assets
COPY --from=moderatorimage /app/dist/demo-angular/assets ./assets/
COPY --from=moderatorimage /app/dist/demo-angular/*.* ./
run mkdir /usr/local/apache2/htdocs/dashboard
WORKDIR /usr/local/apache2/htdocs/dashboard/
COPY --from=dashboardimage /app/dist/demo-angular/ ./
# Example of a build for an Angular app (we have two of these)
# The built image contains the production app and is pulled in in the apache Dockerfile build
FROM node:11 as devseed
FROM devseed as toolinstaller
RUN npm install -g @angular/cli yarn
FROM toolinstaller as dependencies-installed
RUN mkdir /app
WORKDIR /app
COPY package.json .
COPY yarn.lock .
RUN yarn install
FROM dependencies-installed
COPY . .
RUN yarn build-prod
# An example "create-react-app" build for our player app
FROM node:11 as devseed
FROM devseed as toolinstaller
RUN npm install -g @angular/cli yarn
FROM toolinstaller as dependencies-installed
RUN mkdir /app
WORKDIR /app
COPY package.json .
COPY yarn.lock .
RUN yarn install
FROM dependencies-installed
COPY . .
RUN npm run-script build
# this is our Spring app server build image. A java app server with Spring and Spring Boot, Spring state machine and
# GraphQL for Java
# see https://medium.com/@sairamkrish/docker-for-spring-boot-gradle-java-micro-service-done-the-right-way-2f46231dbc06
FROM openjdk:11.0-jdk-slim AS BUILD_IMAGE
ENV APP_HOME=/usr/app/
WORKDIR $APP_HOME
COPY build.gradle settings.gradle gradlew $APP_HOME
COPY gradle $APP_HOME/gradle
COPY . .
RUN ./gradlew build --no-daemon || return 0
# Entrypoint: When a container is launched from the image, Spring Boot will look for the properties file in a mapped location
# The docker-compose.yml file maps /etc/quizzo to whatever the config directory is in .env (see snippet of .env below)
# as CONFIG_DIR, so if you deploy to an environment make sure your config settings are available there.
ENTRYPOINT ["./gradlew", "bootRun", "--no-daemon", "-Dspring.config.location=/etc/quizzo/spring/application.properties,classpath:application.properties"]
# this file will contain your external configuration settings such as passwords, etc.
# DO NOT CHECK IT IN TO YOUR SOURCE REPO. Usually you put a .env-sample file in the repo and
# let developers copy to .env and fill in their own settings.
POSTGRES_USER=postgres
POSTGRES_PASSWORD=whateverpassword
POSTGRES_DB=postgres
PG_BACKUP_DIR=../backups
CONFIG_DIR=../config
CERTS_DIR=../config/certs
PGADMIN_DEFAULT_EMAIL=who@you.com
PGADMIN_DEFAULT_PASSWORD=letmein
# For completeness, here is a Spring config file we reference in our Spring Dockerfile
# and map to /etc/quizzo/spring/application.properties
# note- the host name for the database is "db" - the same name given to the service in docker-compose.yml
spring.datasource.url=jdbc:postgresql://db:5432/postgres
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.username=postgres
spring.datasource.password=whateverpasswordyouhave
# GraphQL stuff
graphql.servlet.mapping=/graphql
graphql.servlet.enabled=true
graphql.servlet.corsEnabled=true
grpahql.servlet.exception-handlers-enabled=true
graphiql.mapping=/graphiql
# JWT cookie stuff
jwt.cookie=MyM0therTellMeToNeverE@tCookies
security.jwt.token.secret-key=3245ljaposdfiasudpfiusf or whatever
security.jwt.token.expire-length=3600000
server.error.include-stacktrace=always
# database stuff
spring.data.database=POSTGRES
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
# logging stuff
logging.level.org.springframework=WARN
logging.level.org.springframework.statemachine=DEBUG
logging.level.org.hibernate=WARN
logging.level.com=ERROR
logging.level.com.chariot.quizzographql=INFO
# starts with relevant module loading, look lower for proxy config
...
LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule filter_module modules/mod_filter.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule proxy_html_module modules/mod_proxy_html.so
LoadModule mime_module modules/mod_mime.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule headers_module modules/mod_headers.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
...
# for proxy/reverse proxy
ProxyPreserveHost On
ProxyPass /moderator/graphql http://spring:8080/graphql
ProxyPassReverse /moderator/graphql http://spring:8080/graphql
ProxyPass /dashboard/graphql http://spring:8080/graphql
ProxyPassReverse /dashboard/graphql http://spring:8080/graphql
ProxyPass /player/graphql http://spring:8080/graphql
ProxyPassReverse /player/graphql http://spring:8080/graphql
ProxyPass /graphql http://spring:8080/graphql
ProxyPassReverse /graphql http://spring:8080/graphql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment