|
| 1 | +# Use Ubuntu 22.04 as the base image |
| 2 | +FROM ubuntu:22.04 |
| 3 | + |
| 4 | +# Set environment variables to prevent interactive prompts during package installation |
| 5 | +ARG DEBIAN_FRONTEND=noninteractive |
| 6 | + |
| 7 | +# Update package list and install necessary tools and dependencies |
| 8 | +RUN apt-get update && \ |
| 9 | + apt-get install -y \ |
| 10 | + git \ |
| 11 | + curl \ |
| 12 | + gnupg \ |
| 13 | + make \ |
| 14 | + build-essential \ |
| 15 | + pkg-config \ |
| 16 | + libzmq3-dev \ |
| 17 | + && rm -rf /var/lib/apt/lists/* |
| 18 | + |
| 19 | +# Install Go 1.21 based on the system architecture |
| 20 | +RUN ARCH=$(dpkg --print-architecture) && \ |
| 21 | + if [ "$ARCH" = "amd64" ]; then \ |
| 22 | + GO_ARCH="go1.21.0.linux-amd64.tar.gz"; \ |
| 23 | + elif [ "$ARCH" = "arm64" ]; then \ |
| 24 | + GO_ARCH="go1.21.0.linux-arm64.tar.gz"; \ |
| 25 | + else \ |
| 26 | + echo "Unsupported architecture"; exit 1; \ |
| 27 | + fi && \ |
| 28 | + curl -fsSL "https://go.dev/dl/$GO_ARCH" -o "$GO_ARCH" && \ |
| 29 | + tar -C /usr/local -xzf "$GO_ARCH" && \ |
| 30 | + rm "$GO_ARCH" && \ |
| 31 | + # Install Go language server |
| 32 | + /usr/local/go/bin/go install golang.org/x/tools/gopls@latest |
| 33 | + |
| 34 | +# Install golangci-lint |
| 35 | +RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin v1.54.2 |
| 36 | + |
| 37 | +# Create a non-root user with a home directory and bash as default shell |
| 38 | +ARG USERNAME=devuser |
| 39 | +ARG USER_UID=1000 |
| 40 | +ARG USER_GID=$USER_UID |
| 41 | + |
| 42 | +RUN groupadd --gid $USER_GID $USERNAME \ |
| 43 | + && useradd --uid $USER_UID --gid $USER_GID -m -s /bin/bash $USERNAME \ |
| 44 | + && apt-get update && apt-get install -y sudo \ |
| 45 | + && echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME \ |
| 46 | + && chmod 0440 /etc/sudoers.d/$USERNAME |
| 47 | + |
| 48 | +# Copy skeleton files to set up the user's shell environment |
| 49 | +RUN cp /etc/skel/.bashrc /home/$USERNAME/.bashrc \ |
| 50 | + && cp /etc/skel/.profile /home/$USERNAME/.profile \ |
| 51 | + && chown -R $USERNAME:$USERNAME /home/$USERNAME |
| 52 | + |
| 53 | +# Switch to the new user |
| 54 | +USER $USERNAME |
| 55 | + |
| 56 | +# Set the working directory |
| 57 | +WORKDIR /home/$USERNAME |
| 58 | +# Set up Go environment variables |
| 59 | +ENV PATH="/usr/local/go/bin:/usr/local/bin:${PATH}" |
| 60 | + |
| 61 | +# Ensure CGO is enabled for the zmq4 package |
| 62 | +ENV CGO_ENABLED=1 |
| 63 | + |
| 64 | +# Set the CGO CFLAGS and LDFLAGS for the zmq4 library |
| 65 | +ENV CGO_CFLAGS_ALLOW="-std=gnu99" |
| 66 | +ENV PKG_CONFIG_PATH="/usr/local/lib/pkgconfig" |
| 67 | + |
0 commit comments