Dockerfile 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. FROM mcr.microsoft.com/devcontainers/base:jammy
  2. # Combine installation steps for Nginx and Go to avoid repetitive update/cleanup commands
  3. RUN apt-get update && \
  4. apt-get install -y --no-install-recommends curl gnupg2 ca-certificates lsb-release ubuntu-keyring jq cloc && \
  5. \
  6. # Configure the Nginx repository
  7. curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor > /usr/share/keyrings/nginx-archive-keyring.gpg && \
  8. echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/mainline/ubuntu $(lsb_release -cs) nginx" \
  9. > /etc/apt/sources.list.d/nginx.list && \
  10. printf "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
  11. > /etc/apt/preferences.d/99nginx && \
  12. \
  13. # Update package information and install Nginx
  14. apt-get update && \
  15. apt-get install -y --no-install-recommends nginx inotify-tools file && \
  16. \
  17. # Automatically retrieve the latest stable Go version and install it,
  18. # download the appropriate binary based on system architecture (amd64 or arm64)
  19. GO_VERSION=$(curl -sSL "https://golang.org/dl/?mode=json" | \
  20. jq -r 'map(select(.stable)) | .[0].version' | sed 's/^go//') && \
  21. ARCH=$(dpkg --print-architecture) && \
  22. if [ "$ARCH" = "arm64" ]; then \
  23. GO_ARCH=linux-arm64; \
  24. else \
  25. GO_ARCH=linux-amd64; \
  26. fi && \
  27. echo "Installing Go version: ${GO_VERSION} for architecture: ${GO_ARCH}" && \
  28. curl -sSL "https://golang.org/dl/go${GO_VERSION}.${GO_ARCH}.tar.gz" -o go.tar.gz && \
  29. rm -rf /usr/local/go && \
  30. tar -C /usr/local -xzf go.tar.gz && \
  31. rm go.tar.gz && \
  32. \
  33. # Remove jq and clean up to reduce image size
  34. apt-get remove -y jq && \
  35. apt-get autoremove -y && \
  36. apt-get clean && \
  37. rm -rf /var/lib/apt/lists/*
  38. RUN cp -rp /etc/nginx /etc/nginx.orig
  39. # Set PATH to include Go installation and default go install binary location
  40. ENV PATH="/usr/local/go/bin:/root/go/bin:${PATH}"
  41. # Install air with go install (requires Go 1.23 or higher)
  42. RUN go install github.com/air-verse/air@latest
  43. # set zsh as default shell
  44. RUN chsh -s $(which zsh)