forked from nginx-proxy/nginx-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
81 lines (64 loc) · 2.8 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# setup build arguments for version of dependencies to use
ARG NGINX_VERSION=
ARG GO_VERSION=1.22.0
ARG DOCKER_GEN_VERSION=0.12.0
ARG FOREGO_VERSION=0.18.1
# Use a specific version of golang to build both binaries
FROM --platform=linux/amd64 golang:$GO_VERSION as gobuilder
# Build docker-gen from scratch
FROM gobuilder as dockergen
# Download the sources for the given version
ARG DOCKER_GEN_VERSION
ADD https://github.com/nginx-proxy/docker-gen/archive/refs/tags/${DOCKER_GEN_VERSION}.tar.gz sources.tar.gz
RUN tar -xzf sources.tar.gz \
&& mkdir -p /go/src/github.com/jwilder/ \
&& mv docker-gen-* /go/src/github.com/jwilder/docker-gen \
&& cd /go/src/github.com/jwilder/docker-gen \
&& go get -v ./... \
&& CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.buildVersion=${DOCKER_GEN_VERSION}" ./cmd/docker-gen
FROM gobuilder as forego
ARG FOREGO_VERSION
ADD https://github.com/nginx-proxy/forego/archive/refs/tags/v${FOREGO_VERSION}.tar.gz sources.tar.gz
ENV GO111MODULE=auto
RUN tar -xzf sources.tar.gz \
&& mkdir -p /go/src/github.com/ddollar/ \
&& mv forego-* /go/src/github.com/ddollar/forego \
&& cd /go/src/github.com/ddollar/forego/ \
&& go get -v ./... \
&& CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o forego .
FROM --platform=linux/amd64 nginx:${NGINX_VERSION}
LABEL maintainer="Jonathan Adami <[email protected]>"
LABEL creator="Jason Wilder <[email protected]>"
ENV DOCKER_HOST=unix:///tmp/docker.sock
COPY ./crons/crontab /etc/cron.d/root
COPY ./crons/run-cronjob.sh /usr/local/bin/run-cronjob
# Install python with crossplane, wget, cron and install/updates certificates
RUN apt-get update \
&& apt-get install -y -q --no-install-recommends \
ca-certificates \
wget \
cron \
python3 python3.11-venv \
&& python3 -m venv $HOME/.venvs/crossplane \
&& /root/.venvs/crossplane/bin/pip3 install crossplane \
&& apt-get purge -y python3.11-venv \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -r /var/lib/apt/lists/*
# Configure Nginx and apply fix for very long server names
COPY ./nginx/network_internal.conf /etc/nginx/
COPY ./nginx/healthcheck.conf /etc/nginx/conf.d
RUN echo "daemon off;" >> /etc/nginx/nginx.conf \
&& sed -i 's/worker_processes 1/worker_processes auto/' /etc/nginx/nginx.conf \
&& mkdir /etc/nginx/node.conf.d \
&& mkdir /etc/nginx/certs \
&& echo "http { include ./*.conf; }" > /etc/nginx/node.conf.d/swarm.conf
# Install Forego / Dockergen
COPY --from=forego /go/src/github.com/ddollar/forego/forego /usr/local/bin/forego
COPY --from=dockergen /go/src/github.com/jwilder/docker-gen/docker-gen /usr/local/bin/docker-gen
COPY ./app/ /app/
WORKDIR /app/
HEALTHCHECK CMD /app/nginx-healthcheck.sh
VOLUME ["/etc/nginx/static_files", "/etc/nginx/node.conf.d"]
ENTRYPOINT ["/app/docker-entrypoint.sh"]
CMD ["forego", "start", "-r"]