Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build #15

Merged
merged 4 commits into from
Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ Session.vim
# coverage artifacts
.coverprofile
/gover.coverprofile
bin/

# build artifacts
.go/
.*-container
.*-dockerfile
.*-push
bin/
4 changes: 2 additions & 2 deletions Dockerfile → Dockerfile.glbc
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ FROM alpine:3.6

RUN apk add --no-cache ca-certificates

COPY glbc glbc
ENTRYPOINT ["/glbc"]
ADD bin/ARG_ARCH/ARG_BIN /ARG_BIN
ENTRYPOINT ["/ARG_BIN"]
52 changes: 39 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
all: push
# Copyright 2016 The Kubernetes Authors.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update to 2017?

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# 0.0 shouldn't clobber any released builds
TAG=0.9.7
PREFIX=gcr.io/google_containers/glbc
PKG=k8s.io/ingress-gce
#
# `make help` will show commonly used targets.
#

server:
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-w' -o glbc ${PKG}/cmd/glbc
# Golang package.
PKG := k8s.io/ingress-gce

container: server
docker build --pull -t $(PREFIX):$(TAG) .
# List of binaries to build. You must have a matching Dockerfile.BINARY
# for each BINARY.
CONTAINER_BINARIES := glbc

push: container
gcloud docker -- push $(PREFIX):$(TAG)
# Registry to push to.
REGISTRY ?= gcr.io/google_containers

clean:
rm -f glbc
ARCH ?= amd64
ALL_ARCH := amd64

# Image to use for building.
BUILD_IMAGE ?= golang:1.9-alpine
# Containers will be named: $(CONTAINER_PREFIX)-$(BINARY)-$(ARCH):$(VERSION).
CONTAINER_PREFIX ?= ingress-gce

# This version-strategy uses git tags to set the version string
VERSION ?= $(shell git describe --tags --always --dirty)

# Set to 1 to print more verbose output from the build.
VERBOSE ?= 0

# Include standard build rules.
include build/rules.mk
43 changes: 43 additions & 0 deletions build/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/sh
#
# Copyright 2016 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

if [ -z "${PKG}" ]; then
echo "PKG must be set"
exit 1
fi
if [ -z "${ARCH}" ]; then
echo "ARCH must be set"
exit 1
fi
if [ -z "${VERSION}" ]; then
echo "VERSION must be set"
exit 1
fi

export CGO_ENABLED=0
export GOARCH="${ARCH}"
if [ $GOARCH == "amd64" ]; then
export GOBIN="$GOPATH/bin/linux_amd64"
fi

go install \
-installsuffix "static" \
-ldflags "-X ${PKG}/pkg/version.VERSION=${VERSION}" \
./...
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
270 changes: 270 additions & 0 deletions build/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
# Copyright 2016 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#
# These build rules should not need to be modified.
#

# Variables exported to submake
export ARCH
export CONTAINER_PREFIX
export IMAGES
export REGISTRY
export VERBOSE
export VERSION

# directories which hold app source (not vendored)
SRC_DIRS := cmd pkg

# Variables exported to submake
export ARCH
export CONTAINER_PREFIX
export IMAGES
export REGISTRY
export VERBOSE
export VERSION

# directories which hold app source (not vendored)
SRC_DIRS := cmd pkg

ALL_ARCH ?= amd64 arm arm64 ppc64le s390x
NOBODY ?= nobody
# Set default base image dynamically for each arch
ifeq ($(ARCH),amd64)
BASEIMAGE?=alpine
endif
ifeq ($(ARCH),arm)
BASEIMAGE?=arm32v6/alpine
endif
ifeq ($(ARCH),arm64)
BASEIMAGE?=arm64v8/alpine
endif
ifeq ($(ARCH),ppc64le)
BASEIMAGE?=ppc64le/alpine
endif
ifeq ($(ARCH),s390x)
BASEIMAGE?=s390x/alpine
endif

# These rules MUST be expanded at reference time (hence '=') as BINARY
# is dynamically scoped.
CONTAINER_NAME = $(REGISTRY)/$(CONTAINER_PREFIX)-$(BINARY)-$(ARCH)
BUILDSTAMP_NAME = $(subst :,_,$(subst /,_,$(CONTAINER_NAME))_$(VERSION))

ALL_BINARIES += $(BINARIES)
ALL_BINARIES += $(CONTAINER_BINARIES)

GO_BINARIES := $(addprefix bin/$(ARCH)/,$(ALL_BINARIES))
CONTAINER_BUILDSTAMPS := $(foreach BINARY,$(CONTAINER_BINARIES),.$(BUILDSTAMP_NAME)-container)
PUSH_BUILDSTAMPS := $(foreach BINARY,$(CONTAINER_BINARIES),.$(BUILDSTAMP_NAME)-push)

ifeq ($(VERBOSE), 1)
DOCKER_BUILD_FLAGS :=
VERBOSE_OUTPUT := >&1
else
DOCKER_BUILD_FLAGS := -q
VERBOSE_OUTPUT := >/dev/null
endif

# This MUST appear as the first rule in a Makefile
all: build

build-%:
@$(MAKE) --no-print-directory ARCH=$* build

containers-%:
@$(MAKE) --no-print-directory ARCH=$* containers

push-%:
@$(MAKE) --no-print-directory ARCH=$* push


.PHONY: all-build
all-build: $(addprefix build-, $(ALL_ARCH))

.PHONY: all-containers
all-containers: $(addprefix containers-, $(ALL_ARCH))

.PHONY: all-push
all-push: $(addprefix push-, $(ALL_ARCH))

