Dockerfile 2.5 KB

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