Dockerfile 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # setup build arguments for version of dependencies to use
  2. ARG DOCKER_GEN_VERSION=0.7.6
  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. ARG DOCKER_GEN_VERSION
  9. RUN git clone https://github.com/jwilder/docker-gen \
  10. && cd /go/docker-gen \
  11. && git -c advice.detachedHead=false checkout $DOCKER_GEN_VERSION \
  12. && go mod download \
  13. && CGO_ENABLED=0 GOOS=linux go build -ldflags "-X main.buildVersion=${DOCKER_GEN_VERSION}" ./cmd/docker-gen \
  14. && go clean -cache \
  15. && mv docker-gen /usr/local/bin/ \
  16. && cd - \
  17. && rm -rf /go/docker-gen
  18. # Build forego from scratch
  19. # Because this relies on golang workspaces, we need to use go < 1.8.
  20. FROM gobuilder as forego
  21. # Download the sources for the given version
  22. ARG FOREGO_VERSION
  23. ADD https://github.com/jwilder/forego/archive/v${FOREGO_VERSION}.tar.gz sources.tar.gz
  24. # Move the sources into the right directory
  25. RUN tar -xzf sources.tar.gz && \
  26. mkdir -p /go/src/github.com/ddollar/ && \
  27. mv forego-* /go/src/github.com/ddollar/forego
  28. # Install the dependencies and make the forego executable
  29. WORKDIR /go/src/github.com/ddollar/forego/
  30. RUN go get -v ./... && \
  31. CGO_ENABLED=0 GOOS=linux go build -o forego .
  32. # Build the final image
  33. FROM nginx:1.19.10
  34. LABEL maintainer="Nicolas Duchon <nicolas.duchon@gmail.com> (@buchdag)"
  35. # Install wget and install/updates certificates
  36. RUN apt-get update \
  37. && apt-get install -y -q --no-install-recommends \
  38. ca-certificates \
  39. wget \
  40. && apt-get clean \
  41. && rm -r /var/lib/apt/lists/*
  42. # Configure Nginx and apply fix for very long server names
  43. RUN echo "daemon off;" >> /etc/nginx/nginx.conf \
  44. && sed -i 's/worker_processes 1/worker_processes auto/' /etc/nginx/nginx.conf \
  45. && sed -i 's/worker_connections 1024/worker_connections 10240/' /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 /usr/local/bin/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"]