Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems when building the binary #47

Closed
ulm0 opened this issue Apr 20, 2018 · 8 comments
Closed

Problems when building the binary #47

ulm0 opened this issue Apr 20, 2018 · 8 comments
Labels
help wanted Extra attention is needed

Comments

@ulm0
Copy link
Contributor

ulm0 commented Apr 20, 2018

I'm building a Docker image for mouthful, everything went well until it attempts to build the binary

Dockerfile

FROM golang:1.10-alpine
ARG MOUTHFUL_VER
ENV CGO_ENABLED=${CGO_ENABLED:-0} \
    GOOS=${GOOS:-linux} \
    MOUTHFUL_VER=${MOUTHFUL_VER:-1.0.1}
RUN set -ex; \
    apk add --no-cache bash curl file git && \
    echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
    echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories && \
    apk add --no-cache upx nodejs nodejs-npm && \
    go get -d github.com/vkuznecovas/mouthful && \
    curl -sSL https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 -o /usr/bin/dep && \
    chmod +x /usr/bin/dep
WORKDIR /go/src/github.com/vkuznecovas/mouthful
RUN git checkout $MOUTHFUL_VER && \
    chmod +x build.sh && \
    ./build.sh && \
    cd dist/ && \
    file mouthful && \
    upx --best mouthful

FROM scratch
COPY --from=0 /go/src/github.com/vkuznecovas/mouthful/dist/ /
EXPOSE 8080
CMD ["/mouthful"]

Output

$ docker build -t mouthful .
Sending build context to Docker daemon  4.096kB
Step 1/10 : FROM golang:1.10-alpine
 ---> 52d894fca6d4
Step 2/12 : ARG MOUTHFUL_VER
 ---> Using cache
 ---> 31098fa6a859
Step 3/10 : ENV CGO_ENABLED=${CGO_ENABLED:-0}     GOOS=${GOOS:-linux}     MOUTHFUL_VER=${MOUTHFUL_VER:-1.0.1}
 ---> Using cache
 ---> 804edb0c5837
Step 4/10 : RUN set -ex;     apk add --no-cache bash curl file git &&     echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories &&     echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories &&     apk add --no-cache upxnodejs nodejs-npm &&     go get -d github.com/vkuznecovas/mouthful &&     curl -sSL https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 -o /usr/bin/dep &&     chmod +x /usr/bin/dep
 ---> Using cache
 ---> 4e97532d309b
Step 5/10 : WORKDIR /go/src/github.com/vkuznecovas/mouthful
 ---> Using cache
 ---> edf4092b2449
Step 6/10 : RUN git checkout $MOUTHFUL_VER &&     chmod +x build.sh &&     ./build.sh &&     cd dist/ &&     file mouthful &&     upx --best mouthful
 ---> Running in 59089bfa4c72
Note: checking out '1.0.1'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 93bb036... travis changes

> node-sass@4.5.3 install /go/src/github.com/vkuznecovas/mouthful/client/node_modules/node-sass
> node scripts/install.js

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.5.3/linux_musl-x64-57_binding.node
Download complete
Binary saved to /go/src/github.com/vkuznecovas/mouthful/client/node_modules/node-sass/vendor/linux_musl-x64-57/binding.node
Caching binary to /root/.npm/node-sass/4.5.3/linux_musl-x64-57_binding.node

> preact@8.2.5 postinstall /go/src/github.com/vkuznecovas/mouthful/client/node_modules/preact
> node -e "console.log('\u001b[35m\u001b[1mLove Preact? You can now donate to our open collective:\u001b[22m\u001b[39m\n > \u001b[34mhttps://opencollective.com/preact/donate\u001b[0m')"

Love Preact? You can now donate to our open collective:
 > https://opencollective.com/preact/donate

> uglifyjs-webpack-plugin@0.4.6 postinstall /go/src/github.com/vkuznecovas/mouthful/client/node_modules/uglifyjs-webpack-plugin
> node lib/post_install.js


> simplehttp2server@2.0.0 postinstall /go/src/github.com/vkuznecovas/mouthful/client/node_modules/simplehttp2server
> node lib/install.js


> node-sass@4.5.3 postinstall /go/src/github.com/vkuznecovas/mouthful/client/node_modules/node-sass
> node scripts/build.js

Binary found at /go/src/github.com/vkuznecovas/mouthful/client/node_modules/node-sass/vendor/linux_musl-x64-57/binding.node
Testing binary
Binary is fine

