From d07cdd923fce202df51d5f713ece52940acc1188 Mon Sep 17 00:00:00 2001 From: Bruno Michel <bmichel@menfin.info> Date: Tue, 23 Jul 2019 10:16:41 +0200 Subject: [PATCH] Fix self-hosted release with go modules (#1989) --- docs/docker.md | 3 ++- scripts/Dockerfile | 20 +++++++++++++------- scripts/build.sh | 3 +-- scripts/release.sh | 2 -- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/docs/docker.md b/docs/docker.md index 9d531ec67..dacd5e9a5 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 d71bad190..d0b00a272 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 53784e1a0..3ba7be48f 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 b5fcda04b..d61fc5214 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" -- GitLab