depado / goploader

Easy file sharing with server-side encryption, curl/httpie/wget compliant
https://docs.gpldr.in
MIT License
275 stars 41 forks source link

Failing to build using docker golang container #82

Open Halfwalker opened 3 years ago

Halfwalker commented 3 years ago

I usually use the docker golang container for building go projects - works quite nicely without needing golang installed locally. In this I attempted a build with

docker run --rm -v "/tmp":/output golang /bin/bash -c "go get github.com/Depado/goploader/server && go get github.com/GeertJohan/go.rice/rice && rice embed-go -i=github.com/Depado/goploader/server && go build github.com/Depado/goploader/server && cp src/github.com/Depado/goploader/server/{assets,templates} /output"

Basically duplicating what's in the README for a local build. It goes (heh) and downloads a bunch from github, but then reports this - it can't find go.mod anywhere

go: downloading github.com/Depado/goploader v0.0.0-20210411141917-6ae6953c8577
go: downloading github.com/GeertJohan/go.rice v1.0.0
go: downloading github.com/gin-gonic/gin v1.6.3
go: downloading github.com/ogier/pflag v0.0.1
go: downloading github.com/imdario/mergo v0.3.11
go: downloading github.com/asdine/storm v2.1.2+incompatible
go: downloading go.etcd.io/bbolt v1.3.5
go: downloading gopkg.in/yaml.v2 v2.3.0
go: downloading github.com/prometheus/client_golang v1.8.0
go: downloading github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5
go: downloading github.com/gin-gonic/contrib v0.0.0-20201101042839-6a891bf89f19
go: downloading github.com/fatih/color v1.10.0
go: downloading github.com/daaku/go.zipexe v1.0.1
go: downloading golang.org/x/sys v0.0.0-20201113233024-12cec1faf1ba
go: downloading github.com/mattn/go-isatty v0.0.12
go: downloading github.com/mattn/go-colorable v0.1.8
go: downloading github.com/ugorji/go v1.2.0
go: downloading github.com/golang/protobuf v1.4.3
go: downloading github.com/json-iterator/go v1.1.10
go: downloading github.com/gin-contrib/sse v0.1.0
go: downloading github.com/go-playground/validator/v10 v10.4.1
go: downloading github.com/prometheus/common v0.15.0
go: downloading github.com/prometheus/client_model v0.2.0
go: downloading github.com/beorn7/perks v1.0.1
go: downloading github.com/cespare/xxhash/v2 v2.1.1
go: downloading github.com/prometheus/procfs v0.2.0
go: downloading github.com/ugorji/go/codec v1.2.0
go: downloading github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
go: downloading github.com/modern-go/reflect2 v1.0.1
go: downloading google.golang.org/protobuf v1.25.0
go: downloading github.com/go-playground/universal-translator v0.17.0
go: downloading github.com/leodido/go-urn v1.2.0
go: downloading golang.org/x/crypto v0.0.0-20201112155050-0c6587e931a9
go: downloading github.com/matttproud/golang_protobuf_extensions v1.0.1
go: downloading github.com/go-playground/locales v0.13.0
go: downloading github.com/asdine/storm v1.1.0
go: downloading github.com/GeertJohan/go.rice v1.0.2
go: downloading github.com/akavel/rsrc v0.8.0
go: downloading github.com/daaku/go.zipexe v1.0.0
go: downloading github.com/GeertJohan/go.incremental v1.0.0
go: downloading github.com/jessevdk/go-flags v1.4.0
go: downloading github.com/nkovacs/streamquote v1.0.0
go: downloading github.com/valyala/fasttemplate v1.0.1
go: downloading github.com/valyala/bytebufferpool v1.0.0
error reading package: no required module provides package github.com/Depado/goploader/server: go.mod file not found in current directory or any parent directory; see 'go help modules'

Normally I like this method of building as it lends itself to ansible automation - can create a new binary in a single ansible task.

Halfwalker commented 3 years ago

I installed golang locally, and was able to build just fine ... It's the rice embed-go cmd that's failing. Here's the output from doing it via docker manually ...

$ docker run -it --rm -v $(pwd):/output golang /bin/bash

