diff --git a/scripts/Dockerfile b/scripts/Dockerfile index 543f278d2eb629dad6b91d69f98f9b66b7a5ab19..c1cd25b69ab036feeddffaa8dc675b4943bd4a95 100644 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -4,31 +4,26 @@ FROM debian:jessie -# CouchDB and CGo dependencies + +# CouchDB +ENV COUCHDB_VERSION 2.0.0 +ENV COUCHDB_SRC_URL https://dist.apache.org/repos/dist/release/couchdb/source/$COUCHDB_VERSION/apache-couchdb-$COUCHDB_VERSION.tar.gz +ENV COUCHDB_SRC_SHA256 ccaf3ce9cb06c50a73e091696e557e2a57c5ba02c5b299e1ac2f5b959ee96eca + RUN apt-get update && apt-get install -y --no-install-recommends \ - bash \ - git \ + build-essential \ ca-certificates \ curl \ libicu52 \ libmozjs185-1.0 \ - erlang \ + erlang-nox \ + erlang-reltool \ + erlang-dev \ libicu-dev \ libmozjs185-dev \ openssl \ - g++ \ - gcc \ - libc6-dev \ - make \ - pkg-config \ - && rm -rf /var/lib/apt/lists/* - - -# CouchDB -ENV COUCHDB_VERSION 2.0.0 -ENV COUCHDB_SRC_URL https://dist.apache.org/repos/dist/release/couchdb/source/$COUCHDB_VERSION/apache-couchdb-$COUCHDB_VERSION.tar.gz -ENV COUCHDB_SRC_SHA256 ccaf3ce9cb06c50a73e091696e557e2a57c5ba02c5b299e1ac2f5b959ee96eca -RUN mkdir /usr/src/couchdb \ + && rm -rf /var/lib/apt/lists/* \ + && 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 \ @@ -37,43 +32,39 @@ RUN mkdir /usr/src/couchdb \ && ./configure --disable-docs \ && make release \ && mv ./rel/couchdb /usr/local \ - && rm -rf /usr/src/couchdb -ENV PATH $PATH:/usr/local/couchdb/bin - - -# Golang -ENV GOLANG_VERSION 1.7.4 -ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz -ENV GOLANG_DOWNLOAD_SHA256 47fda42e46b4c3ec93fa5d4d4cc6a748aa3f9411a2a2b7e08e3a6d80d753ec8b -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 - -ENV COZY_ENV development -RUN go get -d github.com/cozy/cozy-stack -RUN cd "$GOPATH/src/github.com/cozy/cozy-stack" \ - && ./scripts/build.sh install - - -# Cleanup -RUN apt-get purge -y \ + && rm -rf /usr/src/couchdb \ + # Cleanup + && apt-get purge -y \ + binutils \ + build-essential \ + cpp \ erlang-dev \ libicu-dev \ libmozjs185-dev \ - && apt-get autoremove -y \ - && apt-get clean + make \ + perl \ + && echo "[chttpd]\nbind_address = 0.0.0.0" \ + > /usr/local/couchdb/etc/local.ini \ + && apt-get autoremove -y && apt-get clean \ + && apt-get install -y libicu52 --no-install-recommends + +ENV PATH $PATH:/usr/local/couchdb/bin + + +# Caddy +ENV CADDY_VERSION v0.9.5 +ENV CADDY_DOWNLOAD_URL https://github.com/mholt/caddy/releases/download/$CADDY_VERSION/caddy_linux_amd64.tar.gz +ENV CADDY_DOWNLOAD_SHA256 c759640c9f56f7c4bb9fa828c0fa81a6e45f0f607e68677d56471bba53ad1777 +RUN curl -fsSL "$CADDY_DOWNLOAD_URL" -o caddy.tar.gz \ + && echo "$CADDY_DOWNLOAD_SHA256 caddy.tar.gz" | sha256sum -c - \ + && tar -xz -C "$GOPATH/bin" -f caddy.tar.gz caddy_linux_amd64 \ + && mv $GOPATH/bin/caddy_linux_amd64 $GOPATH/bin/caddy \ + && rm caddy.tar.gz -RUN echo "[chttpd]\nbind_address = 0.0.0.0" \ - > /usr/local/couchdb/etc/local.ini +# cozy-stack +COPY cozy-stack /usr/bin +RUN chmod +x /usr/bin/cozy-stack COPY cozy-app-dev.sh /usr/bin RUN chmod +x /usr/bin/cozy-app-dev.sh @@ -81,6 +72,8 @@ ENV COZY_PROXY_HOST cozy.local ENV COZY_PROXY_PORT 8080 ENV COZY_STACK_HOST localhost ENV COZY_STACK_PORT 8081 +ENV COZY_PROXY_PATH caddy +ENV COZY_STACK_PATH cozy-stack RUN mkdir -p /data/cozy-app && mkdir -p /data/cozy-storage diff --git a/scripts/build.sh b/scripts/build.sh index e6b538dbb12ba375095aed938d9111e75b432913..d54f1e75fab3accb9544cad00ae9aa84ff37047c 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -22,11 +22,12 @@ echo_err() { usage() { echo -e "Usage: ${1} [release] [install] [deploy] [assets] [clean]" echo -e "\nCommands:\n" - echo -e " release builds a release of the current working-tree" - echo -e " install builds a release and install it the GOPATH" - echo -e " deploy builds a release of the current working-tree and deploys it" - echo -e " assets move and download all the required assets (see: ./assets/externals)" - echo -e " clean remove all generated files from the working-tree" + echo -e " release builds a release of the current working-tree" + echo -e " install builds a release and install it the GOPATH" + echo -e " deploy builds a release of the current working-tree and deploys it" + echo -e " docker-dev builds a cozy-app-dev docker image" + echo -e " assets move and download all the required assets (see: ./assets/externals)" + echo -e " clean remove all generated files from the working-tree" echo -e "\nEnvironment variables:" echo -e "\n COZY_ENV" @@ -94,19 +95,7 @@ do_prepare_ldflags() { do_release() { check_env - do_prepare_ldflags - - do_assets - - BINARY="cozy-stack-${VERSION_STRING}" - - go build -ldflags "\ - -X github.com/cozy/cozy-stack/pkg/config.Version=${VERSION_STRING} \ - -X github.com/cozy/cozy-stack/pkg/config.BuildTime=${BUILD_TIME} \ - -X github.com/cozy/cozy-stack/pkg/config.BuildMode=${BUILD_MODE} - " \ - -o "${BINARY}" - + do_build openssl dgst -sha256 -hex "${BINARY}" > "${BINARY}.sha256" printf "${BINARY}\t" @@ -124,6 +113,26 @@ do_install() { -X github.com/cozy/cozy-stack/pkg/config.BuildMode=${BUILD_MODE}" } +do_build() { + check_env + + do_prepare_ldflags + do_assets + + if [ -z "${1}" ]; then + BINARY="cozy-stack-${VERSION_STRING}" + else + BINARY="${1}" + fi + + go build -ldflags "\ + -X github.com/cozy/cozy-stack/pkg/config.Version=${VERSION_STRING} \ + -X github.com/cozy/cozy-stack/pkg/config.BuildTime=${BUILD_TIME} \ + -X github.com/cozy/cozy-stack/pkg/config.BuildMode=${BUILD_MODE} + " \ + -o "${BINARY}" +} + # The deploy command will build a new release and deploy it on a # distant server using scp. To configure the distance server, you can # use the environment variables (see help usage): @@ -168,6 +177,25 @@ do_assets() { clean_assets } +do_docker_dev_image() { + docker_work_dir="${WORK_DIR}/.docker-work" + mkdir "${docker_work_dir}" + + trap "trap - SIGTERM && rm -rf "${docker_work_dir}" > /dev/null -- -${$}" SIGINT SIGTERM EXIT + + cp "${WORK_DIR}/scripts/Dockerfile" "${docker_work_dir}" + cp "${WORK_DIR}/scripts/cozy-app-dev.sh" "${docker_work_dir}" + + export GOOS=linux + export GOARCH=386 + export COZY_ENV=development + do_build "${docker_work_dir}/cozy-stack" + + docker build -t cozy/cozy-app-dev "${docker_work_dir}" + + rm -rf "${docker_work_dir}" +} + clean_assets() { rm -rf "${WORK_DIR}/.assets" } @@ -279,6 +307,10 @@ case "${1}" in do_assets ;; + docker-dev) + do_docker_dev_image + ;; + *) usage "${0}" exit 1 diff --git a/scripts/cozy-app-dev.sh b/scripts/cozy-app-dev.sh index f585b3248be5484c8f77f229c2f0f925193bb6e5..8db865894ac47628f2a2a6c8d36aaa1476c78541 100755 --- a/scripts/cozy-app-dev.sh +++ b/scripts/cozy-app-dev.sh @@ -56,41 +56,43 @@ usage() { echo -e " the script won't try to start couchdb." } -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_PROXY_PORT}" ]; then echo_err "COZY_STACK_HOST and COZY_PROXY_PORT are equal" exit 1 fi do_start() { - if [ ! -f "${GOPATH}/bin/caddy" ]; then - if [ -z `command -v go` ]; then - echo_err "executable \"go\" not found in \$PATH" - exit 1 + if [ -z "${COZY_PROXY_PATH}" ]; then + COZY_PROXY_PATH="${GOPATH}/bin/caddy" + if [ ! -f "${COZY_PROXY_PATH}" ]; 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 "github.com/mholt/caddy/caddy" + echo "ok" fi - printf "installing http server (caddy)... " - go get "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 + if [ -z `command -v go` ]; then + echo_err "executable \"go\" not found in \$PATH" + exit 1 + fi printf "installing cozy-stack... " go get "github.com/cozy/cozy-stack" echo "ok" fi fi + if [ -n "${cozy_stack_version}" ]; then + echo_err "not implemented... we do not have a release yet" + exit 1 + fi + if [ "$update" = true ]; then printf "updating cozy-stack... " go get -u "github.com/cozy/cozy-stack" @@ -214,7 +216,7 @@ app.${COZY_PROXY_HOST} { \n\ " printf "starting caddy on \"${site_root}\"... " - echo -e ${caddy_file} | ${GOPATH}/bin/caddy \ + echo -e ${caddy_file} | ${COZY_PROXY_PATH} \ -quiet \ -conf stdin \ -port ${COZY_PROXY_PORT} &