diff --git a/docs/docker.md b/docs/docker.md index 9d531ec67b3bf19ebdb7de260feb7493d88ae9c9..dacd5e9a5a695665508b4ec2100a0b561c737f8d 100644 --- a/docs/docker.md +++ b/docs/docker.md @@ -33,7 +33,8 @@ adapt to your own system. ```bash # From your cozy-stack developement folder docker run -it --rm --name cozy-stack \ - -v $(pwd):/go/src/github.com/cozy/cozy-stack \ + --workdir /app \ + -v $(pwd):/app \ -v $(pwd):/go/bin \ golang:1.12 \ go get -v github.com/cozy/cozy-stack diff --git a/scripts/Dockerfile b/scripts/Dockerfile index d71bad1909c713108b47e8d4a60f8a9df3807196..d0b00a2729678de203705ff9de50870a05ff04ed 100644 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -3,9 +3,9 @@ # It should not be used for hosting your cozy cloud in production. -# Multi-stage image: this step builds cozy-stack +# Multi-stage image: this step builds cozy-stack (and mailhog) FROM golang:1.12 as build -WORKDIR /go/src/github.com/cozy/cozy-stack +WORKDIR /app # MailHog ENV MAILHOG_SRC_URL=https://github.com/mailhog/MailHog/releases/download/v1.0.0/MailHog_linux_amd64 \ @@ -14,9 +14,15 @@ RUN set -eu; curl -fsSL "$MAILHOG_SRC_URL" -o MailHog \ && echo "$MAILHOG_SRC_SHA256 MailHog" | sha256sum -c - \ && chmod +x MailHog +# Use docker layer caching to avoid redownloading go modules if the code has +# changed but not the dependencies. +COPY go.mod . +COPY go.sum . +RUN go mod download + # Build cozy-stack COPY . . -RUN go get -d -v ./... && ./scripts/build.sh dev +RUN ./scripts/build.sh dev # Multi-stage image: the main image @@ -73,10 +79,10 @@ RUN set -eux; apt-get update \ COPY --from=build \ - /go/src/github.com/cozy/cozy-stack/cozy-stack \ - /go/src/github.com/cozy/cozy-stack/scripts/docker-entrypoint.sh \ - /go/src/github.com/cozy/cozy-stack/scripts/cozy-app-dev.sh \ - /go/src/github.com/cozy/cozy-stack/MailHog \ + /app/cozy-stack \ + /app/scripts/docker-entrypoint.sh \ + /app/scripts/cozy-app-dev.sh \ + /app/MailHog \ /usr/bin/ EXPOSE 8080 6060 8025 5984 diff --git a/scripts/build.sh b/scripts/build.sh index 53784e1a0d661ad84eaf1be62f1a2a1bf283c56b..3ba7be48f9580f0ec4e661d6a16281d4b02de92a 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -95,8 +95,7 @@ do_build() { 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} - " \ + -X github.com/cozy/cozy-stack/pkg/config.BuildMode=${BUILD_MODE}" \ -o "${BINARY}" popd > /dev/null echo "ok" diff --git a/scripts/release.sh b/scripts/release.sh index b5fcda04b0d084e1be80a272d17ad1a6b0cdfad4..d61fc521463e1c1a16c705d2e017d360e64a411d 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -3,8 +3,6 @@ set -xe RELEASE="$(git describe --tags)" -go get -u -v ./... || true # Always fail if you are in a tag… - docker build -t "cozy/cozy-app-dev:${RELEASE}" -f scripts/Dockerfile . docker push "cozy/cozy-app-dev:${RELEASE}" docker tag "cozy/cozy-app-dev:${RELEASE}" "cozy/cozy-app-dev:latest"