Containerize kubernetes-entrypoint image build
Containerizes the kubernetes-entrypoint image build so that go tooling does not need to be pre-installed on the host. Change-Id: I47766ef81f70170683e61c634411e259806932c5
This commit is contained in:
parent
e55fafa1b0
commit
db0903c77f
@ -1,5 +1,4 @@
|
|||||||
FROM docker.io/ubuntu:xenial
|
FROM docker.io/ubuntu:xenial
|
||||||
MAINTAINER sean.eagan@att.com
|
|
||||||
|
|
||||||
ARG BINARY_PATH
|
ARG BINARY_PATH
|
||||||
ARG BINARY_INSTALL_PATH=/usr/local/bin/kubernetes-entrypoint
|
ARG BINARY_INSTALL_PATH=/usr/local/bin/kubernetes-entrypoint
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Copyright 2017 The Openstack-Helm Authors.
|
# Copyright 2018 The Openstack-Helm Authors.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@ -18,7 +18,8 @@ SHELL := /bin/bash
|
|||||||
# Git args
|
# Git args
|
||||||
GIT_REPO ?= https://github.com/stackanetes/kubernetes-entrypoint.git
|
GIT_REPO ?= https://github.com/stackanetes/kubernetes-entrypoint.git
|
||||||
GIT_REF ?= master
|
GIT_REF ?= master
|
||||||
GIT_CLONE_DIR = src
|
_GIT_CLONE_SUBDIR := src
|
||||||
|
_GIT_CLONE_MOUNT_DIR := /go/src/github.com/stackanetes/kubernetes-entrypoint
|
||||||
|
|
||||||
# Image args
|
# Image args
|
||||||
IMAGE_REGISTRY ?= docker.io
|
IMAGE_REGISTRY ?= docker.io
|
||||||
@ -28,46 +29,56 @@ IMAGE_TAG ?= $(GIT_REF)
|
|||||||
IMAGE_LABELS ?=
|
IMAGE_LABELS ?=
|
||||||
# Overrides above image args if specified.
|
# Overrides above image args if specified.
|
||||||
IMAGE ?= ${IMAGE_REGISTRY}/${IMAGE_PREFIX}/${IMAGE_NAME}$(if $(IMAGE_TAG),:$(IMAGE_TAG),)
|
IMAGE ?= ${IMAGE_REGISTRY}/${IMAGE_PREFIX}/${IMAGE_NAME}$(if $(IMAGE_TAG),:$(IMAGE_TAG),)
|
||||||
|
IMAGE_DOCKER_BUILD_OPTS ?=
|
||||||
|
IMAGE_BINARY_INSTALL_PATH ?=
|
||||||
|
|
||||||
# Build args
|
# Go args
|
||||||
BINARY_INSTALL_PATH ?=
|
GO_IMAGE ?= docker.io/golang:1.10
|
||||||
|
GO_BUILD_OPTS ?=
|
||||||
|
|
||||||
# Extra args to pass to Docker build
|
# Binary args
|
||||||
DOCKER_BUILD_OPTS ?=
|
_BINARY_SUBDIR := out
|
||||||
|
_BINARY_PATH := $(_BINARY_SUBDIR)/kubernetes-entrypoint
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: clean checkout binary image push
|
all: clean checkout binary image push
|
||||||
|
|
||||||
# Remove source code
|
# Remove source code and binary
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(GIT_CLONE_DIR)
|
rm -rf $(_GIT_CLONE_SUBDIR)
|
||||||
|
|
||||||
# Checkout source code
|
# Checkout source code
|
||||||
.PHONY: checkout
|
.PHONY: checkout
|
||||||
checkout:
|
checkout:
|
||||||
git clone $(GIT_REPO) $(GIT_CLONE_DIR)
|
git clone $(GIT_REPO) $(_GIT_CLONE_SUBDIR)
|
||||||
cd $(GIT_CLONE_DIR); git checkout $(GIT_REF) .
|
cd $(_GIT_CLONE_SUBDIR); git checkout $(GIT_REF) .
|
||||||
|
|
||||||
# Build binary
|
# Build binary
|
||||||
.PHONY: binary
|
.PHONY: binary
|
||||||
binary:
|
binary:
|
||||||
cd $(GIT_CLONE_DIR); go build
|
docker run\
|
||||||
|
-v "$(shell pwd)/$(_GIT_CLONE_SUBDIR)":$(_GIT_CLONE_MOUNT_DIR)\
|
||||||
|
`# Run as current user, not root, to avoid sudo usage in clean target`\
|
||||||
|
-v /etc/group:/etc/group:ro -v /etc/passwd:/etc/passwd:ro\
|
||||||
|
-u $(shell id -u ${USER}):$(shell id -g ${USER})\
|
||||||
|
-w $(_GIT_CLONE_MOUNT_DIR)\
|
||||||
|
$(GO_IMAGE)\
|
||||||
|
go build -o "$(_BINARY_PATH)" $(GO_BUILD_OPTS)
|
||||||
|
|
||||||
# Internal variables
|
# Internal variables
|
||||||
_BINARY_PATH := $(GIT_CLONE_DIR)/kubernetes-entrypoint
|
_BINARY_INSTALL_PATH_ARG := $(if $(IMAGE_BINARY_INSTALL_PATH),--build-arg BINARY_INSTALL_PATH="${IMAGE_BINARY_INSTALL_PATH}" ,)
|
||||||
_BINARY_INSTALL_PATH_ARG := $(if $(BINARY_INSTALL_PATH),--build-arg BINARY_INSTALL_PATH="${BINARY_INSTALL_PATH}" ,)
|
|
||||||
_IMAGE_LABELS_ARG := $(if $(IMAGE_LABELS),--label="${IMAGE_LABELS}" ,)
|
_IMAGE_LABELS_ARG := $(if $(IMAGE_LABELS),--label="${IMAGE_LABELS}" ,)
|
||||||
|
|
||||||
# Build image
|
# Build image
|
||||||
.PHONY: image
|
.PHONY: image
|
||||||
image:
|
image:
|
||||||
docker build\
|
docker build\
|
||||||
--build-arg BINARY_PATH=$(_BINARY_PATH)\
|
--build-arg BINARY_PATH=/$(_GIT_CLONE_SUBDIR)/$(_BINARY_PATH)\
|
||||||
$(_BINARY_INSTALL_PATH_ARG)\
|
$(_BINARY_INSTALL_PATH_ARG)\
|
||||||
$(_IMAGE_LABELS_ARG)\
|
$(_IMAGE_LABELS_ARG)\
|
||||||
-t $(IMAGE)\
|
-t $(IMAGE)\
|
||||||
$(DOCKER_BUILD_OPTS)\
|
$(IMAGE_DOCKER_BUILD_OPTS)\
|
||||||
.
|
.
|
||||||
|
|
||||||
# Push image
|
# Push image
|
||||||
|
@ -6,7 +6,7 @@ Builds an image with kubernetes-entrypoint for use with OpenStack-Helm.
|
|||||||
Prerequisites
|
Prerequisites
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
Must have golang 1.7.x installed in order to build the binary.
|
git, docker
|
||||||
|
|
||||||
Instructions
|
Instructions
|
||||||
------------
|
------------
|
||||||
@ -19,7 +19,7 @@ you wish to build your own image, from the directory containing this README run:
|
|||||||
|
|
||||||
.. code:: bash
|
.. code:: bash
|
||||||
# Example configuration overrides, see Makefile for all available options:
|
# Example configuration overrides, see Makefile for all available options:
|
||||||
# export IMAGE_REPO=quay.io
|
# export IMAGE_REGISTRY=quay.io
|
||||||
# export GIT_REPO=https://github.com/someuser/kubernetes-entrypoint.git
|
# export GIT_REPO=https://github.com/someuser/kubernetes-entrypoint.git
|
||||||
# export GIT_REF=someref
|
# export GIT_REF=someref
|
||||||
make
|
make
|
||||||
|
Loading…
Reference in New Issue
Block a user