> preact-cli@2.0.2 postinstall /go/src/github.com/vkuznecovas/mouthful/client/node_modules/preact-cli
> node -p 'require("./check.js")()'

true
npm WARN client@0.1.0 No description
npm WARN client@0.1.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.2 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 1592 packages in 35.768s

> client@0.1.0 build /go/src/github.com/vkuznecovas/mouthful/client
> preact build --no-prerender --clean --template src/index.ejs --service-worker false

(node:90) DeprecationWarning: Chunk.modules is deprecated. Use Chunk.getNumberOfModules/mapModules/forEachModule/containsModule instead.

  Total precache size is about 110 kB for 5 resources.
npm WARN deprecated gulp-util@3.0.8: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5

> preact@8.2.7 postinstall /go/src/github.com/vkuznecovas/mouthful/admin/node_modules/preact
> node -e "console.log('\u001b[35m\u001b[1mLove Preact? You can now donate to our open collective:\u001b[22m\u001b[39m\n > \u001b[34mhttps://opencollective.com/preact/donate\u001b[0m')"

Love Preact? You can now donate to our open collective:
 > https://opencollective.com/preact/donate

> uglifyjs-webpack-plugin@0.4.6 postinstall /go/src/github.com/vkuznecovas/mouthful/admin/node_modules/uglifyjs-webpack-plugin
> node lib/post_install.js


> simplehttp2server@2.0.0 postinstall /go/src/github.com/vkuznecovas/mouthful/admin/node_modules/simplehttp2server
> node lib/install.js


> preact-cli@2.2.1 postinstall /go/src/github.com/vkuznecovas/mouthful/admin/node_modules/preact-cli
> node -p 'require("./check.js")()'

true
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.0 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.0: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 1787 packages in 47.606s

> admin@0.0.0 build /go/src/github.com/vkuznecovas/mouthful/admin
> preact build


  Total precache size is about 51.3 kB for 6 resources.
