Merge pull request #714 from martialblog/docker

Optimise Docker Image
This commit is contained in:
Tomas Bures 2019-10-02 13:19:47 +03:00 committed by GitHub
commit cbf2a6e39d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 7 deletions

View file

@ -1 +1,9 @@
node_modules node_modules/
docs/
Dockerfile
*.md
.git
.gitignore
.gitmodules
docker-compose.yml
docker-compose-local.yml

View file

@ -1,8 +1,12 @@
FROM node:10.14-alpine # Mutistaged Node.js Build
FROM node:10-alpine as builder
RUN apk add --update pwgen netcat-openbsd python make gcc git g++ bash imagemagick # Install system dependencies
RUN set -ex; \
apk add --update --no-cache \
make gcc g++ git
# First install dependencies # Copy package.json dependencies
COPY server/package.json /app/server/package.json COPY server/package.json /app/server/package.json
COPY server/package-lock.json /app/server/package-lock.json COPY server/package-lock.json /app/server/package-lock.json
COPY client/package.json /app/client/package.json COPY client/package.json /app/client/package.json
@ -14,13 +18,29 @@ COPY zone-mta/package-lock.json /app/zone-mta/package-lock.json
WORKDIR /app/ WORKDIR /app/
RUN for idx in client shared server zone-mta; do (cd $idx && npm install); done # Install dependencies in each directory
RUN set -ex; \
for idx in client shared server zone-mta; do (cd $idx && npm install); done
# Later, copy the app files. That improves development speed as buiding the Docker image will not have # Later, copy the app files. That improves development speed as buiding the Docker image will not have
# to download and install all the NPM dependencies every time there's a change in the source code # to download and install all the NPM dependencies every time there's a change in the source code
COPY . /app COPY . /app
RUN cd client && npm run build RUN set -ex; \
cd client && \
npm run build
# Final Image
FROM node:10-alpine
WORKDIR /app/
# Install system dependencies
RUN set -ex; \
apk add --update --no-cache \
pwgen netcat-openbsd bash imagemagick
COPY --from=builder /app/ /app/
EXPOSE 3000 3003 3004 EXPOSE 3000 3003 3004
ENTRYPOINT ["bash", "/app/docker-entrypoint.sh"] ENTRYPOINT ["bash", "/app/docker-entrypoint.sh"]

View file

@ -12,6 +12,9 @@ Optional parameters:
--mongoHost XXX - sets mongo host (default: mongo) --mongoHost XXX - sets mongo host (default: mongo)
--redisHost XXX - sets redis host (default: redis) --redisHost XXX - sets redis host (default: redis)
--mySqlHost XXX - sets mysql host (default: mysql) --mySqlHost XXX - sets mysql host (default: mysql)
--mySqlDatabase XXX - sets mysql database (default: mailtrain)
--mySqlUser XXX - sets mysql user (default: mailtrain)
--mySqlPassword XXX - sets mysql password (default: mailtrain)
--withLdap - use if you want to enable LDAP authentication --withLdap - use if you want to enable LDAP authentication
--ldapHost XXX - LDAP Host for authentication (default: ldap) --ldapHost XXX - LDAP Host for authentication (default: ldap)
--ldapPort XXX - LDAP port (default: 389) --ldapPort XXX - LDAP port (default: 389)
@ -43,6 +46,9 @@ ldapUidTag=""
mongoHost=mongo mongoHost=mongo
redisHost=redis redisHost=redis
mySqlHost=mysql mySqlHost=mysql
mySqlDatabase=mailtrain
mySqlUser=mailtrain
mySqlPassword=mailtrain
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
@ -77,6 +83,18 @@ while [ $# -gt 0 ]; do
mySqlHost="$2" mySqlHost="$2"
shift 2 shift 2
;; ;;
--mySqlDatabase)
mySqlDatabase="$2"
shift 2
;;
--mySqlUser)
mySqlUser="$2"
shift 2
;;
--mySqlPassword)
mySqlPassword="$2"
shift 2
;;
--withLdap) --withLdap)
withLdap=true withLdap=true
shift 1 shift 1
@ -156,6 +174,9 @@ www:
mysql: mysql:
host: $mySqlHost host: $mySqlHost
database: $mySqlDatabase
user: $mySqlUser
password: $mySqlPassword
redis: redis:
enabled: true enabled: true
@ -198,4 +219,5 @@ while ! nc -z $redisHost 6379; do sleep 1; done
while ! nc -z $mongoHost 27017; do sleep 1; done while ! nc -z $mongoHost 27017; do sleep 1; done
cd server cd server
NODE_ENV=production node index.js NODE_ENV=production node index.js