diff --git a/.gitignore b/.gitignore index 5606b93b65..c96973cf9f 100644 --- a/.gitignore +++ b/.gitignore @@ -39,8 +39,5 @@ cmd/nginx-ingress/nginx-ingress # Default certificate and key default.pem -# Dockerfiles for building -/Dockerfile - # IntelliJ IDEA .idea diff --git a/Makefile b/Makefile index f01ca518d1..b3b16691dd 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ VERSION = edge TAG = $(VERSION) PREFIX = nginx/nginx-ingress +GOLANG_CONTAINER = golang:1.13 DOCKERFILEPATH = build DOCKERFILE = Dockerfile # note, this can be overwritten e.g. can be DOCKERFILE=DockerFileForPlus @@ -12,7 +13,7 @@ PUSH_TO_GCR = GENERATE_DEFAULT_CERT_AND_KEY = DOCKER_BUILD_OPTIONS = -GIT_COMMIT=$(shell git rev-parse --short HEAD) +GIT_COMMIT = $(shell git rev-parse --short HEAD) export DOCKER_BUILDKIT = 1 @@ -44,7 +45,7 @@ endif container: test verify-codegen binary certificate-and-key ifeq ($(BUILD_IN_CONTAINER),1) - docker build $(DOCKER_BUILD_OPTIONS) --build-arg IC_VERSION=$(VERSION)-$(GIT_COMMIT) --target container -f $(DOCKERFILEPATH)/$(DOCKERFILE) -t $(PREFIX):$(TAG) . + docker build $(DOCKER_BUILD_OPTIONS) --build-arg IC_VERSION=$(VERSION)-$(GIT_COMMIT) --build-arg GIT_COMMIT=$(GIT_COMMIT) --build-arg VERSION=$(VERSION) --build-arg GOLANG_CONTAINER=$(GOLANG_CONTAINER) --target container -f $(DOCKERFILEPATH)/$(DOCKERFILE) -t $(PREFIX):$(TAG) . else docker build $(DOCKER_BUILD_OPTIONS) --build-arg IC_VERSION=$(VERSION)-$(GIT_COMMIT) --target local -f $(DOCKERFILEPATH)/$(DOCKERFILE) -t $(PREFIX):$(TAG) . endif diff --git a/build/Dockerfile b/build/Dockerfile index 1ed800833e..9114a4b6dd 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,3 +1,5 @@ +ARG GOLANG_CONTAINER + FROM nginx:1.17.7 AS base # forward nginx access and error logs to stdout and stderr of the ingress @@ -36,7 +38,9 @@ FROM base AS local COPY nginx-ingress / -FROM golang:1.13 AS builder +FROM $GOLANG_CONTAINER AS builder +ARG VERSION +ARG GIT_COMMIT WORKDIR /go/src/github.com/nginxinc/kubernetes-ingress/nginx-ingress/cmd/nginx-ingress COPY . /go/src/github.com/nginxinc/kubernetes-ingress/nginx-ingress/ RUN CGO_ENABLED=0 GOFLAGS='-mod=vendor' \ diff --git a/build/DockerfileForAlpine b/build/DockerfileForAlpine index fa20800129..2dd50fee19 100644 --- a/build/DockerfileForAlpine +++ b/build/DockerfileForAlpine @@ -1,3 +1,5 @@ +ARG GOLANG_CONTAINER + FROM nginx:1.17.7-alpine AS base # forward nginx access and error logs to stdout and stderr of the ingress @@ -35,7 +37,9 @@ FROM base AS local COPY nginx-ingress / -FROM golang:1.13 AS builder +FROM $GOLANG_CONTAINER AS builder +ARG VERSION +ARG GIT_COMMIT WORKDIR /go/src/github.com/nginxinc/kubernetes-ingress/nginx-ingress/cmd/nginx-ingress COPY . /go/src/github.com/nginxinc/kubernetes-ingress/nginx-ingress/ RUN CGO_ENABLED=0 GOFLAGS='-mod=vendor' \ diff --git a/build/DockerfileForPlus b/build/DockerfileForPlus index 434229d74a..a78b733257 100644 --- a/build/DockerfileForPlus +++ b/build/DockerfileForPlus @@ -1,3 +1,5 @@ +ARG GOLANG_CONTAINER + FROM debian:stretch-slim AS base LABEL maintainer="NGINX Docker Maintainers " @@ -77,7 +79,9 @@ FROM base AS local COPY nginx-ingress / -FROM golang:1.13 AS builder +FROM $GOLANG_CONTAINER AS builder +ARG VERSION +ARG GIT_COMMIT WORKDIR /go/src/github.com/nginxinc/kubernetes-ingress/nginx-ingress/cmd/nginx-ingress COPY . /go/src/github.com/nginxinc/kubernetes-ingress/nginx-ingress/ RUN CGO_ENABLED=0 GOFLAGS='-mod=vendor' \ diff --git a/build/DockerfileWithOpentracing b/build/DockerfileWithOpentracing index ccbeb14dc5..fa58a678dd 100644 --- a/build/DockerfileWithOpentracing +++ b/build/DockerfileWithOpentracing @@ -1,5 +1,6 @@ ARG NGINX_VERSION=1.17.7 ARG OPENTRACING_CPP_VERSION=1.5.1 +ARG GOLANG_CONTAINER FROM nginx:${NGINX_VERSION} AS opentracing-builder ARG OPENTRACING_CPP_VERSION @@ -102,7 +103,9 @@ FROM base AS local COPY nginx-ingress / -FROM golang:1.13 AS builder +FROM $GOLANG_CONTAINER AS builder +ARG VERSION +ARG GIT_COMMIT WORKDIR /go/src/github.com/nginxinc/kubernetes-ingress/nginx-ingress/cmd/nginx-ingress COPY . /go/src/github.com/nginxinc/kubernetes-ingress/nginx-ingress/ RUN CGO_ENABLED=0 GOFLAGS='-mod=vendor' \ diff --git a/build/DockerfileWithOpentracingForPlus b/build/DockerfileWithOpentracingForPlus index 8e4cd58103..dc94581dd8 100644 --- a/build/DockerfileWithOpentracingForPlus +++ b/build/DockerfileWithOpentracingForPlus @@ -14,6 +14,7 @@ ENV NGINX_PLUS_VERSION 20-1~stretch ENV NGINX_OPENTRACING_MODULE_VERSION 20+0.9.0-1~stretch ARG IC_VERSION +ARG GOLANG_CONTAINER # Download certificate and key from the customer portal (https://cs.nginx.com) # and copy to the build context @@ -94,6 +95,8 @@ COPY nginx-ingress / FROM golang:1.13 AS builder +ARG VERSION +ARG GIT_COMMIT WORKDIR /go/src/github.com/nginxinc/kubernetes-ingress/nginx-ingress/cmd/nginx-ingress COPY . /go/src/github.com/nginxinc/kubernetes-ingress/nginx-ingress/ RUN CGO_ENABLED=0 GOFLAGS='-mod=vendor' \ diff --git a/docs-web/installation/building-ingress-controller-image.md b/docs-web/installation/building-ingress-controller-image.md index e1c129cbaa..0b9f156163 100644 --- a/docs-web/installation/building-ingress-controller-image.md +++ b/docs-web/installation/building-ingress-controller-image.md @@ -53,8 +53,8 @@ Next you will find the details about available Makefile targets and variables. ### Makefile Targets The **Makefile** we provide has the following targets: -* **test**: runs unit tests. -* **binary**: creates the controller binary. +* **test**: runs unit tests (ignored when `BUILD_IN_CONTAINER` is `1`). +* **binary**: creates the controller binary using local golang environment (ignored when `BUILD_IN_CONTAINER` is `1`). * **container**: builds a Docker image. * **push**: pushes the image to the private Docker registry. * **all** (the default target): executes the four targets above in the order listed. If one of the targets fails, the execution process stops, reporting an error.