# github.com/vkuznecovas/mouthful/vendor/github.com/mattn/go-sqlite3
vendor/github.com/mattn/go-sqlite3/sqlite3_go18.go:18:10: undefined: SQLiteConn
chmod: dist/mouthful: No such file or directory
mouthful: cannot open `mouthful' (No such file or directory)
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2017
UPX 3.94        Markus Oberhumer, Laszlo Molnar & John Reiser   May 12th 2017

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------

Packed 0 files.
upx: mouthful: FileNotFoundException: mouthful: No such file or directory
The command '/bin/sh -c git checkout $MOUTHFUL_VER &&     chmod +x build.sh &&     ./build.sh &&     cd dist/ &&     file mouthful && upx --best mouthful' returned a non-zero code: 1

It all seems the problem is at vendor/github.com/mattn/go-sqlite3/sqlite3_go18.go:18:10: undefined: SQLiteConn.

@ulm0
Copy link
Contributor Author

ulm0 commented Apr 20, 2018

Switched to FROM golang:1.8-alpine, more errors

...
# github.com/vkuznecovas/mouthful/vendor/github.com/mattn/go-sqlite3
vendor/github.com/mattn/go-sqlite3/sqlite3_go18.go:18: undefined: SQLiteConn
vendor/github.com/mattn/go-sqlite3/sqlite3_go18.go:26: undefined: SQLiteConn
vendor/github.com/mattn/go-sqlite3/sqlite3_go18.go:27: undefined: namedValue
vendor/github.com/mattn/go-sqlite3/sqlite3_go18.go:29: undefined: namedValue
vendor/github.com/mattn/go-sqlite3/sqlite3_go18.go:35: undefined: SQLiteConn
vendor/github.com/mattn/go-sqlite3/sqlite3_go18.go:36: undefined: namedValue
vendor/github.com/mattn/go-sqlite3/sqlite3_go18.go:44: undefined: SQLiteConn
vendor/github.com/mattn/go-sqlite3/sqlite3_go18.go:49: undefined: SQLiteConn
vendor/github.com/mattn/go-sqlite3/sqlite3_go18.go:54: undefined: SQLiteStmt
vendor/github.com/mattn/go-sqlite3/sqlite3_go18.go:63: undefined: SQLiteStmt
vendor/github.com/mattn/go-sqlite3/sqlite3_go18.go:36: too many errors
...

@vkuznecovas
Copy link
Owner

This is not an issue with mouthful per-se it's an issue with one of its dependencies, github.com/mattn/go-sqlite3. Go-sqlite3 is a pain to cross build for, you gotta have a toolchain to build it for another os. What OS are you building the container on?

@ulm0
Copy link
Contributor Author

ulm0 commented Apr 21, 2018

I'm bulding it on Linux (Manjaro 17.1.7) with Docker CE v18.03, any way i can help you solve this? @vkuznecovas

@vkuznecovas
Copy link
Owner

vkuznecovas commented Apr 21, 2018

Care to try with CGO_ENABLED=1 ?

mattn/go-sqlite3#483
mattn/go-sqlite3#384

@vkuznecovas vkuznecovas added the help wanted Extra attention is needed label Apr 21, 2018
@ulm0
Copy link
Contributor Author

ulm0 commented Apr 21, 2018

Sure i can, btw any specific version to build this? Go 1.8 and later? 1.10?

@ulm0
Copy link
Contributor Author

ulm0 commented Apr 21, 2018

@vkuznecovas, first attempt to build with golang 1.8 successful

  • Dockerfile:
FROM golang:1.8-alpine
ARG GOARCH
ARG GOARM
ARG MOUTHFUL_VER
ENV CGO_ENABLED=${CGO_ENABLED:-1} \
    GOARCH=${GOARCH:-} \
    GOARM=${GOARM:-} \
    GOOS=${GOOS:-linux} \
    MOUTHFUL_VER=${MOUTHFUL_VER:-1.0.2}
RUN set -ex; \
    apk add --no-cache bash build-base curl file git && \
    echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
    echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories && \
    apk add --no-cache upx nodejs nodejs-npm && \
    go get -d github.com/vkuznecovas/mouthful && \
    curl -sSL https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 -o /usr/bin/dep && \
    chmod +x /usr/bin/dep
WORKDIR /go/src/github.com/vkuznecovas/mouthful
RUN git checkout $MOUTHFUL_VER && \
    chmod +x build.sh && \
    ./build.sh && \
    cd dist/ && \
    file mouthful && \
    upx --best mouthful && \
    file mouthful

FROM alpine:3.7
COPY --from=0 /go/src/github.com/vkuznecovas/mouthful/dist/ /
EXPOSE 8080
CMD ["/mouthful"]

Added GOARCH and GOARMargs for trying to cross-build later

  • docker build output:
$ docker build -t mouthful .
Sending build context to Docker daemon  4.096kB
Step 1/12 : FROM golang:1.8-alpine
 ---> 4cb86d3661bf
Step 2/12 : ARG GOARCH
 ---> Using cache
 ---> 64939569ca50
Step 3/12 : ARG GOARM
 ---> Using cache
 ---> 1684d0891686
Step 4/12 : ARG MOUTHFUL_VER
 ---> Using cache
 ---> c39a0bd3b7af
Step 5/12 : ENV CGO_ENABLED=${CGO_ENABLED:-1}     GOARCH=${GOARCH:-}     GOARM=${GOARM:-}     GOOS=${GOOS:-linux}     MOUTHFUL_VER=${MOUTHFUL_VER:-1.0.2}
 ---> Using cache
 ---> 594204077365
Step 6/12 : RUN set -ex;     apk add --no-cache bash build-base curl file git &&     echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories &&     echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories &&     apk add --no-cache upx nodejs nodejs-npm &&     go get -d github.com/vkuznecovas/mouthful &&     curl -sSL https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 -o /usr/bin/dep &&     chmod +x /usr/bin/dep
 ---> Using cache
 ---> 92c81d7452c0
Step 7/12 : WORKDIR /go/src/github.com/vkuznecovas/mouthful
 ---> Using cache
 ---> d8c76624cb9d
Step 8/12 : RUN git checkout $MOUTHFUL_VER &&     chmod +x build.sh &&     ./build.sh &&     cd dist/ &&     file mouthful &&     upx --best mouthful &&     file mouthful
 ---> Running in 4a48e4056d56
Note: checking out '1.0.2'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 216eccc... removed redundant logging

> node-sass@4.5.3 install /go/src/github.com/vkuznecovas/mouthful/client/node_modules/node-sass
> node scripts/install.js

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.5.3/linux_musl-x64-57_binding.node
Download complete
Binary saved to /go/src/github.com/vkuznecovas/mouthful/client/node_modules/node-sass/vendor/linux_musl-x64-57/binding.node
Caching binary to /root/.npm/node-sass/4.5.3/linux_musl-x64-57_binding.node

> preact@8.2.5 postinstall /go/src/github.com/vkuznecovas/mouthful/client/node_modules/preact
> node -e "console.log('\u001b[35m\u001b[1mLove Preact? You can now donate to our open collective:\u001b[22m\u001b[39m\n > \u001b[34mhttps://opencollective.com/preact/donate\u001b[0m')"

Love Preact? You can now donate to our open collective:
 > https://opencollective.com/preact/donate

> uglifyjs-webpack-plugin@0.4.6 postinstall /go/src/github.com/vkuznecovas/mouthful/client/node_modules/uglifyjs-webpack-plugin
> node lib/post_install.js


> simplehttp2server@2.0.0 postinstall /go/src/github.com/vkuznecovas/mouthful/client/node_modules/simplehttp2server
> node lib/install.js


> node-sass@4.5.3 postinstall /go/src/github.com/vkuznecovas/mouthful/client/node_modules/node-sass
> node scripts/build.js

Binary found at /go/src/github.com/vkuznecovas/mouthful/client/node_modules/node-sass/vendor/linux_musl-x64-57/binding.node
Testing binary
Binary is fine

> preact-cli@2.0.2 postinstall /go/src/github.com/vkuznecovas/mouthful/client/node_modules/preact-cli
> node -p 'require("./check.js")()'

true
npm WARN client@0.1.0 No description
npm WARN client@0.1.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.2 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 1592 packages in 42.109s

> client@0.1.0 build /go/src/github.com/vkuznecovas/mouthful/client
> preact build --no-prerender --clean --template src/index.ejs --service-worker false

(node:89) DeprecationWarning: Chunk.modules is deprecated. Use Chunk.getNumberOfModules/mapModules/forEachModule/containsModule instead.

  Total precache size is about 110 kB for 5 resources.
npm WARN deprecated gulp-util@3.0.8: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5

> preact@8.2.7 postinstall /go/src/github.com/vkuznecovas/mouthful/admin/node_modules/preact
> node -e "console.log('\u001b[35m\u001b[1mLove Preact? You can now donate to our open collective:\u001b[22m\u001b[39m\n > \u001b[34mhttps://opencollective.com/preact/donate\u001b[0m')"

Love Preact? You can now donate to our open collective:
 > https://opencollective.com/preact/donate

> uglifyjs-webpack-plugin@0.4.6 postinstall /go/src/github.com/vkuznecovas/mouthful/admin/node_modules/uglifyjs-webpack-plugin
> node lib/post_install.js


> simplehttp2server@2.0.0 postinstall /go/src/github.com/vkuznecovas/mouthful/admin/node_modules/simplehttp2server
> node lib/install.js


> preact-cli@2.2.1 postinstall /go/src/github.com/vkuznecovas/mouthful/admin/node_modules/preact-cli
> node -p 'require("./check.js")()'

true
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.0 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.0: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 1787 packages in 46.889s

> admin@0.0.0 build /go/src/github.com/vkuznecovas/mouthful/admin
> preact build


  Total precache size is about 51.3 kB for 6 resources.
mouthful: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, not stripped
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2017
UPX 3.94        Markus Oberhumer, Laszlo Molnar & John Reiser   May 12th 2017

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
  26995064 ->   7621240   28.23%   linux/amd64   mouthful

Packed 1 file.
mouthful: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
Removing intermediate container 4a48e4056d56
 ---> 48195ebd4fef
Step 9/12 : FROM alpine:3.7
 ---> 3fd9065eaf02
Step 10/12 : COPY --from=0 /go/src/github.com/vkuznecovas/mouthful/dist/ /
 ---> f74e6b003899
Step 11/12 : EXPOSE 8080
 ---> Running in c4f0e011cfba
Removing intermediate container c4f0e011cfba
 ---> 217a7ecbac7b
Step 12/12 : CMD ["/mouthful"]
 ---> Running in 1414d1f70af5
Removing intermediate container 1414d1f70af5
 ---> a8f1e13af887
Successfully built a8f1e13af887
Successfully tagged mouthful:latest
  • docker run output:
$ docker run --rm -p 8080:8080 mouthful
panic: Please change the config.Moderation.AdminPassword value in config. Do not leave the default there

goroutine 1 [running]:
main.main()
        /go/src/github.com/vkuznecovas/mouthful/main.go:40 +0x486

Most likely i'll change the default config location to somewhere else, if you agree, so i can add something like VOLUME /data/ to the Dockerfile in order to persist the configuration and the db.

@vkuznecovas
Copy link
Owner

I think anything above 1.8 GO should work. Nice to see you got it built. Do make a PR with the default config change :)

@ulm0
Copy link
Contributor Author

ulm0 commented Apr 24, 2018

Will do, but before I'm gonna test it out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants