Skip to content

Commit

Permalink
fix bug / error for Mongo Express and Mongo Compass to connect to Mon…
Browse files Browse the repository at this point in the history
…godb
  • Loading branch information
Dr.Snowbird authored and Dr.Snowbird committed Feb 19, 2019
1 parent d0d7709 commit b2624ed
Show file tree
Hide file tree
Showing 7 changed files with 429 additions and 105 deletions.
21 changes: 5 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ARG VCS_REF=${VCS_REF:-}

#### ---- Product Specifications ----
ENV PRODUCT=${PRODUCT:-"compass"}
ENV PRODUCT_VERSION=${PRODUCT_VERSION:-1.16.3}
ENV PRODUCT_VERSION=${PRODUCT_VERSION:-1.16.4}
ENV PRODUCT_DIR=${PRODUCT_DIR}
ENV PRODUCT_EXE=${PRODUCT_EXE:-mongodb-compass}

Expand All @@ -23,29 +23,23 @@ LABEL org.label-schema.url="https://imagelayers.io" \
org.label-schema.docker.dockerfile="/Dockerfile" \
org.label-schema.description="This utility provides a docker template files for building Docker." \
org.label-schema.schema-version="1.0"

RUN echo PRODUCT=${PRODUCT} && echo HOME=$HOME && \
sudo apt-get install -y gosu firefox

#### --------------------------
#### ---- Install Product ----:
#### --------------------------
# https://downloads.mongodb.com/compass/mongodb-compass-community_1.16.3_amd64.deb
ARG PRODUCT_URL=https://downloads.mongodb.com/${PRODUCT}/mongodb-${PRODUCT}_${PRODUCT_VERSION}_amd64.deb
#RUN sudo wget https://downloads.mongodb.com/compass/mongodb-compass-community_1.16.3_amd64.deb
RUN sudo wget --no-check-certificate ${PRODUCT_URL}
#RUN wget wget https://downloads.mongodb.com/compass/mongodb-compass-community_1.16.3_amd64.deb

RUN sudo apt-get update -y && \
sudo apt-get install -y libsecret-1-0 libgconf-2-4 libnss3 && \
sudo dpkg -i $(basename ${PRODUCT_URL});
sudo wget -q --no-check-certificate ${PRODUCT_URL} && \
sudo dpkg -i $(basename ${PRODUCT_URL}) && \
sudo rm -f $(basename ${PRODUCT_URL})

#### ---- Plugin for Compass ---- ####
#RUN wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash && \
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash

RUN \
export NVM_DIR="$HOME/.nvm" && \
RUN export NVM_DIR="$HOME/.nvm" && \
sudo chown -R ${USER}:${USER} ${HOME} && \
chmod +x .nvm/nvm.sh && $NVM_DIR/nvm.sh && \
#nvm install stable && \
Expand All @@ -55,11 +49,6 @@ RUN \
#cd ${HOME}/.mongodb/${PRODUCT}-community/plugins && khaos create mongodb-js/compass-plugin ./${USER}-plugin && \
#cd ${HOME}/.mongo/compass/plugins

#RUN \
# # [ -s "$NVM_DIR/nvm.sh" ] && \
# /bin/bash -c "$NVM_DIR/nvm.sh"
# # This loads nvm

#### --- Copy Entrypoint script in the container ---- ####
COPY ./docker-entrypoint.sh /

Expand Down
128 changes: 99 additions & 29 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,47 +1,103 @@
#!/bin/bash -x
#!/bin/bash

set -e

# Reference:
# - https://docs.docker.com/engine/userguide/containers/dockerimages/
# - https://github.com/dockerfile/java/blob/master/oracle-java8/Dockerfile

