2016-09-21 07:15:39 +03:00
# 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.
# The binary to build (just the basename).
2017-05-12 21:45:19 +03:00
BIN := ip-masq-agent
2016-09-21 07:15:39 +03:00
# This repo's root import path (under GOPATH).
2017-05-12 21:45:19 +03:00
PKG := k8s.io/ip-masq-agent
2016-09-21 07:15:39 +03:00
# Where to push the docker image.
2017-04-18 16:09:12 +03:00
REGISTRY ?= gcr.io/google-containers
2016-09-21 07:15:39 +03:00
# Which architecture to build - see $(ALL_ARCH) for options.
ARCH ?= amd64
2016-10-01 06:28:27 +03:00
# This version-strategy uses git tags to set the version string
2016-10-28 19:10:41 +03:00
VERSION := $( shell git describe --tags --always --dirty)
2016-10-01 06:28:27 +03:00
#
# This version-strategy uses a manual value to set the version string
#VERSION := 1.2.3
2016-09-21 07:15:39 +03:00
###
### These variables should not need tweaking.
###
SRC_DIRS := cmd pkg # directories which hold app source (not vendored)
2016-09-23 08:45:29 +03:00
ALL_ARCH := amd64 arm arm64 ppc64le
# Set default base image dynamically for each arch
i f e q ( $( ARCH ) , a m d 6 4 )
2017-04-18 16:09:12 +03:00
BASEIMAGE?= gcr.io/google-containers/debian-iptables-amd64:v7 # we use this base image instead of alpine, because iptables version should match kube-proxy
2016-09-23 08:45:29 +03:00
e n d i f
i f e q ( $( ARCH ) , a r m )
BASEIMAGE?= armel/busybox
e n d i f
i f e q ( $( ARCH ) , a r m 6 4 )
BASEIMAGE?= aarch64/busybox
e n d i f
i f e q ( $( ARCH ) , p p c 6 4 l e )
BASEIMAGE?= ppc64le/busybox
e n d i f
2016-09-21 07:15:39 +03:00
IMAGE := $( REGISTRY) /$( BIN) -$( ARCH)
BUILD_IMAGE ?= golang:1.7-alpine
# If you want to build all binaries, see the 'all-build' rule.
# If you want to build all containers, see the 'all-container' rule.
# If you want to build AND push all containers, see the 'all-push' rule.
all : build
build-% :
@$( MAKE) --no-print-directory ARCH = $* build
container-% :
@$( MAKE) --no-print-directory ARCH = $* container
push-% :
@$( MAKE) --no-print-directory ARCH = $* push
all-build : $( addprefix build -, $ ( ALL_ARCH ) )
all-container : $( addprefix container -, $ ( ALL_ARCH ) )
all-push : $( addprefix push -, $ ( ALL_ARCH ) )
build : bin /$( ARCH ) /$( BIN )
bin/$(ARCH)/$(BIN) : build -dirs
@echo " building: $@ "
@docker run \
-ti \
-u $$ ( id -u) :$$ ( id -g) \
-v $$ ( pwd ) /.go:/go \
-v $$ ( pwd ) :/go/src/$( PKG) \
-v $$ ( pwd ) /bin/$( ARCH) :/go/bin \
2016-09-24 02:09:59 +03:00
-v $$ ( pwd ) /bin/$( ARCH) :/go/bin/linux_$( ARCH) \
2016-09-21 07:15:39 +03:00
-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 \
"
2017-02-15 01:10:20 +03:00
DOTFILE_IMAGE = $( subst :,_,$( subst /,_,$( IMAGE) ) -$( VERSION) )
2016-09-21 07:15:39 +03:00
container : .container -$( DOTFILE_IMAGE ) container -name
2016-09-23 08:45:29 +03:00
.container-$(DOTFILE_IMAGE) : bin /$( ARCH ) /$( BIN ) Dockerfile .in
@sed \
-e 's|ARG_BIN|$(BIN)|g' \
-e 's|ARG_ARCH|$(ARCH)|g' \
-e 's|ARG_FROM|$(BASEIMAGE)|g' \
Dockerfile.in > .dockerfile-$( ARCH)
@docker build -t $( IMAGE) :$( VERSION) -f .dockerfile-$( ARCH) .
2016-09-21 07:15:39 +03:00
@docker images -q $( IMAGE) :$( VERSION) > $@
container-name :
@echo " container: $( IMAGE) : $( VERSION) "
push : .push -$( DOTFILE_IMAGE ) push -name
.push-$(DOTFILE_IMAGE) : .container -$( DOTFILE_IMAGE )
2017-02-15 01:10:20 +03:00
i f e q ( $( findstring gcr .io ,$ ( REGISTRY ) ) , g c r . i o )
@gcloud docker -- push $( IMAGE) :$( VERSION)
e l s e
@docker push $( IMAGE) :$( VERSION)
e n d i f
2016-09-21 07:15:39 +03:00
@docker images -q $( IMAGE) :$( VERSION) > $@
push-name :
@echo " pushed: $( IMAGE) : $( VERSION) "
version :
@echo $( VERSION)
test : build -dirs
@docker run \
-ti \
-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) \
"
build-dirs :
@mkdir -p bin/$( ARCH)
@mkdir -p .go/src/$( PKG) .go/pkg .go/bin .go/std/$( ARCH)
clean : container -clean bin -clean
container-clean :
2016-09-23 08:45:29 +03:00
rm -rf .container-* .dockerfile-* .push-*
2016-09-21 07:15:39 +03:00
bin-clean :
rm -rf .go bin