From 29483bab8c7e319186020de6c401ee5e47b89a3c Mon Sep 17 00:00:00 2001 From: ahkui <14049597+ahkui@users.noreply.github.com> Date: Fri, 13 Jul 2018 11:33:41 +0800 Subject: [PATCH 1/8] Add Ipython (#1685) --- docker-compose.yml | 22 ++++++++++++++++++++++ env-example | 3 +++ ipython/Dockerfile.controller | 17 +++++++++++++++++ ipython/Dockerfile.engine | 23 +++++++++++++++++++++++ ipython/ipcontroller-client.json | 16 ++++++++++++++++ ipython/ipcontroller-engine.json | 16 ++++++++++++++++ 6 files changed, 97 insertions(+) create mode 100644 ipython/Dockerfile.controller create mode 100644 ipython/Dockerfile.engine create mode 100644 ipython/ipcontroller-client.json create mode 100644 ipython/ipcontroller-engine.json diff --git a/docker-compose.yml b/docker-compose.yml index 2e6a7ea5..71ffa068 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -717,9 +717,31 @@ services: volumes: - ${DATA_PATH_HOST}/portainer_data:/data - /var/run/docker.sock:/var/run/docker.sock + extra_hosts: + - "dockerhost:${DOCKER_HOST_IP}" ports: - 9010:9000 +### IPython ######################################### + ipython-controller: + build: + context: ./ipython + dockerfile: Dockerfile.controller + networks: + - backend + extra_hosts: + - "laradock-ipython:${LARADOCK_IPYTHON_CONTROLLER_IP}" + ports: + - "33327-33338:33327-33338" + ipython-engine: + build: + context: ./ipython + dockerfile: Dockerfile.engine + networks: + - backend + extra_hosts: + - "laradock-ipython:${LARADOCK_IPYTHON_CONTROLLER_IP}" + ### Docker-in-Docker ################################################ docker-in-docker: image: docker:dind diff --git a/env-example b/env-example index 25ebcb7e..f9325ce8 100644 --- a/env-example +++ b/env-example @@ -360,6 +360,9 @@ SOLR_VERSION=5.5 SOLR_PORT=8983 SOLR_DATAIMPORTHANDLER_MYSQL=false +### IPYTHON ################################################## +LARADOCK_IPYTHON_CONTROLLER_IP=127.0.0.1 + ### NETDATA ############################################### NETDATA_PORT=19999 diff --git a/ipython/Dockerfile.controller b/ipython/Dockerfile.controller new file mode 100644 index 00000000..3acb62d9 --- /dev/null +++ b/ipython/Dockerfile.controller @@ -0,0 +1,17 @@ +FROM python:3.5-alpine + +LABEL maintainer="ahkui " + +USER root + +RUN apk add --no-cache build-base + +RUN python -m pip --quiet --no-cache-dir install \ + ipyparallel + +RUN ipython profile create --parallel --profile=default + +COPY ipcontroller-client.json /root/.ipython/profile_default/security/ipcontroller-client.json +COPY ipcontroller-engine.json /root/.ipython/profile_default/security/ipcontroller-engine.json + +CMD ["sh","-c","ipcontroller --ip=* --reuse"] \ No newline at end of file diff --git a/ipython/Dockerfile.engine b/ipython/Dockerfile.engine new file mode 100644 index 00000000..5f709b61 --- /dev/null +++ b/ipython/Dockerfile.engine @@ -0,0 +1,23 @@ +FROM python:3.5-alpine + +LABEL maintainer="ahkui " + +USER root + +RUN apk add --no-cache build-base + +RUN python -m pip --quiet --no-cache-dir install \ + ipyparallel \ + numpy \ + pandas \ + pymongo \ + redis \ + requests \ + bs4 + +RUN ipython profile create --parallel --profile=default + +COPY ipcontroller-client.json /root/.ipython/profile_default/security/ipcontroller-client.json +COPY ipcontroller-engine.json /root/.ipython/profile_default/security/ipcontroller-engine.json + +CMD ["sh","-c","ipcluster engines"] diff --git a/ipython/ipcontroller-client.json b/ipython/ipcontroller-client.json new file mode 100644 index 00000000..987cb511 --- /dev/null +++ b/ipython/ipcontroller-client.json @@ -0,0 +1,16 @@ +{ + "key": "868074dd-060311910ab3d6991611bccf", + "signature_scheme": "hmac-sha256", + "unpack": "json", + "pack": "json", + "ssh": "", + "task_scheme": "leastload", + "interface": "tcp://*", + "location": "laradock-ipython", + "notification": 33338, + "iopub": 33337, + "control": 33336, + "mux": 33335, + "task": 33334, + "registration": 33333 +} \ No newline at end of file diff --git a/ipython/ipcontroller-engine.json b/ipython/ipcontroller-engine.json new file mode 100644 index 00000000..d3c0911f --- /dev/null +++ b/ipython/ipcontroller-engine.json @@ -0,0 +1,16 @@ +{ + "key": "868074dd-060311910ab3d6991611bccf", + "signature_scheme": "hmac-sha256", + "unpack": "json", + "pack": "json", + "ssh": "", + "interface": "tcp://*", + "location": "laradock-ipython", + "iopub": 33327, + "hb_ping": 33328, + "hb_pong": 33329, + "control": 33330, + "mux": 33331, + "task": 33332, + "registration": 33333 +} \ No newline at end of file From dc234b9b28443db4690170067281740fc4c7f368 Mon Sep 17 00:00:00 2001 From: ahkui <14049597+ahkui@users.noreply.github.com> Date: Fri, 13 Jul 2018 11:35:46 +0800 Subject: [PATCH 2/8] Add Jupyterhub (#1686) --- docker-compose.yml | 35 +++++ env-example | 14 ++ jupyterhub/Dockerfile | 26 ++++ jupyterhub/Dockerfile.user | 72 +++++++++++ jupyterhub/jupyterhub_config.py | 121 ++++++++++++++++++ jupyterhub/start-notebook.sh | 12 ++ jupyterhub/start-singleuser.sh | 40 ++++++ jupyterhub/start.sh | 7 + jupyterhub/userlist | 1 + .../docker-entrypoint-initdb.d/.gitignore | 1 + .../init_jupyterhub_db.sh | 41 ++++++ 11 files changed, 370 insertions(+) create mode 100644 jupyterhub/Dockerfile create mode 100644 jupyterhub/Dockerfile.user create mode 100644 jupyterhub/jupyterhub_config.py create mode 100644 jupyterhub/start-notebook.sh create mode 100644 jupyterhub/start-singleuser.sh create mode 100644 jupyterhub/start.sh create mode 100644 jupyterhub/userlist create mode 100644 postgres/docker-entrypoint-initdb.d/init_jupyterhub_db.sh diff --git a/docker-compose.yml b/docker-compose.yml index 71ffa068..2474f999 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -722,6 +722,41 @@ services: ports: - 9010:9000 +### JupyterHub ######################################### + jupyterhub: + build: + context: ./jupyterhub + depends_on: + - postgres + - jupyterhub-user + restart: always + volumes: + - /var/run/docker.sock:/var/run/docker.sock:rw + - ${DATA_PATH_HOST}/jupyterhub/:/data + - ${JUPYTERHUB_CUSTOM_CONFIG}:/jupyterhub_config.py + - ${JUPYTERHUB_USER_DATA}:/user-data + - ${JUPYTERHUB_USER_LIST}:/userlist + networks: + - backend + ports: + - "${JUPYTERHUB_PORT}:80" + environment: + - TERM=xterm + - JUPYTERHUB_USER_DATA=${JUPYTERHUB_USER_DATA} + - JUPYTERHUB_POSTGRES_DB=${JUPYTERHUB_POSTGRES_DB} + - JUPYTERHUB_POSTGRES_USER=${JUPYTERHUB_POSTGRES_USER} + - JUPYTERHUB_POSTGRES_HOST=${JUPYTERHUB_POSTGRES_HOST} + - JUPYTERHUB_POSTGRES_PASSWORD=${JUPYTERHUB_POSTGRES_PASSWORD} + - JUPYTERHUB_OAUTH_CALLBACK_URL=${JUPYTERHUB_OAUTH_CALLBACK_URL} + - JUPYTERHUB_OAUTH_CLIENT_ID=${JUPYTERHUB_OAUTH_CLIENT_ID} + - JUPYTERHUB_OAUTH_CLIENT_SECRET=${JUPYTERHUB_OAUTH_CLIENT_SECRET} + - JUPYTERHUB_LOCAL_NOTEBOOK_IMAGE=${JUPYTERHUB_LOCAL_NOTEBOOK_IMAGE} + jupyterhub-user: + build: + context: ./jupyterhub + dockerfile: Dockerfile.user + command: ["sh", "-c", "echo \"build only\""] + ### IPython ######################################### ipython-controller: build: diff --git a/env-example b/env-example index f9325ce8..0f524098 100644 --- a/env-example +++ b/env-example @@ -360,6 +360,20 @@ SOLR_VERSION=5.5 SOLR_PORT=8983 SOLR_DATAIMPORTHANDLER_MYSQL=false +### JUPYTERHUB ############################################### +JUPYTERHUB_POSTGRES_HOST=postgres +JUPYTERHUB_POSTGRES_USER=laradock_jupyterhub +JUPYTERHUB_POSTGRES_PASSWORD=laradock_jupyterhub +JUPYTERHUB_POSTGRES_DB=laradock_jupyterhub +JUPYTERHUB_PORT=9991 +JUPYTERHUB_OAUTH_CALLBACK_URL=http://laradock:9991/hub/oauth_callback +JUPYTERHUB_OAUTH_CLIENT_ID={GITHUB_CLIENT_ID} +JUPYTERHUB_OAUTH_CLIENT_SECRET={GITHUB_CLIENT_SECRET} +JUPYTERHUB_LOCAL_NOTEBOOK_IMAGE=laradock_jupyterhub-user +JUPYTERHUB_CUSTOM_CONFIG=./jupyterhub/jupyterhub_config.py +JUPYTERHUB_USER_DATA=/jupyterhub +JUPYTERHUB_USER_LIST=./jupyterhub/userlist + ### IPYTHON ################################################## LARADOCK_IPYTHON_CONTROLLER_IP=127.0.0.1 diff --git a/jupyterhub/Dockerfile b/jupyterhub/Dockerfile new file mode 100644 index 00000000..2016f773 --- /dev/null +++ b/jupyterhub/Dockerfile @@ -0,0 +1,26 @@ +FROM python +LABEL maintainer="ahkui " + +ENV JUPYTERHUB_USER_DATA ${JUPYTERHUB_USER_DATA} +ENV JUPYTERHUB_POSTGRES_DB ${JUPYTERHUB_POSTGRES_DB} +ENV JUPYTERHUB_POSTGRES_USER ${JUPYTERHUB_POSTGRES_USER} +ENV JUPYTERHUB_POSTGRES_HOST ${JUPYTERHUB_POSTGRES_HOST} +ENV JUPYTERHUB_POSTGRES_PASSWORD ${JUPYTERHUB_POSTGRES_PASSWORD} +ENV JUPYTERHUB_OAUTH_CALLBACK_URL ${JUPYTERHUB_OAUTH_CALLBACK_URL} +ENV JUPYTERHUB_OAUTH_CLIENT_ID ${JUPYTERHUB_OAUTH_CLIENT_ID} +ENV JUPYTERHUB_OAUTH_CLIENT_SECRET ${JUPYTERHUB_OAUTH_CLIENT_SECRET} +ENV JUPYTERHUB_LOCAL_NOTEBOOK_IMAGE ${JUPYTERHUB_LOCAL_NOTEBOOK_IMAGE} + +RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - + +RUN apt update -yqq && \ + apt-get install -y nodejs + +RUN npm install -g configurable-http-proxy + +RUN pip install jupyterhub +RUN pip install oauthenticator +RUN pip install dockerspawner +RUN pip install psycopg2 psycopg2-binary + +CMD ["sh", "-c", "jupyterhub upgrade-db && jupyterhub -f /jupyterhub_config.py"] diff --git a/jupyterhub/Dockerfile.user b/jupyterhub/Dockerfile.user new file mode 100644 index 00000000..3d855377 --- /dev/null +++ b/jupyterhub/Dockerfile.user @@ -0,0 +1,72 @@ +FROM tensorflow/tensorflow:latest-gpu + +MAINTAINER ahkui + +RUN apt-get update && apt-get install -y --no-install-recommends \ + python \ + python-dev \ + && \ + apt-get autoremove -y && \ + apt-get autoclean && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +RUN apt-get update && apt-get install -y --no-install-recommends \ + wget \ + git \ + && \ + apt-get autoremove -y && \ + apt-get autoclean && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +RUN curl -O https://bootstrap.pypa.io/get-pip.py && \ + python3 get-pip.py && \ + rm get-pip.py + +RUN python3 -m pip --quiet --no-cache-dir install \ + Pillow \ + h5py \ + ipykernel \ + jupyter \ + notebook \ + jupyterhub \ + matplotlib \ + numpy \ + pandas \ + scipy \ + sklearn \ + Flask \ + gunicorn \ + pymongo \ + redis \ + requests \ + ipyparallel \ + bs4 \ + && \ + python3 -m ipykernel.kernelspec + +RUN pip --no-cache-dir install \ + https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.8.0-cp35-cp35m-linux_x86_64.whl + +RUN ln -s -f /usr/bin/python3 /usr/bin/python + +COPY start.sh /usr/local/bin/ +COPY start-notebook.sh /usr/local/bin/ +COPY start-singleuser.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/start.sh +RUN chmod +x /usr/local/bin/start-notebook.sh +RUN chmod +x /usr/local/bin/start-singleuser.sh + +RUN wget --quiet https://github.com/krallin/tini/releases/download/v0.10.0/tini && \ + mv tini /usr/local/bin/tini && \ + chmod +x /usr/local/bin/tini + +# cleanup +RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +ENTRYPOINT ["tini", "--"] + +CMD ["start-notebook.sh"] + + diff --git a/jupyterhub/jupyterhub_config.py b/jupyterhub/jupyterhub_config.py new file mode 100644 index 00000000..612296c6 --- /dev/null +++ b/jupyterhub/jupyterhub_config.py @@ -0,0 +1,121 @@ +# Copyright (c) Jupyter Development Team. +# Distributed under the terms of the Modified BSD License. + +# Configuration file for JupyterHub +import os + +c = get_config() + +def create_dir_hook(spawner): + username = spawner.user.name # get the username + volume_path = os.path.join('/user-data', username) + if not os.path.exists(volume_path): + # create a directory with umask 0755 + # hub and container user must have the same UID to be writeable + # still readable by other users on the system + os.mkdir(volume_path, 0o755) + os.chown(volume_path, 1000,100) + # now do whatever you think your user needs + # ... + pass + +# attach the hook function to the spawner +c.Spawner.pre_spawn_hook = create_dir_hook + +# We rely on environment variables to configure JupyterHub so that we +# avoid having to rebuild the JupyterHub container every time we change a +# configuration parameter. + +# Spawn single-user servers as Docker containers +c.JupyterHub.spawner_class = 'dockerspawner.DockerSpawner' + +# Spawn containers from this image +c.DockerSpawner.image = os.environ['JUPYTERHUB_LOCAL_NOTEBOOK_IMAGE'] + +# JupyterHub requires a single-user instance of the Notebook server, so we +# default to using the `start-singleuser.sh` script included in the +# jupyter/docker-stacks *-notebook images as the Docker run command when +# spawning containers. Optionally, you can override the Docker run command +# using the DOCKER_SPAWN_CMD environment variable. +spawn_cmd = os.environ.get('JUPYTERHUB_DOCKER_SPAWN_CMD', "start-singleuser.sh") +c.DockerSpawner.extra_create_kwargs.update({ 'command': spawn_cmd }) + +# Connect containers to this Docker network +network_name = os.environ.get('JUPYTERHUB_NETWORK_NAME','laradock_backend') +c.DockerSpawner.use_internal_ip = True +c.DockerSpawner.network_name = network_name + +# Pass the network name as argument to spawned containers +c.DockerSpawner.extra_host_config = { 'network_mode': network_name, 'runtime': 'nvidia' } +# c.DockerSpawner.extra_host_config = { 'network_mode': network_name, "devices":["/dev/nvidiactl","/dev/nvidia-uvm","/dev/nvidia0"] } +# Explicitly set notebook directory because we'll be mounting a host volume to +# it. Most jupyter/docker-stacks *-notebook images run the Notebook server as +# user `jovyan`, and set the notebook directory to `/home/jovyan/work`. +# We follow the same convention. +# notebook_dir = os.environ.get('JUPYTERHUB_DOCKER_NOTEBOOK_DIR') or '/home/jovyan/work' +notebook_dir = '/notebooks' +c.DockerSpawner.notebook_dir = notebook_dir + +# Mount the real user's Docker volume on the host to the notebook user's +# notebook directory in the container +user_data = os.environ.get('JUPYTERHUB_USER_DATA','/jupyterhub') +c.DockerSpawner.volumes = { + user_data+'/{username}': notebook_dir +} + +c.DockerSpawner.extra_create_kwargs.update({ 'user': 'root'}) + +# volume_driver is no longer a keyword argument to create_container() +# c.DockerSpawner.extra_create_kwargs.update({ 'volume_driver': 'local' }) +# Remove containers once they are stopped +c.DockerSpawner.remove_containers = True + +# For debugging arguments passed to spawned containers +c.DockerSpawner.debug = True + +# User containers will access hub by container name on the Docker network +c.JupyterHub.hub_ip = 'jupyterhub' +c.JupyterHub.hub_port = 8000 + +# TLS config +c.JupyterHub.port = 80 +# c.JupyterHub.ssl_key = os.environ['SSL_KEY'] +# c.JupyterHub.ssl_cert = os.environ['SSL_CERT'] + +# Authenticate users with GitHub OAuth +c.JupyterHub.authenticator_class = 'oauthenticator.GitHubOAuthenticator' +c.GitHubOAuthenticator.oauth_callback_url = os.environ['JUPYTERHUB_OAUTH_CALLBACK_URL'] +c.GitHubOAuthenticator.client_id = os.environ['JUPYTERHUB_OAUTH_CLIENT_ID'] +c.GitHubOAuthenticator.client_secret = os.environ['JUPYTERHUB_OAUTH_CLIENT_SECRET'] + +# Persist hub data on volume mounted inside container +data_dir = '/data' + +c.JupyterHub.cookie_secret_file = os.path.join(data_dir, + 'jupyterhub_cookie_secret') + +print(os.environ) + +c.JupyterHub.db_url = 'postgresql://{user}:{password}@{host}/{db}'.format( + user=os.environ['JUPYTERHUB_POSTGRES_USER'], + host=os.environ['JUPYTERHUB_POSTGRES_HOST'], + password=os.environ['JUPYTERHUB_POSTGRES_PASSWORD'], + db=os.environ['JUPYTERHUB_POSTGRES_DB'], +) + +# Whitlelist users and admins +c.Authenticator.whitelist = whitelist = set() +c.Authenticator.admin_users = admin = set() +c.JupyterHub.admin_access = True +pwd = os.path.dirname(__file__) +with open(os.path.join(pwd, 'userlist')) as f: + for line in f: + if not line: + continue + parts = line.split() + name = parts[0] + print(name) + whitelist.add(name) + if len(parts) > 1 and parts[1] == 'admin': + admin.add(name) +admin.add('laradock') diff --git a/jupyterhub/start-notebook.sh b/jupyterhub/start-notebook.sh new file mode 100644 index 00000000..00d95b42 --- /dev/null +++ b/jupyterhub/start-notebook.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# Copyright (c) Jupyter Development Team. +# Distributed under the terms of the Modified BSD License. + +set -e + +if [[ ! -z "${JUPYTERHUB_API_TOKEN}" ]]; then + # launched by JupyterHub, use single-user entrypoint + exec /usr/local/bin/start-singleuser.sh $* +else + . /usr/local/bin/start.sh jupyter notebook $* +fi diff --git a/jupyterhub/start-singleuser.sh b/jupyterhub/start-singleuser.sh new file mode 100644 index 00000000..fb1326e3 --- /dev/null +++ b/jupyterhub/start-singleuser.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# Copyright (c) Jupyter Development Team. +# Distributed under the terms of the Modified BSD License. + +set -e + +# set default ip to 0.0.0.0 +if [[ "$NOTEBOOK_ARGS $@" != *"--ip="* ]]; then + NOTEBOOK_ARGS="--ip=0.0.0.0 $NOTEBOOK_ARGS" +fi + +# handle some deprecated environment variables +# from DockerSpawner < 0.8. +# These won't be passed from DockerSpawner 0.9, +# so avoid specifying --arg=empty-string +# if [ ! -z "$NOTEBOOK_DIR" ]; then + # NOTEBOOK_ARGS="--notebook-dir='$NOTEBOOK_DIR' $NOTEBOOK_ARGS" +# fi +if [ ! -z "$JPY_PORT" ]; then + NOTEBOOK_ARGS="--port=$JPY_PORT $NOTEBOOK_ARGS" +fi +if [ ! -z "$JPY_USER" ]; then + NOTEBOOK_ARGS="--user=$JPY_USER $NOTEBOOK_ARGS" +fi +if [ ! -z "$JPY_COOKIE_NAME" ]; then + NOTEBOOK_ARGS="--cookie-name=$JPY_COOKIE_NAME $NOTEBOOK_ARGS" +fi +if [ ! -z "$JPY_BASE_URL" ]; then + NOTEBOOK_ARGS="--base-url=$JPY_BASE_URL $NOTEBOOK_ARGS" +fi +if [ ! -z "$JPY_HUB_PREFIX" ]; then + NOTEBOOK_ARGS="--hub-prefix=$JPY_HUB_PREFIX $NOTEBOOK_ARGS" +fi +if [ ! -z "$JPY_HUB_API_URL" ]; then + NOTEBOOK_ARGS="--hub-api-url=$JPY_HUB_API_URL $NOTEBOOK_ARGS" +fi + +NOTEBOOK_ARGS=" --allow-root --notebook-dir='/notebooks' $NOTEBOOK_ARGS" + +. /usr/local/bin/start.sh jupyterhub-singleuser $NOTEBOOK_ARGS $@ diff --git a/jupyterhub/start.sh b/jupyterhub/start.sh new file mode 100644 index 00000000..92c02810 --- /dev/null +++ b/jupyterhub/start.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# Copyright (c) Jupyter Development Team. +# Distributed under the terms of the Modified BSD License. + +set -e + +exec sh -c "env PATH=$PATH $*" diff --git a/jupyterhub/userlist b/jupyterhub/userlist new file mode 100644 index 00000000..d48d1c01 --- /dev/null +++ b/jupyterhub/userlist @@ -0,0 +1 @@ +laradock diff --git a/postgres/docker-entrypoint-initdb.d/.gitignore b/postgres/docker-entrypoint-initdb.d/.gitignore index c97f963b..0f14d17d 100644 --- a/postgres/docker-entrypoint-initdb.d/.gitignore +++ b/postgres/docker-entrypoint-initdb.d/.gitignore @@ -1 +1,2 @@ *.sh +!init_jupyterhub_db.sh \ No newline at end of file diff --git a/postgres/docker-entrypoint-initdb.d/init_jupyterhub_db.sh b/postgres/docker-entrypoint-initdb.d/init_jupyterhub_db.sh new file mode 100644 index 00000000..6f3d44c3 --- /dev/null +++ b/postgres/docker-entrypoint-initdb.d/init_jupyterhub_db.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# +# Copy createdb.sh.example to createdb.sh +# then uncomment then set database name and username to create you need databases +# +# example: .env POSTGRES_USER=appuser and need db name is myshop_db +# +# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL +# CREATE USER myuser WITH PASSWORD 'mypassword'; +# CREATE DATABASE myshop_db; +# GRANT ALL PRIVILEGES ON DATABASE myshop_db TO myuser; +# EOSQL +# +# this sh script will auto run when the postgres container starts and the $DATA_PATH_HOST/postgres not found. +# +# +# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL +# CREATE USER db1 WITH PASSWORD 'db1'; +# CREATE DATABASE db1; +# GRANT ALL PRIVILEGES ON DATABASE db1 TO db1; +# EOSQL +# +# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL +# CREATE USER db2 WITH PASSWORD 'db2'; +# CREATE DATABASE db2; +# GRANT ALL PRIVILEGES ON DATABASE db2 TO db2; +# EOSQL +# +# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL +# CREATE USER db3 WITH PASSWORD 'db3'; +# CREATE DATABASE db3; +# GRANT ALL PRIVILEGES ON DATABASE db3 TO db3; +# EOSQL +# +### default database and user for jupyterhub ############################################## +psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL + CREATE USER laradock_jupyterhub WITH PASSWORD 'laradock_jupyterhub'; + CREATE DATABASE laradock_jupyterhub; + GRANT ALL PRIVILEGES ON DATABASE laradock_jupyterhub TO laradock_jupyterhub; + ALTER ROLE laradock_jupyterhub CREATEROLE SUPERUSER; +EOSQL From 20b0181b6dd8609e4dd77f123450058ac0a516e1 Mon Sep 17 00:00:00 2001 From: Alex Mayer Date: Fri, 13 Jul 2018 06:29:18 -0400 Subject: [PATCH 3/8] Make PR Template Checkboxes Render Correctly (#1697) --- .github/PULL_REQUEST_TEMPLATE.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 9160f018..163c99c0 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -2,6 +2,6 @@ ##### I completed the 3 steps below: -- [] I've read the [Contribution Guide](http://laradock.io/contributing). -- [] I've updated the **documentation**. (refer to [this](http://laradock.io/contributing/#update-the-documentation-site) for how to do so). -- [] I enjoyed my time contributing and making developer's life easier :) +- [ ] I've read the [Contribution Guide](http://laradock.io/contributing). +- [ ] I've updated the **documentation**. (refer to [this](http://laradock.io/contributing/#update-the-documentation-site) for how to do so). +- [ ] I enjoyed my time contributing and making developer's life easier :) From 4ce25e95b48b2a9e51f569c597689597d54506d6 Mon Sep 17 00:00:00 2001 From: Youri Westerman Date: Fri, 13 Jul 2018 17:31:13 +0700 Subject: [PATCH 4/8] Added option to install the php calendar extension in php-fpm (#1672) * Added option to install the php calendar extension in php-fpm * Added section about installing php calendar extension in php-fpm --- DOCUMENTATION/content/documentation/index.md | 13 +++++++++++++ docker-compose.yml | 1 + env-example | 1 + php-fpm/Dockerfile | 13 +++++++++++++ 4 files changed, 28 insertions(+) diff --git a/DOCUMENTATION/content/documentation/index.md b/DOCUMENTATION/content/documentation/index.md index 9c74ac31..10ffefbd 100644 --- a/DOCUMENTATION/content/documentation/index.md +++ b/DOCUMENTATION/content/documentation/index.md @@ -1456,6 +1456,19 @@ e) set it to `true` + +## Install php calendar extension + +1 - Open the `.env` file +
+2 - Search for the `PHP_FPM_INSTALL_CALENDAR` argument under the PHP-FPM container +
+3 - Set it to `true` +
+4 - Re-build the containers `docker-compose build php-fpm` + + +
diff --git a/docker-compose.yml b/docker-compose.yml index 2474f999..e717a44a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -143,6 +143,7 @@ services: - INSTALL_SWOOLE=${PHP_FPM_INSTALL_SWOOLE} - INSTALL_IMAGE_OPTIMIZERS=${PHP_FPM_INSTALL_IMAGE_OPTIMIZERS} - INSTALL_IMAGEMAGICK=${PHP_FPM_INSTALL_IMAGEMAGICK} + - INSTALL_CALENDAR=${PHP_FPM_INSTALL_CALENDAR} volumes: - ./php-fpm/php${PHP_VERSION}.ini:/usr/local/etc/php/php.ini - ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER} diff --git a/env-example b/env-example index 0f524098..ecd4c2ee 100644 --- a/env-example +++ b/env-example @@ -148,6 +148,7 @@ PHP_FPM_INSTALL_LDAP=false PHP_FPM_INSTALL_SWOOLE=false PHP_FPM_INSTALL_PG_CLIENT=false PHP_FPM_INSTALL_PCNTL=false +PHP_FPM_INSTALL_CALENDAR=false ### PHP_WORKER ############################################ diff --git a/php-fpm/Dockerfile b/php-fpm/Dockerfile index 92f81c18..8a76ab75 100644 --- a/php-fpm/Dockerfile +++ b/php-fpm/Dockerfile @@ -469,6 +469,19 @@ RUN if [ ${INSTALL_IMAP} = true ]; then \ docker-php-ext-install imap \ ;fi +########################################################################### +# Calendar: +########################################################################### + +USER root + +ARG INSTALL_CALENDAR=false + +RUN if [ ${INSTALL_CALENDAR} = true ]; then \ + docker-php-ext-configure calendar && \ + docker-php-ext-install calendar \ +;fi + ########################################################################### # Check PHP version: ########################################################################### From 7ef36daaba3b5ef882366321e77ea8e350e27776 Mon Sep 17 00:00:00 2001 From: "Shao Yu-Lung (Allen)" Date: Fri, 13 Jul 2018 22:32:40 +0800 Subject: [PATCH 5/8] Fix run mongo-webui service get exit 1 (#1702) --- docker-compose.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index e717a44a..57329dbf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -522,7 +522,6 @@ services: - frontend - backend - ### ElasticSearch ######################################## elasticsearch: build: ./elasticsearch @@ -545,7 +544,6 @@ services: - frontend - backend - ### Kibana ############################################## kibana: build: ./kibana @@ -820,6 +818,7 @@ services: mongo-webui: build: context: ./mongo-webui + restart: always environment: - ROOT_URL=${MONGO_WEBUI_ROOT_URL} - MONGO_URL=${MONGO_WEBUI_MONGO_URL} From 8624335f61e384163a3f3a2f11f8dbf69f94436f Mon Sep 17 00:00:00 2001 From: Vladislav Otchenashev Date: Fri, 13 Jul 2018 17:36:43 +0300 Subject: [PATCH 6/8] Update crontab to reference full PHP path (#1517) Otherwise it doesn't work --- workspace/crontab/laradock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workspace/crontab/laradock b/workspace/crontab/laradock index c807cf4d..d21529bf 100644 --- a/workspace/crontab/laradock +++ b/workspace/crontab/laradock @@ -1 +1 @@ -* * * * * laradock php /var/www/artisan schedule:run >> /dev/null 2>&1 +* * * * * laradock /usr/bin/php /var/www/artisan schedule:run >> /dev/null 2>&1 From 0f65c60a893474615b5411d81b854e4000940a31 Mon Sep 17 00:00:00 2001 From: Valerian Pereira Date: Wed, 18 Jul 2018 18:47:49 +0530 Subject: [PATCH 7/8] DockerFile update for improvement (#1568) Docker file changes for image size improvements. --- mysql/Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mysql/Dockerfile b/mysql/Dockerfile index a3de8863..3fe5bdcf 100644 --- a/mysql/Dockerfile +++ b/mysql/Dockerfile @@ -9,9 +9,7 @@ LABEL maintainer="Mahmoud Zalt " ARG TZ=UTC ENV TZ ${TZ} -RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - -RUN chown -R mysql:root /var/lib/mysql/ +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && chown -R mysql:root /var/lib/mysql/ COPY my.cnf /etc/mysql/conf.d/my.cnf From d8b2b8c2331bd06ce614c04092a598b9a490b5ae Mon Sep 17 00:00:00 2001 From: ahkui <14049597+ahkui@users.noreply.github.com> Date: Wed, 18 Jul 2018 21:20:43 +0800 Subject: [PATCH 8/8] Add gitlab (#1683) * Add gitlab --- DOCUMENTATION/content/documentation/index.md | 19 ++++++++ DOCUMENTATION/content/introduction/index.md | 2 +- docker-compose.yml | 44 +++++++++++++++++++ env-example | 8 ++++ gitlab/Dockerfile | 3 ++ .../docker-entrypoint-initdb.d/.gitignore | 3 +- .../init_gitlab_db.sh | 41 +++++++++++++++++ 7 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 gitlab/Dockerfile create mode 100644 postgres/docker-entrypoint-initdb.d/init_gitlab_db.sh diff --git a/DOCUMENTATION/content/documentation/index.md b/DOCUMENTATION/content/documentation/index.md index 10ffefbd..745cf237 100644 --- a/DOCUMENTATION/content/documentation/index.md +++ b/DOCUMENTATION/content/documentation/index.md @@ -739,6 +739,25 @@ docker-compose up -d mariadb phpmyadmin +
+ +## Use Gitlab + +1 - Run the Gitlab Container (`gitlab`) with the `docker-compose up` command. Example: + +```bash +docker-compose up -d gitlab +``` + +2 - Open your browser and visit the localhost on port **8989**: `http://localhost:8989` +
+*Note: You may change GITLAB_DOMAIN_NAME to your own domain name like `http://gitlab.example.com` default is `http://localhost`* + + + + + +
## Use Adminer diff --git a/DOCUMENTATION/content/introduction/index.md b/DOCUMENTATION/content/introduction/index.md index 7478f10e..a8ccf260 100644 --- a/DOCUMENTATION/content/introduction/index.md +++ b/DOCUMENTATION/content/introduction/index.md @@ -97,7 +97,7 @@ Beanstalkd - RabbitMQ - PHP Worker - **Queueing Management:** Beanstalkd Console - RabbitMQ Console - **Random Tools:** -HAProxy - Certbot - Blackfire - Selenium - Jenkins - ElasticSearch - Kibana - Grafana - Mailhog - MailDev - Minio - Varnish - Swoole - NetData - Portainer - Laravel Echo... +HAProxy - Certbot - Blackfire - Selenium - Jenkins - ElasticSearch - Kibana - Grafana - Gitlab - Mailhog - MailDev - Minio - Varnish - Swoole - NetData - Portainer - Laravel Echo... Laradock introduces the **Workspace** Image, as a development environment. It contains a rich set of helpful tools, all pre-configured to work and integrate with almost any combination of Containers and tools you may choose. diff --git a/docker-compose.yml b/docker-compose.yml index 57329dbf..9ffde6bd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -720,6 +720,50 @@ services: - "dockerhost:${DOCKER_HOST_IP}" ports: - 9010:9000 + networks: + - backend + +### Gitlab ################################################ + gitlab: + build: + context: ./gitlab + environment: + GITLAB_OMNIBUS_CONFIG: | + external_url '${GITLAB_DOMAIN_NAME}' + redis['enable'] = false + nginx['listen_https'] = false + nginx['listen_port'] = 80 + postgresql['enable'] = false + gitlab_rails['trusted_proxies'] = ['caddy','nginx','apache2'] + gitlab_rails['redis_host'] = 'redis' + gitlab_rails['redis_database'] = 8 + gitlab_rails['db_host'] = 'postgres' + gitlab_rails['db_username'] = 'laradock_gitlab' + gitlab_rails['db_password'] = 'laradock_gitlab' + gitlab_rails['db_database'] = 'laradock_gitlab' + gitlab_rails['initial_root_password'] = '${GITLAB_ROOT_PASSWORD}' + gitlab_rails['gitlab_shell_ssh_port'] = ${GITLAB_HOST_SSH_PORT} + volumes: + - ${DATA_PATH_HOST}/gitlab/config:/etc/gitlab + - ${DATA_PATH_HOST}/gitlab/data:/var/opt/gitlab + - ${GITLAB_HOST_LOG_PATH}:/var/log/gitlab + ports: + - "${GITLAB_HOST_HTTP_PORT}:80" + - "${GITLAB_HOST_HTTPS_PORT}:443" + - "${GITLAB_HOST_SSH_PORT}:22" + networks: + - backend + depends_on: + - redis + - postgres + gitlab-runner: + image: gitlab/gitlab-runner:latest + environment: + - CI_SERVER_URL=${GITLAB_DOMAIN_NAME} + volumes: + - ${DATA_PATH_HOST}/gitlab/runner:/etc/gitlab-runner + - /var/run/docker.sock:/var/run/docker.sock:rw + restart: always ### JupyterHub ######################################### jupyterhub: diff --git a/env-example b/env-example index ecd4c2ee..536a9e98 100644 --- a/env-example +++ b/env-example @@ -361,6 +361,14 @@ SOLR_VERSION=5.5 SOLR_PORT=8983 SOLR_DATAIMPORTHANDLER_MYSQL=false +### GITLAB ############################################### +GITLAB_HOST_HTTP_PORT=8989 +GITLAB_HOST_HTTPS_PORT=9898 +GITLAB_HOST_SSH_PORT=2289 +GITLAB_DOMAIN_NAME=http://localhost +GITLAB_ROOT_PASSWORD=laradock +GITLAB_HOST_LOG_PATH=./logs/gitlab + ### JUPYTERHUB ############################################### JUPYTERHUB_POSTGRES_HOST=postgres JUPYTERHUB_POSTGRES_USER=laradock_jupyterhub diff --git a/gitlab/Dockerfile b/gitlab/Dockerfile new file mode 100644 index 00000000..d9929c92 --- /dev/null +++ b/gitlab/Dockerfile @@ -0,0 +1,3 @@ +FROM gitlab/gitlab-ce:latest + +LABEL maintainer="ahkui " diff --git a/postgres/docker-entrypoint-initdb.d/.gitignore b/postgres/docker-entrypoint-initdb.d/.gitignore index 0f14d17d..c462039b 100644 --- a/postgres/docker-entrypoint-initdb.d/.gitignore +++ b/postgres/docker-entrypoint-initdb.d/.gitignore @@ -1,2 +1,3 @@ *.sh -!init_jupyterhub_db.sh \ No newline at end of file +!init_gitlab_db.sh +!init_jupyterhub_db.sh diff --git a/postgres/docker-entrypoint-initdb.d/init_gitlab_db.sh b/postgres/docker-entrypoint-initdb.d/init_gitlab_db.sh new file mode 100644 index 00000000..d9d7738a --- /dev/null +++ b/postgres/docker-entrypoint-initdb.d/init_gitlab_db.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# +# Copy createdb.sh.example to createdb.sh +# then uncomment then set database name and username to create you need databases +# +# example: .env POSTGRES_USER=appuser and need db name is myshop_db +# +# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL +# CREATE USER myuser WITH PASSWORD 'mypassword'; +# CREATE DATABASE myshop_db; +# GRANT ALL PRIVILEGES ON DATABASE myshop_db TO myuser; +# EOSQL +# +# this sh script will auto run when the postgres container starts and the $DATA_PATH_HOST/postgres not found. +# +# +# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL +# CREATE USER db1 WITH PASSWORD 'db1'; +# CREATE DATABASE db1; +# GRANT ALL PRIVILEGES ON DATABASE db1 TO db1; +# EOSQL +# +# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL +# CREATE USER db2 WITH PASSWORD 'db2'; +# CREATE DATABASE db2; +# GRANT ALL PRIVILEGES ON DATABASE db2 TO db2; +# EOSQL +# +# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL +# CREATE USER db3 WITH PASSWORD 'db3'; +# CREATE DATABASE db3; +# GRANT ALL PRIVILEGES ON DATABASE db3 TO db3; +# EOSQL +# +### default database and user for gitlab ############################################## +psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL + CREATE USER laradock_gitlab WITH PASSWORD 'laradock_gitlab'; + CREATE DATABASE laradock_gitlab; + GRANT ALL PRIVILEGES ON DATABASE laradock_gitlab TO laradock_gitlab; + ALTER ROLE laradock_gitlab CREATEROLE SUPERUSER; +EOSQL