root@f998eaad95a2:/go# go get github.com/Depado/goploader/server
go: downloading github.com/Depado/goploader v0.0.0-20210411141917-6ae6953c8577
go: downloading github.com/gin-gonic/gin v1.6.3
go: downloading github.com/asdine/storm v2.1.2+incompatible
go: downloading github.com/GeertJohan/go.rice v1.0.0
go: downloading go.etcd.io/bbolt v1.3.5
go: downloading github.com/ogier/pflag v0.0.1
go: downloading github.com/prometheus/client_golang v1.8.0
go: downloading gopkg.in/yaml.v2 v2.3.0
go: downloading github.com/imdario/mergo v0.3.11
go: downloading github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5
go: downloading github.com/gin-gonic/contrib v0.0.0-20201101042839-6a891bf89f19
go: downloading github.com/fatih/color v1.10.0
go: downloading github.com/mattn/go-colorable v0.1.8
go: downloading github.com/mattn/go-isatty v0.0.12
go: downloading github.com/daaku/go.zipexe v1.0.1
go: downloading golang.org/x/sys v0.0.0-20201113233024-12cec1faf1ba
go: downloading github.com/ugorji/go v1.2.0
go: downloading github.com/golang/protobuf v1.4.3
go: downloading github.com/json-iterator/go v1.1.10
go: downloading github.com/gin-contrib/sse v0.1.0
go: downloading github.com/go-playground/validator/v10 v10.4.1
go: downloading github.com/prometheus/client_model v0.2.0
go: downloading github.com/prometheus/common v0.15.0
go: downloading github.com/prometheus/procfs v0.2.0
go: downloading github.com/cespare/xxhash/v2 v2.1.1
go: downloading github.com/beorn7/perks v1.0.1
go: downloading github.com/ugorji/go/codec v1.2.0
go: downloading google.golang.org/protobuf v1.25.0
go: downloading github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
go: downloading github.com/modern-go/reflect2 v1.0.1
go: downloading github.com/go-playground/universal-translator v0.17.0
go: downloading github.com/leodido/go-urn v1.2.0
go: downloading golang.org/x/crypto v0.0.0-20201112155050-0c6587e931a9
go: downloading github.com/matttproud/golang_protobuf_extensions v1.0.1
go: downloading github.com/go-playground/locales v0.13.0
go: downloading github.com/asdine/storm v1.1.0
root@f998eaad95a2:/go# go get github.com/GeertJohan/go.rice/rice
go: downloading github.com/GeertJohan/go.rice v1.0.2
go: downloading github.com/GeertJohan/go.incremental v1.0.0
go: downloading github.com/akavel/rsrc v0.8.0
go: downloading github.com/jessevdk/go-flags v1.4.0
go: downloading github.com/nkovacs/streamquote v1.0.0
go: downloading github.com/daaku/go.zipexe v1.0.0
go: downloading github.com/valyala/fasttemplate v1.0.1
go: downloading github.com/valyala/bytebufferpool v1.0.0
root@f998eaad95a2:/go# ls -la
total 11
drwxrwxrwx  5 root root  5 Apr 16 19:57 .
drwxr-xr-x 23 root root 24 Apr 16 19:57 ..
drwxrwxrwx  2 root root  4 Apr 16 19:58 bin
drwxr-xr-x  4 root root  4 Apr 16 19:57 pkg
drwxrwxrwx  2 root root  2 Apr 11 00:22 src
root@f998eaad95a2:/go# ls -la *
bin:
total 10338
drwxrwxrwx 2 root root        4 Apr 16 19:58 .
drwxrwxrwx 5 root root        5 Apr 16 19:57 ..
-rwxr-xr-x 1 root root  5502408 Apr 16 19:58 rice
-rwxr-xr-x 1 root root 16758645 Apr 16 19:58 server

pkg:
total 10
drwxr-xr-x 4 root root 4 Apr 16 19:57 .
drwxrwxrwx 5 root root 5 Apr 16 19:57 ..
drwxr-xr-x 8 root root 8 Apr 16 19:57 mod
drwxr-xr-x 3 root root 3 Apr 16 19:57 sumdb

src:
total 1
drwxrwxrwx 2 root root 2 Apr 11 00:22 .
drwxrwxrwx 5 root root 5 Apr 16 19:57 ..
root@f998eaad95a2:/go# env
HOSTNAME=f998eaad95a2
PWD=/go
HOME=/root
GOLANG_VERSION=1.16.3
TERM=xterm
SHLVL=1
PATH=/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
GOPATH=/go
_=/usr/bin/env
root@f998eaad95a2:/go# rice embed-go -i=github.com/Depado/goploader/server
error reading package: no required module provides package github.com/Depado/goploader/server: go.mod file not found in current directory or any parent directory; see 'go help modules'
depado commented 3 years ago

Hello, Sorry about that, but the docker image isn't working properly just yet and would require me to do a refactoring of the app (because as of today, goploader server doesn't support configuration with env variables). I'll eventually get to it but I have not the time for now...

Halfwalker commented 3 years ago

Ah, it's not to get goploader running in a container, it's just to use a golang container to build it - the rice embed-go cmd fails. Not sure what the difference is between a regular install of golang and the golang container is, but something ...

I suppose one could use a stock ubuntu container, install golang inside, then do the build. But that's a lot heavier and would take a bit longer - be nicer to just be able to use the official golang container.

So this actually works

docker run --rm -v "/tmp":/output ubuntu /bin/bash -c "apt update ; apt install -qq -y --no-install-recommends golang git ca-certificates ; echo 'getting goploader' ; go get github.com/Depado/goploader/server ; echo 'Building rice' ; go get github.com/GeertJohan/go.rice/rice ; echo 'Embedding assets' ; /root/go/bin/rice embed-go -i=github.com/Depado/goploader/server ; echo 'Building goploader' ; go build github.com/Depado/goploader/server ; cp /server /output/goploader_server"

Now, to get it working with the lightweight golang container directly, rather than the ubuntu container with installing golang ...

depado commented 3 years ago

That sure looks like a complex solution just to build the binary haha When I'll refactor this project I'll use something else than Rice because it's getting quite outdated.

Halfwalker commented 3 years ago

It's mainly to be able to build in in a CI/CD situation - drone, travis or github actions etc. They usually run things in a container, so getting the steps required to build it in a container .... Given that the CI/CD runners are usually busy, keeping things as lightweight and quick as possible always helps.

Halfwalker commented 3 years ago

Ideal would be if you could run

docker run --rm -v "/tmp":/output golang /bin/bash

then figure out the steps needed to build goploader in that environment.

depado commented 3 years ago

I'm using Drone to build and test, but it's been so long since I worked on this project that the .drone.yml is completely out of date unfortunately.