From 676eed1bea0cb0a767f452f3784f8b3eb6e3d989 Mon Sep 17 00:00:00 2001 From: Francesco Tassi Date: Thu, 19 May 2022 09:15:36 +0200 Subject: [PATCH] Speed up gopls startup Go runtime is installed in /go which is word writable so there is no need for a dedicated user. This removes the need to usermod at runtime which was very time consuming. Not having to manipulate the user at runtime allows to remove the entrypoint script entirely. With this setup the language server is up and running in milliseconds rather than seconds. I based this image on official golang alpine image to avoid as much duplication as possible --- servers/gopls/Dockerfile | 20 +++++++------------- servers/gopls/docker_entrypoint.sh | 11 ----------- 2 files changed, 7 insertions(+), 24 deletions(-) delete mode 100755 servers/gopls/docker_entrypoint.sh diff --git a/servers/gopls/Dockerfile b/servers/gopls/Dockerfile index 2217394..2eb0364 100644 --- a/servers/gopls/Dockerfile +++ b/servers/gopls/Dockerfile @@ -1,21 +1,14 @@ -FROM alpine:3.15.0 +FROM golang:1.18.2-alpine RUN apk add --no-cache \ - go \ shadow \ + gcc \ + musl-dev \ + su-exec \ sudo ENV GO111MODULE="on" -RUN addgroup -g 1001 gopls \ - && adduser -u 1000 -G gopls -h /home/gopls -D gopls \ - && echo '%gopls ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/gopls - -USER gopls - -ENV GOBIN="/home/gopls/.bin" -ENV PATH="${GOBIN}:$PATH" - RUN go install github.com/uudashr/gopkgs/v2/cmd/gopkgs@latest \ && go install github.com/ramya-rao-a/go-outline@latest \ && go install github.com/cweill/gotests/gotests@latest \ @@ -27,6 +20,7 @@ RUN go install github.com/uudashr/gopkgs/v2/cmd/gopkgs@latest \ && go install honnef.co/go/tools/cmd/staticcheck@latest \ && go install golang.org/x/tools/gopls@latest -COPY docker_entrypoint.sh /home/gopls/docker_entrypoint.sh +ENV GOCACHE /tmp/gocache +ENV GOROOT /usr/local/go -CMD [ "/home/gopls/docker_entrypoint.sh" ] +CMD [ "gopls" ] diff --git a/servers/gopls/docker_entrypoint.sh b/servers/gopls/docker_entrypoint.sh deleted file mode 100755 index a8f4160..0000000 --- a/servers/gopls/docker_entrypoint.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -set -e - -GOPLS_USER="$(id -u)" -GOPLS_GROUP="$(id -g)" - -sudo usermod -u $GOPLS_USER gopls \ - && sudo groupmod -g $GOPLS_GROUP gopls \ - && sudo chown -R "$GOPLS_USER:$GOPLS_GROUP" /home/gopls \ - && echo "$GOPLS_USER:$GOPLS_GROUP" \ - && exec "gopls"