diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3aa2759 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM node:6 + +ENV CROWI_VERSION v1.6.3 +ENV NODE_ENV production + +RUN curl -SL -o /usr/local/bin/wait-for-it.sh https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh \ + && chmod +x /usr/local/bin/wait-for-it.sh + +RUN mkdir /usr/src/app \ + && curl -SL https://github.com/crowi/crowi/archive/${CROWI_VERSION}.tar.gz \ + | tar -xz -C /usr/src/app --strip-components 1 + +WORKDIR /usr/src/app + +RUN npm install --unsafe-perm + +COPY docker-entrypoint.sh /entrypoint.sh + +VOLUME /data +ENTRYPOINT ["/entrypoint.sh"] +CMD ["npm", "start"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..efa6f5a --- /dev/null +++ b/LICENSE @@ -0,0 +1,23 @@ +The MIT License (MIT) + +Copyright (c) 2013 Sotaro KARASAWA +Copyright (c) 2016 Giles Hall +Copyright (c) 2016 バクダンくん + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 756d8f4..7b4f5c8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ -docker_crowi -=============== +[![Crowi](https://camo.githubusercontent.com/25aba13a62a44530175dc8eebb1567d829a3cbb0/687474703a2f2f7265732e636c6f7564696e6172792e636f6d2f6872736379777634702f696d6167652f75706c6f61642f635f6c696d69742c665f6175746f2c685f3930302c715f38302c775f313230302f76312f3139393637332f68747470735f7777775f66696c657069636b65725f696f5f6170695f66696c655f567059455033325a5179435a383575365843586f5f7a736b7072612e706e67)](http://site.crowi.wiki) + + +Please use Crowi official image on [dockerhub](https://hub.docker.com/r/crowi/crowi/) instead. diff --git a/alpine/Dockerfile b/alpine/Dockerfile new file mode 100644 index 0000000..a576bbf --- /dev/null +++ b/alpine/Dockerfile @@ -0,0 +1,24 @@ +FROM node:6-alpine + +ENV CROWI_VERSION v1.6.3 +ENV NODE_ENV production + +RUN set -ex; \ + apk --no-cache add openssl; \ + wget -O /usr/local/bin/wait-for https://raw.githubusercontent.com/eficode/wait-for/master/wait-for; \ + chmod +x /usr/local/bin/wait-for; \ + mkdir /usr/src; \ + wget -O - https://github.com/crowi/crowi/archive/${CROWI_VERSION}.tar.gz \ + | tar -xz -C /usr/src/; \ + mv /usr/src/crowi-${CROWI_VERSION#v} /usr/src/app; \ + apk --no-cache del openssl + +WORKDIR /usr/src/app + +RUN npm install --unsafe-perm + +COPY docker-entrypoint.sh /entrypoint.sh + +VOLUME /data +ENTRYPOINT ["/entrypoint.sh"] +CMD ["npm", "start"] diff --git a/alpine/LICENSE b/alpine/LICENSE new file mode 100644 index 0000000..d971524 --- /dev/null +++ b/alpine/LICENSE @@ -0,0 +1,26 @@ +The MIT License (MIT) + +Crowi: + Copyright (c) 2013 Sotaro KARASAWA +wait-for: + Copyright (c) 2016 Eficode Oy +docker-crowi: + Copyright (c) 2016 バクダンくん + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/alpine/docker-entrypoint.sh b/alpine/docker-entrypoint.sh new file mode 100644 index 0000000..4690631 --- /dev/null +++ b/alpine/docker-entrypoint.sh @@ -0,0 +1,72 @@ +#!/bin/sh +set -e + +if [ "$1" == npm ]; then + + if wait-for -t 60 db:27017 ; then + if [ -n "$MONGO_URI" ]; then + echo >&2 'warning: both linked db container and MONGO_URI found' + echo >&2 " Connectiong to MONGO_URI ($MONGO_URI)" + echo >&2 ' instead of linked MongoDB conatiner' + fi + elif [ -z "$MONGO_URI" ]; then + echo >&2 'error: missing db container and MONGO_URI environment variables' + echo >&2 ' Please --link some_mongdb_container:db or set an external db' + echo >&2 ' with -e MONGO_URI=mongodb://hostname:port/some-crowi' + exit 1 + fi + export MONGO_URI=${MONGO_URI:-mongodb://db:27017/crowi} + + if wait-for -t 60 redis:6379 ; then + if [ -n "$REDIS_URL" ]; then + echo >&2 'warning: both linked redis container and REDIS_URL found' + echo >&2 " Connectiong to REDIS_URL ($REDIS_URL)" + echo >&2 ' instead of linked Redis conatiner' + else + export REDIS_URL='redis://redis:6379/crowi' + fi + fi + + if wait-for -t 60 es:9200 ; then + if [ -n "$ELASTICSEARCH_URI" ]; then + echo >&2 'warning: both linked elasticsearch container and ELASTICSEARCH_URI found' + echo >&2 " Connectiong to ELASTICSEARCH_URI ($ELASTICSEARCH_URI)" + echo >&2 ' instead of linked elasticsearch conatiner' + else + export ELASTICSEARCH_URI='http://es:9200/crowi' + fi + fi + + export FILE_UPLOAD=${FILE_UPLOAD:-local} + if [ "$FILE_UPLOAD" = "local" ]; then + # Create local directory for uploaded files + mkdir -p /data/uploads + if [ ! -d /usr/src/app/public/uploads ]; then + ln -s /data/uploads /usr/src/app/public/uploads + fi + fi + + GIVEN_SEED=$PASSWORD_SEED + PASSWORD_SEED='' + if [ -f /data/config ]; then + . /data/config + fi + if [ -n "$GIVEN_SEED" -a "$PASSWORD_SEED" != "$GIVEN_SEED" ]; then + # A seed is given by command line, which is different from the content of /data/config. + # Adopt the given seed and store it to /data/config. + export PASSWORD_SEED=$GIVEN_SEED + echo "export PASSWORD_SEED='$PASSWORD_SEED'" >> /data/config + elif [ -z "$PASSWORD_SEED" ]; then + # Neither command line nor /data/config give PASSWORD_SEED. + # Generate one and store it to /data/config. + export PASSWORD_SEED=`head -c1m /dev/urandom | sha1sum | cut -d' ' -f1` + echo "export PASSWORD_SEED='$PASSWORD_SEED'" >> /data/config + else + # Only /data/config gives PASSWORD_SEED, or given seed matches the content of /data/config. + # The seed is already set to PASSWORD_SEED and /data/config, so nothing to do. + : + fi + +fi + +exec "$@" diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..7aae5a8 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,72 @@ +#!/bin/bash +set -e + +if [ "$1" == npm ]; then + + if wait-for-it.sh -t 60 db:27017 ; then + if [ -n "$MONGO_URI" ]; then + echo >&2 'warning: both linked db container and MONGO_URI found' + echo >&2 " Connectiong to MONGO_URI ($MONGO_URI)" + echo >&2 ' instead of linked MongoDB conatiner' + fi + elif [ -z "$MONGO_URI" ]; then + echo >&2 'error: missing db container and MONGO_URI environment variables' + echo >&2 ' Please --link some_mongdb_container:db or set an external db' + echo >&2 ' with -e MONGO_URI=mongodb://hostname:port/some-crowi' + exit 1 + fi + export MONGO_URI=${MONGO_URI:-mongodb://db:27017/crowi} + + if wait-for-it.sh -t 60 redis:6379 ; then + if [ -n "$REDIS_URL" ]; then + echo >&2 'warning: both linked redis container and REDIS_URL found' + echo >&2 " Connectiong to REDIS_URL ($REDIS_URL)" + echo >&2 ' instead of linked Redis conatiner' + else + export REDIS_URL='redis://redis:6379/crowi' + fi + fi + + if wait-for-it.sh -t 60 es:9200 ; then + if [ -n "$ELASTICSEARCH_URI" ]; then + echo >&2 'warning: both linked elasticsearch container and ELASTICSEARCH_URI found' + echo >&2 " Connectiong to ELASTICSEARCH_URI ($ELASTICSEARCH_URI)" + echo >&2 ' instead of linked elasticsearch conatiner' + else + export ELASTICSEARCH_URI='http://es:9200/crowi' + fi + fi + + export FILE_UPLOAD=${FILE_UPLOAD:-local} + if [ "$FILE_UPLOAD" = "local" ]; then + # Create local directory for uploaded files + mkdir -p /data/uploads + if [ ! -d /usr/src/app/public/uploads ]; then + ln -s /data/uploads /usr/src/app/public/uploads + fi + fi + + GIVEN_SEED=$PASSWORD_SEED + PASSWORD_SEED='' + if [ -f /data/config ]; then + . /data/config + fi + if [ -n "$GIVEN_SEED" -a "$PASSWORD_SEED" != "$GIVEN_SEED" ]; then + # A seed is given by command line, which is different from the content of /data/config. + # Adopt the given seed and store it to /data/config. + export PASSWORD_SEED=$GIVEN_SEED + printf 'export PASSWORD_SEED="%q"' "$PASSWORD_SEED" >> /data/config + elif [ -z "$PASSWORD_SEED" ]; then + # Neither command line nor /data/config give PASSWORD_SEED. + # Generate one and store it to /data/config. + export PASSWORD_SEED=`head -c1M /dev/urandom | sha1sum | cut -d' ' -f1` + printf 'export PASSWORD_SEED="%q"' "$PASSWORD_SEED" >> /data/config + else + # Only /data/config gives PASSWORD_SEED, or given seed matches the content of /data/config. + # The seed is already set to PASSWORD_SEED and /data/config, so nothing to do. + : + fi + +fi + +exec "$@"