if [ $# -lt 1 ]; then
echo "-------------------------------------------------------------------------------------------"
echo "Usage: "
echo " ${0} [<Dockerfile> <imageTag>]"
echo " ${0} [<Dockerfile> <imageTag> [<some more optional arguments...>] ] "
echo "e.g."
echo " ./build.sh ./centos/Dockerfile.centos.xfce.vnc openkbs/centos-xfce-vnc --no-cache --build-arg OS_TYPE=centos'"
echo " ./build.sh ./Dockerfile.ubuntu.xfce.vnc openkbs/ubuntu-xfce-vnc --no-cache --build-arg OS_TYPE=centos'"
echo "-------------------------------------------------------------------------------------------"
fi

MY_DIR=$(dirname "$(readlink -f "$0")")

DOCKERFILE=${1:-Dockerfile}
DOCKERFILE=${1:-./Dockerfile}
DOCKERFILE=$(realpath $DOCKERFILE)
BUILD_CONTEXT=$(dirname ${DOCKERFILE})

imageTag=${2}

if [ $# -gt 2 ]; then
shift 2
options="$*"
else
options=""
fi

##########################################################
#### ---- Whether to remove previous build cache ---- ####
#### ---- Valid value: 0 (No remove); 1 (yes, remove)
##########################################################
REMOVE_CACHE=0

###############################################################################
###############################################################################
###############################################################################
#### ---- DO NOT Change the code below UNLESS you really want to !!!!) --- ####
#### ---- DO NOT Change the code below UNLESS you really want to !!!!) --- ####
#### ---- DO NOT Change the code below UNLESS you really want to !!!!) --- ####
###############################################################################
###############################################################################
###############################################################################

##########################################################
#### ---- Generate remove cache option if needed ---- ####
##########################################################
REMOVE_CACHE_OPTION=""
if [ ${REMOVE_CACHE} -gt 0 ]; then
REMOVE_CACHE_OPTION="--no-cache --rm"
fi

###################################################
#### ---- Change this only if want to use your own
###################################################
ORGANIZATION=openkbs

###################################################
#### ---- Detect docker ----
#### ---- Detect Docker Run Env files ----
###################################################
DOCKER_ENV_FILE="./.env"
function detectDockerEnvFile() {

function detectDockerBuildEnvFile() {
curr_dir=`pwd`
if [ -s "./.env" ]; then
echo "--- INFO: ./.env Docker Environment file (.env) FOUND!"
DOCKER_ENV_FILE="./.env"
if [ -s "${DOCKER_ENV_FILE}" ]; then
echo "--- INFO: Docker Build Environment file '${DOCKER_ENV_FILE}' FOUND!"
else
echo "--- INFO: ./.env Docker Environment file (.env) NOT found!"
if [ -s "./docker.env" ]; then
DOCKER_ENV_FILE="./docker.env"
echo "*** WARNING: Docker Build Environment file '${DOCKER_ENV_FILE}' NOT found!"
echo "*** WARNING: Searching for .env or docker.env as alternative!"
echo "*** --->"
if [ -s "./docker-build.env" ]; then
echo "--- INFO: ./docker-build.env FOUND to use as Docker Run Environment file!"
DOCKER_ENV_FILE="./docker-build.env"
else
echo "*** WARNING: Docker Environment file (.env) or (docker.env) NOT found!"
if [ -s "./.env" ]; then
echo "--- INFO: ./.env FOUND to use as Docker Run Environment file!"
DOCKER_ENV_FILE="./.env"
else
echo "--- INFO: ./.env Docker Environment file (.env) NOT found!"
if [ -s "./docker.env" ]; then
echo "--- INFO: ./docker.env FOUND to use as Docker Run Environment file!"
DOCKER_ENV_FILE="./docker.env"
else
echo "*** WARNING: Docker Environment file (.env) or (docker.env) NOT found!"
fi
fi
fi
fi
}
detectDockerEnvFile
detectDockerBuildEnvFile

###################################################
#### ---- Container package information ----
###################################################
DOCKER_IMAGE_REPO=`echo $(basename $PWD)|tr '[:upper:]' '[:lower:]'|tr "/: " "_" `
imageTag=${2:-"${ORGANIZATION}/${DOCKER_IMAGE_REPO}"}
imageTag=${imageTag:-"${ORGANIZATION}/${DOCKER_IMAGE_REPO}"}

###################################################
#### ---- Generate build-arg arguments ----
Expand All @@ -55,7 +111,7 @@ BUILD_ARGS="--build-arg BUILD_DATE=${BUILD_DATE} --build-arg VCS_REF=${VCS_REF}"
## -- ignore entries start with "#" symbol --
function generateBuildArgs() {
for r in `cat ${DOCKER_ENV_FILE} | grep -v '^#'`; do
echo "entry=$r"
echo "entry=> $r"
key=`echo $r | tr -d ' ' | cut -d'=' -f1`
value=`echo $r | tr -d ' ' | cut -d'=' -f2`
BUILD_ARGS="${BUILD_ARGS} --build-arg $key=$value"
Expand All @@ -71,31 +127,45 @@ echo "BUILD_ARGS=${BUILD_ARGS}"
# export HTTP_PROXY="http://gatekeeper-w.openkbs.org:80"
# when using "wget", add "--no-check-certificate" to avoid https certificate checking failures
#
HTTP_PROXY_PARAM=
echo "... Setup Docker Build Proxy: ..."
PROXY_PARAM=
function generateProxyArgs() {
if [ "${HTTP_PROXY}" != "" ]; then
HTTP_PROXY_PARAM="--build-arg http_proxy=${HTTP_PROXY} --build-arg https_proxy=${HTTP_PROXY}"
else
HTTP_PROXY_PARAM=
PROXY_PARAM="${PROXY_PARAM} --build-arg HTTP_PROXY=${HTTP_PROXY}"
fi
if [ "${HTTPS_PROXY}" != "" ]; then
PROXY_PARAM="${PROXY_PARAM} --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
fi
if [ "${NO_PROXY}" != "" ]; then
HTTP_PROXY_PARAM="${HTTP_PROXY_PARAM} --build-arg no_proxy=${NO_PROXY}"
else
HTTP_PROXY_PARAM=${HTTP_PROXY_PARAM}
PROXY_PARAM="${PROXY_PARAM} --build-arg NO_PROXY=\"${NO_PROXY}\""
fi
if [ "${http_proxy}" != "" ]; then
PROXY_PARAM="${PROXY_PARAM} --build-arg http_proxy=${http_proxy}"
fi
BUILD_ARGS="${BUILD_ARGS} ${HTTP_PROXY_PARAM}"
if [ "${https_proxy}" != "" ]; then
PROXY_PARAM="${PROXY_PARAM} --build-arg https_proxy=${https_proxy}"
fi
if [ "${no_proxy}" != "" ]; then
PROXY_PARAM="${PROXY_PARAM} --build-arg no_proxy=\"${no_proxy}\""
fi
BUILD_ARGS="${BUILD_ARGS} ${PROXY_PARAM}"
}
generateProxyArgs
echo "BUILD_ARGS=${BUILD_ARGS}"
echo -e "BUILD_ARGS=> \n ${BUILD_ARGS}"
echo

###################################################
#### ---- Buidl Container ----
#### ---- Build Container ----
###################################################

echo "========> imageTag: ${imageTag}"
docker build --rm -t ${imageTag} \
cd ${BUILD_CONTEXT}
set -x
docker build ${REMOVE_CACHE_OPTION} -t ${imageTag} \
${BUILD_ARGS} \
-f `pwd`/${DOCKERFILE} .
${options} \
-f $(basename ${DOCKERFILE}) .
set +x
cd -

echo "----> Shell into the Container in interactive mode: "
echo " docker exec -it --name <some-name> /bin/bash"
Expand Down
2 changes: 0 additions & 2 deletions docker-compose-with-mongo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ services:
environment:
- USER_ID=${USER_ID:-1000}
- GROUP_ID=${GROUP_ID:-1000}
env_file:
- ./docker-compose.env
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix
- ./workspace:/home/developer/workspace
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ services:
environment:
- USER_ID=${USER_ID:-1000}
- GROUP_ID=${GROUP_ID:-1000}
env_file:
- ./docker-compose.env
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix
- ./workspace:/home/developer/workspace
Expand Down
5 changes: 2 additions & 3 deletions docker-run.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#VOLUMES_LIST="data workspace"

#### ---- Mongodb login/password ----
MONGO_INITDB_ROOT_USERNAME=admin-user
MONGO_INITDB_ROOT_PASSWORD=admin-password
MONGO_INITDB_ROOT_USERNAME=admin
MONGO_INITDB_ROOT_PASSWORD=password

#PORTS_LIST=27017:27017
14 changes: 14 additions & 0 deletions docker.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#### Ref: https://vsupalov.com/docker-arg-env-variable-guide/
#### Rider configuration for run.sh ####
# - Use "#VOLUMES" and "#PORTS" to indicate that the variables for run.sh"
# - To ignore line, use "##" (double) in the beginning, e.g. "##VOLUMES" and "##PORTS"
# - To indicate that the variables for run.sh", use only one "#", e.g. "#VOLUMES" and "#PORTS"
## VOLUMES_LIST="./data:data ./workspace:workspace"

#VOLUMES_LIST="data workspace"

#### ---- Mongodb login/password ----
MONGO_INITDB_ROOT_USERNAME=mongoadmin
MONGO_INITDB_ROOT_PASSWORD=mongoadmin

#PORTS_LIST=27017:27017
Loading

0 comments on commit b2624ed

Please sign in to comment.