From 061ee6e5f5af6d069a795bd6bcdccd57bf08b28f Mon Sep 17 00:00:00 2001 From: John Eikenberry Date: Mon, 14 Jun 2021 17:22:19 -0700 Subject: [PATCH] remove stuff related to old build system clear out Makefile targets for release and Docker builds remove all old Docker configuration and support files --- Makefile | 205 +---------------------------- docker/alpine/Dockerfile | 58 -------- docker/alpine/docker-entrypoint.sh | 30 ----- docker/light/Dockerfile | 27 ---- docker/pristine/Dockerfile | 8 -- docker/scratch/Dockerfile | 27 ---- 6 files changed, 3 insertions(+), 352 deletions(-) delete mode 100644 docker/alpine/Dockerfile delete mode 100755 docker/alpine/docker-entrypoint.sh delete mode 100644 docker/light/Dockerfile delete mode 100644 docker/pristine/Dockerfile delete mode 100644 docker/scratch/Dockerfile diff --git a/Makefile b/Makefile index f0555360a..e1dddd743 100644 --- a/Makefile +++ b/Makefile @@ -2,22 +2,13 @@ MKFILE_PATH := $(lastword $(MAKEFILE_LIST)) CURRENT_DIR := $(patsubst %/,%,$(dir $(realpath $(MKFILE_PATH)))) -# Ensure GOPATH -GOPATH ?= $(shell go env GOPATH) -# assume last entry in GOPATH is home to project -GOPATH := $(lastword $(subst :, ,${GOPATH})) - # Tags specific for building GOTAGS ?= -# Number of procs to use -GOMAXPROCS ?= 4 - # Get the project metadata -GO_DOCKER_VERSION ?= 1.13 -PROJECT := $(shell go list -m -mod=vendor) OWNER := "hashicorp" -NAME := $(notdir $(PROJECT)) +NAME := "consul-template" +PROJECT := $(shell go list -m) GIT_COMMIT ?= $(shell git rev-parse --short HEAD || echo release) VERSION := $(shell awk -F\" '/Version/ { print $$2; exit }' "${CURRENT_DIR}/version/version.go") @@ -25,81 +16,15 @@ VERSION := $(shell awk -F\" '/Version/ { print $$2; exit }' "${CURRENT_DIR}/vers GOOS ?= $(shell go env GOOS) GOARCH ?= $(shell go env GOARCH) -# Default os-arch combination to build -XC_OS ?= darwin freebsd linux netbsd openbsd solaris windows -XC_ARCH ?= 386 amd64 arm arm64 -# XC_EXCLUDE "arm64" entries excludes both arm and arm64 -XC_EXCLUDE ?= darwin/arm64 freebsd/arm64 netbsd/arm64 openbsd/arm64 solaris/arm64 windows/arm64 solaris/386 - -# GPG Signing key (blank by default, means no GPG signing) -GPG_KEY ?= - # List of ldflags LD_FLAGS ?= \ -s \ -w \ - -X ${PROJECT}/version.Name=${NAME} \ -X ${PROJECT}/version.GitCommit=${GIT_COMMIT} -# List of Docker targets to build -DOCKER_TARGETS ?= alpine light scratch - -# Create a cross-compile target for every os-arch pairing. This will generate -# a make target for each os/arch like "make linux/amd64" as well as generate a -# meta target (build) for compiling everything. -define make-xc-target - $1/$2: - ifneq (,$(findstring ${1}/${2},$(XC_EXCLUDE))) - @printf "%s%20s %s\n" "-->" "${1}/${2}:" "${PROJECT} (excluded)" - else - @printf "%s%20s %s\n" "-->" "${1}/${2}:" "${PROJECT}" - env \ - CGO_ENABLED="0" \ - GOOS="${1}" \ - GOARCH="${2}" \ - go build \ - -a \ - -o="pkg/${1}_${2}/${NAME}${3}" \ - -ldflags "${LD_FLAGS}" \ - -tags "${GOTAGS}" - endif - .PHONY: $1/$2 - - $1:: $1/$2 - .PHONY: $1 - - build:: $1/$2 - .PHONY: build -endef -$(foreach goarch,$(XC_ARCH),$(foreach goos,$(XC_OS),$(eval $(call make-xc-target,$(goos),$(goarch),$(if $(findstring windows,$(goos)),.exe,))))) - -# Use docker to create pristine builds for release -# First build image w/ arm build requirements, then build all binaries -pristine: - @docker build \ - --rm \ - --force-rm \ - --no-cache \ - --compress \ - --file="docker/pristine/Dockerfile" \ - --build-arg="GOVERSION=${GO_DOCKER_VERSION}" \ - --tag="pristine-builder" . - @docker run \ - --interactive \ - --user $$(id -u):$$(id -g) \ - --rm \ - --dns="8.8.8.8" \ - --volume="${CURRENT_DIR}:/go/src/${PROJECT}" \ - --volume="${GOPATH}/pkg/mod:/go/pkg/mod" \ - --workdir="/go/src/${PROJECT}" \ - --env=GO111MODULE=on \ - "pristine-builder" \ - env GOCACHE=/tmp make -j4 build - # dev builds and installs the project locally. dev: @echo "==> Installing ${NAME} for ${GOOS}/${GOARCH}" - @rm -f "${GOPATH}/pkg/${GOOS}_${GOARCH}/${PROJECT}/version.a" # ldflags change and go doesn't detect @env \ CGO_ENABLED="0" \ go install \ @@ -107,73 +32,6 @@ dev: -tags "${GOTAGS}" .PHONY: dev -# dist builds the binaries and then signs and packages them for distribution -dist: - @$(MAKE) -f "${MKFILE_PATH}" _cleanup - @$(MAKE) -f "${MKFILE_PATH}" pristine - @$(MAKE) -f "${MKFILE_PATH}" _compress _checksum -.PHONY: dist - -release: dist -ifndef GPG_KEY - @echo "==> ERROR: No GPG key specified! Without a GPG key, this release cannot" - @echo " be signed. Set the environment variable GPG_KEY to the ID of" - @echo " the GPG key to continue." - @exit 127 -else - @$(MAKE) -f "${MKFILE_PATH}" _sign -endif -.PHONY: release - -# Create a docker compile and push target for each container. This will create -# docker-build/scratch, docker-push/scratch, etc. It will also create two meta -# targets: docker-build and docker-push, which will build and push all -# configured Docker containers. Each container must have a folder in docker/ -# named after itself with a Dockerfile (docker/alpine/Dockerfile). -define make-docker-target - docker-build/$1: - @echo "==> Building ${1} Docker container for ${PROJECT}" - @go mod vendor - @docker build \ - --rm \ - --force-rm \ - --no-cache \ - --compress \ - --file="docker/${1}/Dockerfile" \ - --build-arg="LD_FLAGS=${LD_FLAGS}" \ - --build-arg="GOTAGS=${GOTAGS}" \ - --build-arg="GOVERSION=${GO_DOCKER_VERSION}" \ - $(if $(filter $1,scratch),--tag="${OWNER}/${NAME}",) \ - --tag="${OWNER}/${NAME}:${1}" \ - --tag="${OWNER}/${NAME}:${VERSION}-${1}" \ - "${CURRENT_DIR}" - @rm -rf "${CURRENT_DIR}/vendor/" - .PHONY: docker-build/$1 - - docker-build:: docker-build/$1 - .PHONY: docker-build - - docker-push/$1: - @echo "==> Pushing ${1} to Docker registry" - $(if $(filter $1,scratch),@docker push "${OWNER}/${NAME}",) - @docker push "${OWNER}/${NAME}:${1}" - @docker push "${OWNER}/${NAME}:${VERSION}-${1}" - .PHONY: docker-push/$1 - - docker-push:: docker-push/$1 - .PHONY: docker-push - - docker-clean/$1: - @echo "==> Removing docker image ${1}" - @docker rmi "${OWNER}/${NAME}:${1}" || true - @docker rmi "${OWNER}/${NAME}:${VERSION}-${1}" || true - - docker-clean:: docker-clean/$1 - .PHONY: docker-clean - -endef -$(foreach target,$(DOCKER_TARGETS),$(eval $(call make-docker-target,$(target)))) - # test runs the test suite. test: @echo "==> Testing ${NAME}" @@ -187,69 +45,12 @@ test-race: .PHONY: test-race # _cleanup removes any previous binaries -_cleanup: +clean: @rm -rf "${CURRENT_DIR}/pkg/" @rm -rf "${CURRENT_DIR}/bin/" @rm -f "consul-template" -.PHONY: _cleanup - -clean: _cleanup docker-clean .PHONY: clean -# _compress compresses all the binaries in pkg/* as tarball and zip. -_compress: - @mkdir -p "${CURRENT_DIR}/pkg/dist" - @for platform in $$(find ./pkg -mindepth 1 -maxdepth 1 -type d); do \ - osarch=$$(basename "$$platform"); \ - if [ "$$osarch" = "dist" ]; then \ - continue; \ - fi; \ - \ - ext=""; \ - if test -z "$${osarch##*windows*}"; then \ - ext=".exe"; \ - fi; \ - cd "$$platform"; \ - tar -czf "${CURRENT_DIR}/pkg/dist/${NAME}_${VERSION}_$${osarch}.tgz" "${NAME}$${ext}"; \ - zip -q "${CURRENT_DIR}/pkg/dist/${NAME}_${VERSION}_$${osarch}.zip" "${NAME}$${ext}"; \ - cd - >/dev/null; \ - done -.PHONY: _compress - -# _checksum produces the checksums for the binaries in pkg/dist -_checksum: - @cd "${CURRENT_DIR}/pkg/dist" && \ - shasum --algorithm 256 * > ${CURRENT_DIR}/pkg/dist/${NAME}_${VERSION}_SHA256SUMS && \ - cd - >/dev/null -.PHONY: _checksum - -# _sign signs the binaries using the given GPG_KEY. This should not be called -# as a separate function. -_sign: - @echo "==> Signing ${PROJECT} at v${VERSION}" - @gpg \ - --default-key "${GPG_KEY}" \ - --detach-sig "${CURRENT_DIR}/pkg/dist/${NAME}_${VERSION}_SHA256SUMS" - @git commit \ - --allow-empty \ - --gpg-sign="${GPG_KEY}" \ - --message "Release v${VERSION}" \ - --quiet \ - --signoff - @git tag \ - --annotate \ - --create-reflog \ - --local-user "${GPG_KEY}" \ - --message "Version ${VERSION}" \ - --sign \ - "v${VERSION}" master - @echo "--> Do not forget to run:" - @echo "" - @echo " git push && git push --tags" - @echo "" - @echo "And then upload the binaries in dist/!" -.PHONY: _sign - # Add/Update the "Table Of Contents" in the README.md toc: @./scripts/readme-toc.sh diff --git a/docker/alpine/Dockerfile b/docker/alpine/Dockerfile deleted file mode 100644 index dd54b6743..000000000 --- a/docker/alpine/Dockerfile +++ /dev/null @@ -1,58 +0,0 @@ -### Builder -# -ARG GOVERSION=latest -FROM golang:${GOVERSION} AS builder -LABEL maintainer "John Eikenberry " - -ARG LD_FLAGS -ARG GOTAGS - -WORKDIR "/go/src/github.com/hashicorp/consul-template" - -COPY . . - -RUN \ - CGO_ENABLED="0" \ - GO111MODULE=on \ - go build -mod vendor -a -o "/consul-template" \ - -ldflags "${LD_FLAGS}" -tags "${GOTAGS}" - -### Final -# -FROM alpine:latest -LABEL maintainer "John Eikenberry " - -# UID and GID of consul-template user and group. -# These are the defaults, this makes them explicit and overridable. -ARG UID=100 -ARG GID=1000 - -# Create a consul-template user and group first so the IDs get set the same way, -# even as the rest of this may change over time. -RUN addgroup -g ${GID} consul-template && \ - adduser -u ${UID} -S -G consul-template consul-template - -# Set up certificates, and dumb-init. -RUN apk add --no-cache ca-certificates dumb-init - -# Install consul-template -COPY --from=builder "/consul-template" "/bin/consul-template" - -# The agent will be started with /consul-template/config as the configuration -# directory so you can add additional config files in that location. -RUN mkdir -p /consul-template/data && \ - mkdir -p /consul-template/config && \ - chown -R consul-template:consul-template /consul-template - -# Expose the consul-template data directory as a volume since that's where -# shared results should be rendered. -VOLUME /consul-template/data - -# The entry point script uses dumb-init as the top-level process to reap any -# zombie processes created by Consul Template sub-processes. -COPY "docker/alpine/docker-entrypoint.sh" "/bin/docker-entrypoint.sh" -ENTRYPOINT ["/bin/docker-entrypoint.sh"] -USER ${UID}:${GID} - -# Run consul-template by default -CMD ["/bin/consul-template"] diff --git a/docker/alpine/docker-entrypoint.sh b/docker/alpine/docker-entrypoint.sh deleted file mode 100755 index 86eaabdbf..000000000 --- a/docker/alpine/docker-entrypoint.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/dumb-init /bin/sh -set -e - -# Note above that we run dumb-init as PID 1 in order to reap zombie processes -# as well as forward signals to all processes in its session. Normally, sh -# wouldn't do either of these functions so we'd leak zombies as well as do -# unclean termination of all our sub-processes. - -# CT_CONFIG_DIR isn't exposed as a volume but you can compose additional config -# files in there if you use this image as a base, or use CT_LOCAL_CONFIG below. -CT_CONFIG_DIR=/consul-template/config - -# If the user is trying to run consul-template directly with some arguments, -# then pass them to consul-template. -# On alpine /bin/sh is busybox which supports the bashism below. -if [ "${1:0:1}" = '-' ] -then - set -- /bin/consul-template "$@" -fi - -# Set the configuration directory -if [ "$1" = '/bin/consul-template' ] -then - shift - set -- /bin/consul-template \ - -config="$CT_CONFIG_DIR" \ - "$@" -fi - -exec "$@" diff --git a/docker/light/Dockerfile b/docker/light/Dockerfile deleted file mode 100644 index b2750c884..000000000 --- a/docker/light/Dockerfile +++ /dev/null @@ -1,27 +0,0 @@ -### Builder -# -ARG GOVERSION=latest -FROM golang:${GOVERSION} AS builder -LABEL maintainer "John Eikenberry " - -ARG LD_FLAGS -ARG GOTAGS - -WORKDIR "/go/src/github.com/hashicorp/consul-template" - -COPY . . - -RUN \ - CGO_ENABLED="0" \ - GO111MODULE=on \ - go build -mod vendor -a -o "/consul-template" \ - -ldflags "${LD_FLAGS}" -tags "${GOTAGS}" - -### Final -# -FROM alpine:latest -LABEL maintainer "John Eikenberry " - -RUN apk add --no-cache ca-certificates -COPY --from=builder "/consul-template" "/bin/consul-template" -ENTRYPOINT ["/bin/consul-template"] diff --git a/docker/pristine/Dockerfile b/docker/pristine/Dockerfile deleted file mode 100644 index f1d1e4fe9..000000000 --- a/docker/pristine/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -### Used for pristine builds -# -ARG GOVERSION=latest -FROM golang:${GOVERSION} -LABEL maintainer "John Eikenberry " - -RUN apt-get update && \ - apt-get -y install gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu diff --git a/docker/scratch/Dockerfile b/docker/scratch/Dockerfile deleted file mode 100644 index ffdced1d6..000000000 --- a/docker/scratch/Dockerfile +++ /dev/null @@ -1,27 +0,0 @@ -### Builder -# -ARG GOVERSION=latest -FROM golang:${GOVERSION} AS builder -LABEL maintainer "John Eikenberry " - -ARG LD_FLAGS -ARG GOTAGS - -WORKDIR "/go/src/github.com/hashicorp/consul-template" - -COPY . . - -RUN \ - CGO_ENABLED="0" \ - GO111MODULE=on \ - go build -mod vendor -a -o "/consul-template" \ - -ldflags "${LD_FLAGS}" -tags "${GOTAGS}" - -### Final -# -FROM scratch -LABEL maintainer "John Eikenberry " - -ADD "https://curl.haxx.se/ca/cacert.pem" "/etc/ssl/certs/ca-certificates.crt" -COPY --from=builder "/consul-template" "/consul-template" -ENTRYPOINT ["/consul-template"]