Dockerfile 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # setup build arguments for version of dependencies to use
  2. ARG NGINX_VERSION=1.19.3
  3. ARG GO_VERSION=1.14
  4. ARG DOCKER_GEN_VERSION=0.7.4
  5. ARG FOREGO_VERSION=0.16.1
  6. # Use a specific version of golang to build both binaries
  7. FROM golang:$GO_VERSION as gobuilder
  8. # Build docker-gen from scratch
  9. FROM gobuilder as dockergen
  10. # Download the sources for the given version
  11. ARG DOCKER_GEN_VERSION
  12. ADD https://github.com/jwilder/docker-gen/archive/${DOCKER_GEN_VERSION}.tar.gz sources.tar.gz
  13. # Move the sources into the right directory
  14. RUN tar -xzf sources.tar.gz && \
  15. mkdir -p /go/src/github.com/jwilder/ && \
  16. mv docker-gen-* /go/src/github.com/jwilder/docker-gen
  17. # Install the dependencies and make the docker-gen executable
  18. WORKDIR /go/src/github.com/jwilder/docker-gen
  19. RUN go get -v ./... && \
  20. CGO_ENABLED=0 GOOS=linux go build -ldflags "-X main.buildVersion=${DOCKER_GEN_VERSION}" ./cmd/docker-gen
  21. # Build forego from scratch
  22. # Because this relies on golang workspaces, we need to use go < 1.8.
  23. FROM gobuilder as forego
  24. # Download the sources for the given version
  25. ARG FOREGO_VERSION
  26. ADD https://github.com/jwilder/forego/archive/v${FOREGO_VERSION}.tar.gz sources.tar.gz
  27. # Move the sources into the right directory
  28. RUN tar -xzf sources.tar.gz && \
  29. mkdir -p /go/src/github.com/ddollar/ && \
  30. mv forego-* /go/src/github.com/ddollar/forego
  31. # Install the dependencies and make the forego executable
  32. WORKDIR /go/src/github.com/ddollar/forego/
  33. RUN go get -v ./... && \
  34. CGO_ENABLED=0 GOOS=linux go build -o forego .
  35. # Build the final image
  36. FROM nginx:$NGINX_VERSION
  37. LABEL maintainer="Jason Wilder mail@jasonwilder.com"
  38. # Install wget and install/updates certificates
  39. RUN apt-get update \
  40. && apt-get install -y -q --no-install-recommends \
  41. ca-certificates \
  42. wget \
  43. && apt-get clean \
  44. && rm -r /var/lib/apt/lists/*
  45. # Configure Nginx and apply fix for very long server names
  46. RUN echo "daemon off;" >> /etc/nginx/nginx.conf \
  47. && sed -i 's/worker_processes 1/worker_processes auto/' /etc/nginx/nginx.conf
  48. # Install Forego + docker-gen
  49. COPY --from=forego /go/src/github.com/ddollar/forego/forego /usr/local/bin/forego
  50. COPY --from=dockergen /go/src/github.com/jwilder/docker-gen/docker-gen /usr/local/bin/docker-gen
  51. # Add DOCKER_GEN_VERSION environment variable
  52. # Because some external projects rely on it
  53. ARG DOCKER_GEN_VERSION
  54. ENV DOCKER_GEN_VERSION=${DOCKER_GEN_VERSION}
  55. COPY network_internal.conf /etc/nginx/
  56. COPY . /app/
  57. WORKDIR /app/
  58. ENV DOCKER_HOST unix:///tmp/docker.sock
  59. VOLUME ["/etc/nginx/certs", "/etc/nginx/dhparam"]
  60. ENTRYPOINT ["/app/docker-entrypoint.sh"]
  61. CMD ["forego", "start", "-r"]