.PHONY: build
build: $(GO_BINARIES) images-build


# Rule for all bin/$(ARCH)/bin/$(BINARY)
$(GO_BINARIES): build-dirs
@echo "building : $@"
@docker pull $(BUILD_IMAGE)
@docker run \
--rm \
--sig-proxy=true \
-u $$(id -u):$$(id -g) \
-v $$(pwd)/.go:/go \
-v $$(pwd):/go/src/$(PKG) \
-v $$(pwd)/bin/$(ARCH):/go/bin/linux_$(ARCH) \
-v $$(pwd)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static \
-w /go/src/$(PKG) \
$(BUILD_IMAGE) \
/bin/sh -c " \
ARCH=$(ARCH) \
VERSION=$(VERSION) \
PKG=$(PKG) \
./build/build.sh \
"


# Rules for dockerfiles.
define DOCKERFILE_RULE
.$(BINARY)-$(ARCH)-dockerfile: Dockerfile.$(BINARY)
@echo generating Dockerfile $$@ from $$<
@sed \
-e 's|ARG_ARCH|$(ARCH)|g' \
-e 's|ARG_BIN|$(BINARY)|g' \
-e 's|ARG_REGISTRY|$(REGISTRY)|g' \
-e 's|ARG_FROM|$(BASEIMAGE)|g' \
-e 's|ARG_NOBODY|$(NOBODY)|g' \
-e 's|ARG_VERSION|$(VERSION)|g' \
$$< > $$@
.$(BUILDSTAMP_NAME)-container: .$(BINARY)-$(ARCH)-dockerfile
endef
$(foreach BINARY,$(CONTAINER_BINARIES),$(eval $(DOCKERFILE_RULE)))


# Rules for containers
define CONTAINER_RULE
.$(BUILDSTAMP_NAME)-container: bin/$(ARCH)/$(BINARY)
@echo "container: bin/$(ARCH)/$(BINARY) ($(CONTAINER_NAME))"
@docker pull $(BASEIMAGE)
@docker build \
$(DOCKER_BUILD_FLAGS) \
-t $(CONTAINER_NAME):$(VERSION) \
-f .$(BINARY)-$(ARCH)-dockerfile . \
$(VERBOSE_OUTPUT)
@echo "$(CONTAINER_NAME):$(VERSION)" > $$@
@docker images -q $(CONTAINER_NAME):$(VERSION) >> $$@
endef
$(foreach BINARY,$(CONTAINER_BINARIES),$(eval $(CONTAINER_RULE)))

.PHONY: containers
containers: $(CONTAINER_BUILDSTAMPS) images-containers


# Rules for pushing
.PHONY: push
push: $(PUSH_BUILDSTAMPS) images-push

.%-push: .%-container
@echo "pushing :" $$(head -n 1 $<)
ifeq (,$(findstring gcr.io,$(REGISTRY)))
@docker push $$(head -n 1 $<) $(VERBOSE_OUTPUT)
else
@gcloud docker -- push $$(head -n 1 $<) $(VERBOSE_OUTPUT)
endif
@cat $< > $@

define PUSH_RULE
only-push-$(BINARY): .$(BUILDSTAMP_NAME)-push
endef
$(foreach BINARY,$(CONTAINER_BINARIES),$(eval $(PUSH_RULE)))


# Rule for `test`
.PHONY: test images-test
test: build-dirs
@docker run \
--rm \
--sig-proxy=true \
-u $$(id -u):$$(id -g) \
-v $$(pwd)/.go:/go \
-v $$(pwd):/go/src/$(PKG) \
-v $$(pwd)/bin/$(ARCH):/go/bin \
-v $$(pwd)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static \
-w /go/src/$(PKG) \
$(BUILD_IMAGE) \
/bin/sh -c " \
./build/test.sh $(SRC_DIRS) \
"

# Hook in images build if the directory exists.
ifeq ($(wildcard images),)
.PHONY: images-build images-containers images-push images-test images-clean
images-build:
images-containers:
images-push:
images-test:
images-clean:
else
.PHONY: images-build
images-build:
@$(MAKE) -C images build

.PHONY: images-containers
images-containers:
@$(MAKE) -C images containers

.PHONY: images-push
images-push:
@$(MAKE) -C images push

.PHONY: images-test
images-test:
@$(MAKE) -C images test

.PHONY: images-clean
images-clean:
@$(MAKE) -C images clean
endif

# Miscellaneous rules
.PHONY: version
version:
@echo $(VERSION)

.PHONY: build-dirs
build-dirs:
@mkdir -p bin/$(ARCH)
@mkdir -p .go/src/$(PKG) .go/pkg .go/bin .go/std/$(ARCH)

.PHONY: clean
clean: container-clean bin-clean images-clean

.PHONY: container-clean
container-clean:
rm -f .*-container .*-dockerfile .*-push

.PHONY: bin-clean
bin-clean:
rm -rf .go bin

.PHONY: help
help:
@echo "make targets"
@echo
@echo " all, build build all binaries"
@echo " containers build the containers"
@echo " push push containers to the registry"
@echo " help this help message"
@echo " version show package version"
@echo
@echo " {build,containers,push}-ARCH do action for specific ARCH"
@echo " all-{build,containers,push} do action for all ARCH"
@echo " only-push-BINARY push just BINARY"
@echo
@echo " Available ARCH: $(ALL_ARCH)"
@echo " Available BINARIES: $(ALL_BINARIES)"
@echo
@echo " Setting VERBOSE=1 will show additional build logging."
@echo
@echo " Setting VERSION will override the container version tag."
Loading