Dockerfile 2.5 KB

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