-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Reworked Dockerfile for a more production oriented usage #36
Conversation
- Added .dockerignore to speed up build context and avoid rebuilding when unecessary - Specified Alpine and Go versions as build arguments - Specified Go target CPU architecture as build arguments to be able to build for ARM devices - Specified base images as build arguments to be able to build for ARM devices - Trimmed down size of final image using `-a -installsuffix cgo -ldflags="-s -w"` go build flags and by copying the statically built binary only to the final image - Added clear build and run instructions for the Docker container
Hi there ! Hi ! I just added that so I can run your program without downloading the binary, especially for die hard of running everything in a Docker container... And added ARM build support too. By the way, it seems your program requires Git to function, is this expected? If not, we could manage to run it in a Scratch container as a static binary which would make it very tiny 👍 |
Hmm, I think that needing git to function is a bug. The initial codebase was taken from lazygit and maybe something wasn't removed yet. LGTM. Additionally you may want to add these to
I mean, really only version, commit and buildSource would be enough, cause specyfing date could destroy reproducible building. |
Done, I've added Docker labels with these as well, it might turn to be useful.
Also, is Thanks ! EDIT: Never mind, this issue arises with git from time to time as well. Maybe it's my terminal which sucks, I'm checking now. |
ok so it seems both However, running the container directly without first starting a shell So I will update the instructions, where you need to launch the container and then enter |
- Runs the container with `/bin/sh` initially - Invoke `lazydocker` from within the container, or gocui fails as the terminal window is invalid at launch
It works great on my linux host and my windows host, let me know if I should change anything ! |
Hey man thanks for making this :) Very impressive. I left one comment, other than that this LGTM, happy to merge if @dawidd6 is happy with it |
There seems to be a problem with getting containers logs. It works with normal installation, but not in Docker. @jesseduffield are the logs fetched from command line Docker client? |
diff --git a/Dockerfile b/Dockerfile
index 351e334..0abcc0f 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -24,5 +24,6 @@ LABEL org.label-schema.schema-version="1.0.0-rc1" \
org.label-schema.vcs-description="The lazier way to manage everything docker" \
org.label-schema.docker.cmd="docker run -it -v /var/run/docker.sock:/var/run/docker.sock lazydocker" \
org.label-schema.version=${VERSION}
-ENTRYPOINT [ "/bin/sh" ]
+RUN printf "resize > /dev/null\nlazydocker \$@\n" > /bin/run && chmod +x /bin/run
+ENTRYPOINT [ "sh", "/bin/run" ]
COPY --from=builder /go/src/github.com/jesseduffield/lazydocker/lazydocker /usr/bin/lazydocker
diff --git a/README.md b/README.md
index c651f8f..0af4172 100644
--- a/README.md
+++ b/README.md
@@ -97,8 +97,6 @@ go get github.com/jesseduffield/lazydocker
docker run -it -v /var/run/docker.sock:/var/run/docker.sock lazydocker
```
-1. Then enter `lazydocker`
-
## Usage
Call `lazydocker` in your terminal. I personally use this a lot so I've made an alias for it like so: @qdm12 you can apply this patch on top of your sources in |
@dawidd6 yes they are fetched vis the command line. Though there are various places in the app that use the docker client package to do things. Perhaps there are issues due to that? |
@jesseduffield heh, so now there are 2 possibilities:
Obviously the second one is an instant fix, but in the long run, would be better to do the first. Though I don't really know if it's feasible, would need to dig deeper into the code. |
- Git commit is passed as a build argument as explained in README.md - `.git` directory is ignored by Docker for a quicker build and smaller context - the build arg VCS_REF is used both to tag the image and the Go program
Thanks to the script: ```sh #!/bin/sh resize > /dev/null lazydocker $@ ```
as for the resize thing, perhaps we can something like this in app.go:
I'm in the middle of a long-running migration from dep to go modules right now so I can't actually test that locally :P |
- Build arguments are injected by the build hook - Badges added: number of pulls, stars and if the build is automated
Codecov Report
@@ Coverage Diff @@
## master #36 +/- ##
=======================================
Coverage 18.06% 18.06%
=======================================
Files 12 12
Lines 1052 1052
=======================================
Hits 190 190
Misses 856 856
Partials 6 6 Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #36 +/- ##
=======================================
Coverage 18.06% 18.06%
=======================================
Files 12 12
Lines 1052 1052
=======================================
Hits 190 190
Misses 856 856
Partials 6 6 Continue to review full report at Codecov.
|
Bind mount for the binary is not ideal unless the binary on the host is static and can work cross-OS. I have created a new ticket #109 to use the API instead of the CLI binary. |
I forgot where we were up to with this. If I recall correctly, it was ready to go? I think there might have been some discussion on another issue but I can't find it now |
I need this last question resolved Also now that you use go modules, I need to changed the go binary build stage as it should be different now. I will do that the coming 2 days. |
I'll be glad to test if you need help :) |
Hi all, I tested my latest Dockerfile with the lastest master code (using modules) and it fails with: go: finding github.com/davecgh/go-spew v1.1.1
go: finding github.com/client9/misspell v0.3.4
go: finding golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33
go: finding github.com/onsi/ginkgo v1.6.0
go: error loading module requirements
The command '/bin/sh -c go mod download' returned a non-zero code: 1 during my The full Dockerfile is: ARG BASE_IMAGE_BUILDER=golang
ARG ALPINE_VERSION=3.10
ARG GO_VERSION=1.12.6
FROM ${BASE_IMAGE_BUILDER}:${GO_VERSION}-alpine${ALPINE_VERSION} AS builder
ARG GOARCH=amd64
ARG GOARM
RUN apk --update -q --progress add git ca-certificates
RUN go get -u -v golang.org/x/vgo 2> /dev/null
WORKDIR /tmp/gobuild
COPY go.mod go.sum ./
RUN go mod download
COPY ./ .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${GOARCH} GOARM=${GOARM} go build -a -ldflags="-s -w \
-X main.commit=${VCS_REF} \
-X main.version=${VERSION} \
-X main.buildSource=Docker"
FROM scratch
ARG BUILD_DATE
ARG VCS_REF
ARG VERSION
LABEL org.label-schema.schema-version="1.0.0-rc1" \
maintainer="jessedduffield@gmail.com" \
org.label-schema.build-date=$BUILD_DATE \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.url="https://github.com/jesseduffield/lazydocker" \
org.label-schema.vcs-description="The lazier way to manage everything docker" \
org.label-schema.docker.cmd="docker run -it -v /var/run/docker.sock:/var/run/docker.sock lazydocker" \
org.label-schema.version=${VERSION}
ENTRYPOINT [ "/lazydocker" ]
VOLUME [ "/.config/jesseduffield/lazydocker" ]
COPY --from=builder /tmp/gobuild/lazydocker /lazydocker Any idea why is this? Thanks! |
RUN go get -u -v golang.org/x/vgo 2> /dev/null Why is this needed? COPY go.mod go.sum ./
RUN go mod download That's totally unnecessary. See below. RUN CGO_ENABLED=0 GOOS=linux GOARCH=${GOARCH} GOARM=${GOARM} go build -a -ldflags="-s -w \
-X main.commit=${VCS_REF} \
-X main.version=${VERSION} \
-X main.buildSource=Docker" Just append to this |
It's just to make the build faster, so that dependencies are not downloaded at every build. Do you think it's possible to For now I'll make it a one line build as you suggested but this is quite slow for development purposes. |
- Volume did not work properly as the config would be persistent but not shared across restart of the container running interactively. - Docker run instructions were therefore updated and simplified to bind mount the config directory as volume do not really work in this situation.
As @ibnesayeed mentionned, some environment variables are actually defined even in Scratch Docker images. `PATH` contains `/bin` so there is no need to overwrite it.
But you don't need to download dependencies as they are already available offline in |
Hi, that's great then, less work for me 😄 It would be eventually interesting to get rid of the vendor directory and have only git commit references in the go.mod file, or am I missing something out? Thanks. |
@jesseduffield likes vendoring, cause it makes it easier to quickly make changes to dependencies and see the results. Plus also with vendoring it is enough to just clone one repo and then build, while without vendoring there is also a need to download dependencies from different sources before building. So, in conclusion, I think that vendoring will stay here for a while. |
I just tried the newest iteration of |
I had my CPU stats working on my side. I'll try attaching to containers as well. Are you sure you are trying the last Dockerfile with the current master branch? |
Yep, i just merged this branch from your fork with latest upstream master and I don't get those stats. |
Me neither. I get the same result. I'd suggest merging this PR already as it is very outdated comparing to current master (go modules) and open another PR for fixing remaining issues. |
Yes I wanted to suggest the same thing but didn't want to be rude. It will still be much better than the current Dockerfile implementation. And, as you pointed out, it'll be easier to develop from a new branch as copying back and forth between repositories (one with modules, one without) isn't great. |
It is done. Please open another PR. |
I am using the latest Go installation, and I do not have Top or Stats working (This is installed on windows server 2019), what is the work around? To use the dockerfile for Lazydocker? |
-a -installsuffix cgo -ldflags="-s -w"
go build flags and by copying the statically built binary only to the final image