Dockerfile.dev 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # syntax=docker/dockerfile:1
  2. ARG GO_VERSION=1.23.8
  3. ARG ALPINE_VERSION=3.21
  4. # BUILDX_VERSION sets the version of buildx to install in the dev container.
  5. # It must be a valid tag in the docker.io/docker/buildx-bin image repository
  6. # on Docker Hub.
  7. ARG BUILDX_VERSION=0.23.0
  8. FROM docker/buildx-bin:${BUILDX_VERSION} AS buildx
  9. FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS golang
  10. ENV GOTOOLCHAIN=local
  11. ENV CGO_ENABLED=0
  12. FROM golang AS gofumpt
  13. ARG GOFUMPT_VERSION=v0.7.0
  14. RUN --mount=type=cache,target=/root/.cache/go-build \
  15. --mount=type=cache,target=/go/pkg/mod \
  16. --mount=type=tmpfs,target=/go/src/ \
  17. GO111MODULE=on go install "mvdan.cc/gofumpt@${GOFUMPT_VERSION}" \
  18. && gofumpt --version
  19. FROM golang AS gotestsum
  20. ARG GOTESTSUM_VERSION=v1.12.0
  21. RUN --mount=type=cache,target=/root/.cache/go-build \
  22. --mount=type=cache,target=/go/pkg/mod \
  23. --mount=type=tmpfs,target=/go/src/ \
  24. GO111MODULE=on go install gotest.tools/gotestsum@${GOTESTSUM_VERSION}
  25. FROM golang AS goversioninfo
  26. ARG GOVERSIONINFO_VERSION=v1.4.1
  27. RUN --mount=type=cache,target=/root/.cache/go-build \
  28. --mount=type=cache,target=/go/pkg/mod \
  29. --mount=type=tmpfs,target=/go/src/ \
  30. GO111MODULE=on go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo@${GOVERSIONINFO_VERSION}
  31. FROM golang AS dev
  32. RUN apk add --no-cache \
  33. bash \
  34. bash-completion \
  35. build-base \
  36. ca-certificates \
  37. coreutils \
  38. curl \
  39. git \
  40. jq \
  41. nano
  42. RUN <<-'EOF'
  43. cat > /etc/motd <<-'EOM'
  44. \e[1;32mYou are now in a development container.\e[0m
  45. Run \e[1;36mmake help\e[0m to see available targets.
  46. EOM
  47. cat >> /root/.bashrc <<-'EOB'
  48. # print the MOTD when opening the dev-container (interactive shell only).
  49. if [[ $- == *i* ]] && [[ -z "$MOTD_SHOWN" ]]; then
  50. printf "%b\n" "$(cat /etc/motd)"
  51. export MOTD_SHOWN=1
  52. fi
  53. # set a custom prompt to make it more visible when inside the dev-container.
  54. PS1='\[\e[0;32m\]\u@docker-cli-dev\$ \[\e[0m\]'
  55. # set-up bash completion for testing.
  56. source /etc/bash/bash_completion.sh
  57. EOB
  58. EOF
  59. CMD ["/bin/bash"]
  60. ENV DISABLE_WARN_OUTSIDE_CONTAINER=1
  61. ENV PATH=$PATH:/go/src/github.com/docker/cli/build
  62. COPY --link --from=buildx /buildx /usr/libexec/docker/cli-plugins/docker-buildx
  63. COPY --link --from=gofumpt /go/bin/* /go/bin/
  64. COPY --link --from=gotestsum /go/bin/* /go/bin/
  65. COPY --link --from=goversioninfo /go/bin/* /go/bin/
  66. WORKDIR /go/src/github.com/docker/cli
  67. ENV GO111MODULE=auto
  68. COPY --link . .