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

Add dev script and Dockerfile

parent a9b7c6d3
No related branches found
No related tags found
No related merge requests found
......@@ -113,6 +113,10 @@ Make sure the full stack is up with:
curl -H 'Accept: application/json' 'http://localhost:8080/status/'
```
## Configuration
See [configuration documentation](/docs/config.md).
## Building a release
To build a release of cozy-stack, a `build.sh` script can automate the work. The `release` option of this script will generate a binary with a name containing the version of the file, along with a SHA-256 sum of the binary.
......
FROM debian:jessie
ENV COUCHDB_VERSION 2.0.0
ENV COUCHDB_SRC_URL https://dist.apache.org/repos/dist/release/couchdb/source/2.0.0/apache-couchdb-$COUCHDB_VERSION.tar.gz
ENV COUCHDB_SRC_SHA256 ccaf3ce9cb06c50a73e091696e557e2a57c5ba02c5b299e1ac2f5b959ee96eca
ENV GOLANG_VERSION 1.7.3
ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz
ENV GOLANG_DOWNLOAD_SHA256 508028aac0654e993564b6e2014bf2d4a9751e3b286661b0b0040046cf18028e
# CouchDB and CGo dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
ca-certificates \
curl \
libicu52 \
libmozjs185-1.0 \
erlang \
libicu-dev \
libmozjs185-dev \
openssl \
g++ \
gcc \
libc6-dev \
make \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
# CouchDB
RUN mkdir /usr/src/couchdb \
&& curl -fsSL "$COUCHDB_SRC_URL" -o couchdb.tar.gz \
&& echo "$COUCHDB_SRC_SHA256 couchdb.tar.gz" | sha256sum -c - \
&& tar -xzf couchdb.tar.gz -C /usr/src/couchdb --strip-components=1 \
&& rm couchdb.tar.gz \
&& cd /usr/src/couchdb \
&& ./configure --disable-docs \
&& make release \
&& mv ./rel/couchdb /usr/local
ENV PATH $PATH:/usr/local/couchdb/bin
# Go
RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \
&& echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - \
&& tar -xzf golang.tar.gz -C /usr/local \
&& rm golang.tar.gz
ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
RUN go get github.com/mholt/caddy/caddy \
&& go get github.com/cozy/cozy-stack
# Cleanup
RUN apt-get purge -y \
erlang-dev \
libicu-dev \
libmozjs185-dev \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /usr/src/couchdb
COPY dev.sh /usr/bin
RUN chmod +x /usr/bin/dev.sh
ENV COZY_DEV_HOST cozy.local
ENV COZY_DEV_PORT 8080
ENV COZY_STACK_HOST localhost
ENV COZY_STACK_PORT 8081
ENV COUCHDB_ENABLE 1
ENV COUCHDB_HOST localhost
ENV COUCHDB_PORT 5984
RUN mkdir -p /data/cozy-app
ENTRYPOINT ["/usr/bin/dev.sh"]
CMD ["-d /data/cozy-app"]
#!/bin/sh
[ -z ${COZY_DEV_HOST} ] && COZY_DEV_HOST="cozy.local"
[ -z ${COZY_DEV_PORT} ] && COZY_DEV_PORT="8080"
[ -z ${COZY_STACK_HOST} ] && COZY_STACK_HOST="localhost"
[ -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
COZY_STACK_PATH="${COZY_STACK_PATH}/cozy-stack"
fi
usage() {
echo "Usage: ${0} [-h] [-d <app path>] [–v <stack version>]"
echo "\nEnvironment variables"
echo "\n COZY_DEV_HOST"
echo " specify the hostname or domain on which the dev server is listening"
echo " to incoming requests. default: dev.cozycloud.cc"
echo "\n COZY_DEV_PORT"
echo " specify the port on which the dev server is listening."
echo " default: 8080."
echo "\n COZY_STACK_PATH"
echo " specify the path of the cozy-stack binary folder or the binary"
echo " itself. default: \"\$GOPATH/bin\"."
echo "\n COZY_STACK_HOST"
echo " specify the hostname on which the cozy-stack is launched."
echo " default: localhost."
echo "\n COZY_STACK_PORT"
echo " specify the port on which the cozy-stack is listening."
echo " default: 8080."
echo "\n COUCHDB_ENABLE"
echo " specify whether or not this script should launch couchdb."
echo " default: 1"
echo "\n COUCHDB_HOST"
echo " specify the host of the couchdb database. default: localhost"
echo "\n COUCHDB_PORT"
echo " specify the port of the couchdb database. default: 5984"
}
if [ -n "${COZY_STACK_PATH}" ] && [ ! -f "${COZY_STACK_PATH}" ]; then
echo_err "COZY_STACK_PATH=${COZY_STACK_PATH} file does not exist"
exit 1
fi
if [ "${COZY_STACK_PORT}" = "${COZY_DEV_PORT}" ]; then
echo_err "COZY_STACK_HOST and COZY_DEV_PORT are equal"
exit 1
fi
do_start() {
set -e
if [ ! -f "${GOPATH}/bin/caddy" ]; then
if [ -z `command -v go` ]; then
echo_err "Executable \"go\" not found in \$PATH"
exit 1
fi
printf "installing http server (caddy)... "
go get -x -u "github.com/mholt/caddy/caddy"
echo "ok"
fi
if [ -n "${cozy_stack_version}" ]; then
echo_err "Not implemented... we do not have a release yet"
exit 1
fi
if [ -z "${COZY_STACK_PATH}" ]; then
COZY_STACK_PATH="${GOPATH}/bin/cozy-stack"
if [ ! -f "${COZY_STACK_PATH}" ]; then
printf "installing cozy-stack... "
go get -x -u "github.com/cozy/cozy-stack"
echo "ok"
fi
fi
do_start_couchdb
do_start_proxy
check_hosts
echo ""
echo "Go to http://app.${COZY_DEV_HOST}:${COZY_DEV_PORT}/"
echo ""
${COZY_STACK_PATH} serve \
--port ${COZY_STACK_PORT} \
--host ${COZY_STACK_HOST} \
--couchdb-host ${COUCHDB_HOST} \
--couchdb-port ${COUCHDB_PORT}
}
cleanup() {
for tmpdir in "${TMPDIR}" "${TMP}" /var/tmp /tmp; do
test -d "${tmpdir}" && break
done
pids=`find ${tmpdir} -iname cozy-stack-dev.couch*`
for pidfile in ${pids}; do
pid=`cat "${pidfile}"`
if [ -n "${pid}" ]; then
echo "stopping couchdb"
kill -9 ${pid} 2>/dev/null 1>/dev/null || true
fi
rm "${pidfile}"
done
}
do_start_couchdb() {
if [ "${COUCHDB_ENABLE}" = "0" ]; then
echo "skip couchdb"
return
fi
printf "checking couchdb... "
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
echo_err ""
echo_err "couchdb v1 is running on ${COUCHDB_HOST}:${COUCHDB_PORT}"
echo_err "you need couchdb version >= 2"
exit 1
else
echo "ok"
return
fi
fi
set -e
if [ -z `command -v go` ]; then
echo_err "\nExecutable \"couchdb\" not found in \$PATH"
exit 1
fi
couch_pid=`mktemp -t cozy-stack-dev.couch.XXXX` || exit 1
trap cleanup EXIT
printf "none found, starting... "
couchdb 2> /dev/null 1> /dev/null &
echo ${!} > ${couch_pid}
wait_for "${COUCHDB_HOST}:${COUCHDB_PORT}" "couchdb"
echo "ok"
for i in "_users" "_replicator" "_global_changes"; do
curl -s -XPUT "${COUCHDB_HOST}:${COUCHDB_PORT}/${i}" > /dev/null
done
}
do_start_proxy() {
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\
${COZY_DEV_HOST} { \n\
proxy / ${COZY_STACK_HOST}:${COZY_STACK_PORT} \n\
tls off \n\
} \n\
app.${COZY_DEV_HOST} { \n\
root ${site_root} \n\
tls off \n\
} \n\
"
printf "starting caddy on \"${site_root}\"... "
echo ${caddy_file} | ${GOPATH}/bin/caddy \
-quiet \
-conf stdin \
-port ${COZY_DEV_PORT} &
wait_for "${COZY_STACK_HOST}:${COZY_DEV_PORT}" "caddy"
echo "ok"
}
wait_for() {
i="0"
while ! curl -s --max-time 1 -XGET ${1} > /dev/null; do
sleep 0.5
i=$((i+1))
if [ "${i}" -gt "10" ]; then
echo_err "could not listen to ${2} on ${1}"
exit 1
fi
done
}
check_not_running() {
printf "checking ${1}... "
if curl -s --max-time 1 -XGET ${1} > /dev/null; then
printf "\n"
echo_err "${2} is already running on ${1}"
exit 1
fi
echo "ok"
}
check_hosts() {
set +e
devhost=`cat /etc/hosts | grep ${COZY_DEV_HOST}`
apphost=`cat /etc/hosts | grep app.${COZY_DEV_HOST}`
if [ -z "${devhost}" ] || [ -z "${apphost}" ]; then
echo ""
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}"
fi
set -e
}
echo_err() {
>&2 echo "error: ${1}"
}
while getopts ":hd:v:" optname; do
case "${optname}" in
"h")
usage
exit 0
;;
"d")
appdir=${OPTARG}
;;
"v")
cozy_stack_version=${OPTARG}
;;
":")
echo_err "Option -${OPTARG} requires an argument"
echo_err "Type ${0} --help"
exit 1
;;
"?")
echo_err "Invalid option ${OPTARG}"
echo_err "Type ${0} --help"
exit 1
;;
esac
done
if [ -z "${appdir}" ]; then
echo_err "Missing application directory argument -d"
echo_err "Type ${0} --help"
exit 1
fi
if [ ! -d ${appdir} ]; then
echo_err "Application directory ${1} does not exit"
exit 1
fi
do_start
exit 0
......@@ -8,7 +8,7 @@ should be named `cozy.yaml` or `cozy.json` depending on the format of your
chosing, and should be present in one of these directories (ordered by
priority):
- `.cozy`
- `./.cozy`
- `$HOME/.cozy`
- `/etc/cozy`
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment