Skip to content
Snippets Groups Projects
Commit f580ad1d authored by Pierre Guilleminot's avatar Pierre Guilleminot
Browse files

Do not run couchdb by default

parent ca1ce84e
Branches
Tags
No related merge requests found
...@@ -39,7 +39,9 @@ RUN mkdir /usr/src/couchdb \ ...@@ -39,7 +39,9 @@ RUN mkdir /usr/src/couchdb \
&& cd /usr/src/couchdb \ && cd /usr/src/couchdb \
&& ./configure --disable-docs \ && ./configure --disable-docs \
&& make release \ && make release \
&& mv ./rel/couchdb /usr/local && mv ./rel/couchdb /usr/local \
&& printf "[httpd]\nport = 5984\nbind_address = 127.0.0.1\n" \
> /usr/local/couchdb/etc/local.ini
ENV PATH $PATH:/usr/local/couchdb/bin ENV PATH $PATH:/usr/local/couchdb/bin
...@@ -66,18 +68,17 @@ RUN apt-get purge -y \ ...@@ -66,18 +68,17 @@ RUN apt-get purge -y \
&& apt-get clean \ && apt-get clean \
&& rm -rf /usr/src/couchdb && rm -rf /usr/src/couchdb
COPY dev.sh /usr/bin COPY app-dev.sh /usr/bin
RUN chmod +x /usr/bin/dev.sh RUN chmod +x /usr/bin/app-dev.sh
ENV COZY_DEV_HOST cozy.local ENV COZY_PROXY_HOST cozy.local
ENV COZY_DEV_PORT 8080 ENV COZY_PROXY_PORT 8080
ENV COZY_STACK_HOST localhost ENV COZY_STACK_HOST localhost
ENV COZY_STACK_PORT 8081 ENV COZY_STACK_PORT 8081
ENV COUCHDB_ENABLE 1
ENV COUCHDB_HOST localhost
ENV COUCHDB_PORT 5984
RUN mkdir -p /data/cozy-app RUN mkdir -p /data/cozy-app
ENTRYPOINT ["/usr/bin/dev.sh"] EXPOSE $COZY_PROXY_PORT
ENTRYPOINT ["/usr/bin/app-dev.sh"]
CMD ["-d /data/cozy-app"] CMD ["-d /data/cozy-app"]
#!/usr/bin/env bash #!/usr/bin/env bash
[ -z ${COZY_DEV_HOST} ] && COZY_DEV_HOST="cozy.local" set -e
[ -z ${COZY_DEV_PORT} ] && COZY_DEV_PORT="8080"
[ -z ${COZY_PROXY_HOST} ] && COZY_PROXY_HOST="cozy.local"
[ -z ${COZY_PROXY_PORT} ] && COZY_PROXY_PORT="8080"
[ -z ${COZY_STACK_HOST} ] && COZY_STACK_HOST="localhost" [ -z ${COZY_STACK_HOST} ] && COZY_STACK_HOST="localhost"
[ -z ${COZY_STACK_PORT} ] && COZY_STACK_PORT="8081" [ -z ${COZY_STACK_PORT} ] && COZY_STACK_PORT="8081"
[ -z ${COUCHDB_HOST} ] && COUCHDB_HOST="localhost"
[ -z ${COUCHDB_PORT} ] && COUCHDB_PORT="5984"
[ -z ${COUCHDB_ENABLE} ] && COUCHDB_ENABLE="1"
if [ -d ${COZY_STACK_PATH} ] && [ -f ${COZY_STACK_PATH}/cozy-stack ]; then if [ -d ${COZY_STACK_PATH} ] && [ -f ${COZY_STACK_PATH}/cozy-stack ]; then
COZY_STACK_PATH="${COZY_STACK_PATH}/cozy-stack" COZY_STACK_PATH="${COZY_STACK_PATH}/cozy-stack"
fi fi
...@@ -17,11 +15,11 @@ usage() { ...@@ -17,11 +15,11 @@ usage() {
echo -e "Usage: ${0} [-h] [-d <app path>] [–v <stack version>]" echo -e "Usage: ${0} [-h] [-d <app path>] [–v <stack version>]"
echo -e "\nEnvironment variables" echo -e "\nEnvironment variables"
echo -e "\n COZY_DEV_HOST" echo -e "\n COZY_PROXY_HOST"
echo -e " specify the hostname or domain on which the dev server is listening" echo -e " specify the hostname or domain on which the proxy is listening"
echo -e " to incoming requests. default: cozy.local" echo -e " to incoming requests. default: cozy.local"
echo -e "\n COZY_DEV_PORT" echo -e "\n COZY_PROXY_PORT"
echo -e " specify the port on which the dev server is listening." echo -e " specify the port on which the proxy is listening."
echo -e " default: 8080." echo -e " default: 8080."
echo -e "\n COZY_STACK_PATH" echo -e "\n COZY_STACK_PATH"
echo -e " specify the path of the cozy-stack binary folder or the binary" echo -e " specify the path of the cozy-stack binary folder or the binary"
...@@ -32,13 +30,12 @@ usage() { ...@@ -32,13 +30,12 @@ usage() {
echo -e "\n COZY_STACK_PORT" echo -e "\n COZY_STACK_PORT"
echo -e " specify the port on which the cozy-stack is listening." echo -e " specify the port on which the cozy-stack is listening."
echo -e " default: 8080." echo -e " default: 8080."
echo -e "\n COUCHDB_ENABLE"
echo -e " specify whether or not this script should launch couchdb."
echo -e " default: 1"
echo -e "\n COUCHDB_HOST" echo -e "\n COUCHDB_HOST"
echo -e " specify the host of the couchdb database. default: localhost" echo -e " specify the host of the couchdb database. if specified,"
echo -e " the script won't try to start couchdb."
echo -e "\n COUCHDB_PORT" echo -e "\n COUCHDB_PORT"
echo -e " specify the port of the couchdb database. default: 5984" echo -e " specify the port of the couchdb database. if specified,"
echo -e " the script won't try to start couchdb."
} }
if [ -n "${COZY_STACK_PATH}" ] && [ ! -f "${COZY_STACK_PATH}" ]; then if [ -n "${COZY_STACK_PATH}" ] && [ ! -f "${COZY_STACK_PATH}" ]; then
...@@ -46,17 +43,15 @@ if [ -n "${COZY_STACK_PATH}" ] && [ ! -f "${COZY_STACK_PATH}" ]; then ...@@ -46,17 +43,15 @@ if [ -n "${COZY_STACK_PATH}" ] && [ ! -f "${COZY_STACK_PATH}" ]; then
exit 1 exit 1
fi fi
if [ "${COZY_STACK_PORT}" = "${COZY_DEV_PORT}" ]; then if [ "${COZY_STACK_PORT}" = "${COZY_PROXY_PORT}" ]; then
echo_err "COZY_STACK_HOST and COZY_DEV_PORT are equal" echo_err "COZY_STACK_HOST and COZY_PROXY_PORT are equal"
exit 1 exit 1
fi fi
do_start() { do_start() {
set -e
if [ ! -f "${GOPATH}/bin/caddy" ]; then if [ ! -f "${GOPATH}/bin/caddy" ]; then
if [ -z `command -v go` ]; then if [ -z `command -v go` ]; then
echo_err "Executable \"go\" not found in \$PATH" echo_err "executable \"go\" not found in \$PATH"
exit 1 exit 1
fi fi
printf "installing http server (caddy)... " printf "installing http server (caddy)... "
...@@ -65,7 +60,7 @@ do_start() { ...@@ -65,7 +60,7 @@ do_start() {
fi fi
if [ -n "${cozy_stack_version}" ]; then if [ -n "${cozy_stack_version}" ]; then
echo_err "Not implemented... we do not have a release yet" echo_err "not implemented... we do not have a release yet"
exit 1 exit 1
fi fi
...@@ -78,12 +73,15 @@ do_start() { ...@@ -78,12 +73,15 @@ do_start() {
fi fi
fi fi
check_not_running ":${COZY_PROXY_PORT}" "proxy"
check_not_running ":${COZY_STACK_PORT}" "cozy-stack"
do_start_couchdb do_start_couchdb
do_create_instance
do_start_proxy do_start_proxy
check_hosts check_hosts
echo "" echo ""
echo "Go to http://app.${COZY_DEV_HOST}:${COZY_DEV_PORT}/" echo "Go to http://app.${cozy_dev_addr}/"
echo "" echo ""
${COZY_STACK_PATH} serve \ ${COZY_STACK_PATH} serve \
...@@ -104,78 +102,105 @@ cleanup() { ...@@ -104,78 +102,105 @@ cleanup() {
pid=`cat "${pidfile}"` pid=`cat "${pidfile}"`
if [ -n "${pid}" ]; then if [ -n "${pid}" ]; then
echo "stopping couchdb" echo "stopping couchdb"
kill -9 ${pid} 2>/dev/null 1>/dev/null || true kill -9 ${pid} 2>&1 >/dev/null || true
fi fi
rm "${pidfile}" rm "${pidfile}"
done done
} }
do_start_couchdb() { do_start_couchdb() {
if [ "${COUCHDB_ENABLE}" = "0" ]; then # if COUCHDB_HOST or COUCHDB_PORT is non null, we do not try to start couchdb
echo "skip couchdb" # and only check if it is accessible on the given host:port.
return if [ -n "${COUCHDB_HOST}" ] || [ -n "${COUCHDB_PORT}" ]; then
fi couch_addr="${COUCHDB_HOST}:${COUCHDB_PORT}"
printf "checking couchdb on ${couch_addr}... "
printf "checking couchdb... " couch_test=$(curl -s -XGET "${couch_addr}" || echo "")
couch_vers=$(echo "${couch_test}" | grep "\"version\":\s*\"2" || echo "")
set +e
couch_test=`curl -s -XGET "${COUCHDB_HOST}:${COUCHDB_PORT}"`
if [ -n "${couch_test}" ]; then
couch_test=`echo "${couch_test}" | grep "\"version\":\s*\"2"`
if [ -z "${couch_test}" ]; then if [ -z "${couch_test}" ]; then
echo_err "" echo "failed"
echo_err "couchdb v1 is running on ${COUCHDB_HOST}:${COUCHDB_PORT}" echo_err "could not reach couchdb on ${couch_addr}"
exit 1
elif [ -z "${couch_vers}" ]; then
echo "failed"
echo_err "couchdb v1 is running on ${couch_addr}"
echo_err "you need couchdb version >= 2" echo_err "you need couchdb version >= 2"
exit 1 exit 1
else
echo "ok"
return
fi fi
echo "ok"
return
fi fi
set -e
printf "starting couchdb... "
COUCHDB_HOST="localhost"
COUCHDB_PORT="5984"
if [ -z `command -v go` ]; then if [ -z `command -v go` ]; then
echo_err "\nExecutable \"couchdb\" not found in \$PATH" echo "failed"
echo_err "executable \"couchdb\" not found in \$PATH"
exit 1 exit 1
fi fi
couch_pid=`mktemp -t cozy-stack-dev.couch.XXXX` || exit 1 couch_pid=`mktemp -t cozy-stack-dev.couch.XXXX` || exit 1
trap cleanup EXIT trap cleanup EXIT
printf "none found, starting... " couchdb 2>&1 > /dev/null
couchdb 2> /dev/null 1> /dev/null &
echo ${!} > ${couch_pid} echo ${!} > ${couch_pid}
wait_for "${COUCHDB_HOST}:${COUCHDB_PORT}" "couchdb" wait_for "${COUCHDB_HOST}:${COUCHDB_PORT}" "couchdb"
echo "ok" echo "ok"
for i in "_users" "_replicator" "_global_changes"; do for dbname in "_users" "_replicator" "_global_changes"; do
curl -s -XPUT "${COUCHDB_HOST}:${COUCHDB_PORT}/${i}" > /dev/null curl -s -XPUT "${COUCHDB_HOST}:${COUCHDB_PORT}/${dbname}" > /dev/null
done done
} }
do_create_instance() {
if [ "${COZY_PROXY_PORT}" = "80" ]; then
cozy_dev_addr="${COZY_PROXY_HOST}"
else
cozy_dev_addr="${COZY_PROXY_HOST}:${COZY_PROXY_PORT}"
fi
printf "creating instance ${cozy_dev_addr}... "
set +e
add_instance_val=$(${COZY_STACK_PATH} instances add "${cozy_dev_addr}" 2>&1)
add_instance_ret="${?}"
set -e
if [ "${add_instance_ret}" = "0" ]; then
echo "ok"
else
add_instance_val=$(echo "${add_instance_val}" | grep -i "already exists" || echo "")
if [ -z "${add_instance_val}" ]; then
echo_err "${add_instance_val} ${add_instance_ret}"
exit 1
fi
echo "ok (already created)"
fi
}
do_start_proxy() { do_start_proxy() {
site_root=`realpath ${appdir}` site_root=`realpath ${appdir}`
check_not_running "${COZY_DEV_HOST}:${COZY_DEV_PORT}" "dev server"
check_not_running "${COZY_STACK_HOST}:${COZY_STACK_PORT}" "cozy-stack"
caddy_file="\n\ caddy_file="\n\
${COZY_DEV_HOST} { \n\ ${COZY_PROXY_HOST} { \n\
proxy / ${COZY_STACK_HOST}:${COZY_STACK_PORT} \n\ proxy / ${COZY_STACK_HOST}:${COZY_STACK_PORT} \n\
tls off \n\ tls off \n\
} \n\ } \n\
app.${COZY_DEV_HOST} { \n\ app.${COZY_PROXY_HOST} { \n\
root ${site_root} \n\ root ${site_root} \n\
tls off \n\ tls off \n\
} \n\ } \n\
" "
printf "starting caddy on \"${site_root}\"... " printf "starting caddy on \"${site_root}\"... "
echo ${caddy_file} | ${GOPATH}/bin/caddy \ echo -e ${caddy_file} | ${GOPATH}/bin/caddy \
-quiet \ -quiet \
-conf stdin \ -conf stdin \
-port ${COZY_DEV_PORT} & -port ${COZY_PROXY_PORT} &
wait_for "${COZY_STACK_HOST}:${COZY_DEV_PORT}" "caddy" wait_for "${COZY_STACK_HOST}:${COZY_PROXY_PORT}" "caddy"
echo "ok" echo "ok"
} }
...@@ -192,7 +217,7 @@ wait_for() { ...@@ -192,7 +217,7 @@ wait_for() {
} }
check_not_running() { check_not_running() {
printf "checking ${1}... " printf "checking ${2} on ${1}... "
if curl -s --max-time 1 -XGET ${1} > /dev/null; then if curl -s --max-time 1 -XGET ${1} > /dev/null; then
printf "\n" printf "\n"
echo_err "${2} is already running on ${1}" echo_err "${2} is already running on ${1}"
...@@ -202,15 +227,13 @@ check_not_running() { ...@@ -202,15 +227,13 @@ check_not_running() {
} }
check_hosts() { check_hosts() {
set +e devhost=$(cat /etc/hosts | grep ${COZY_PROXY_HOST} || echo "")
devhost=`cat /etc/hosts | grep ${COZY_DEV_HOST}` apphost=$(cat /etc/hosts | grep app.${COZY_PROXY_HOST} || echo "")
apphost=`cat /etc/hosts | grep app.${COZY_DEV_HOST}`
if [ -z "${devhost}" ] || [ -z "${apphost}" ]; then if [ -z "${devhost}" ] || [ -z "${apphost}" ]; then
echo "" echo ""
echo_err "You should probaby add the following line in the /etc/hosts file:" echo_err "You should probaby add the following line in the /etc/hosts file:"
echo_err "127.0.0.1\t${COZY_DEV_HOST},app.${COZY_DEV_HOST}" echo_err "127.0.0.1\t${COZY_PROXY_HOST},app.${COZY_PROXY_HOST}"
fi fi
set -e
} }
echo_err() { echo_err() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment