mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 10:20:51 +00:00
Use ARG and --build-arg instead of sed for build-image.
This commit is contained in:
parent
ad1e2ffab0
commit
e05f4a3fac
@ -13,7 +13,9 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
# This file creates a standard build environment for building Kubernetes
|
# This file creates a standard build environment for building Kubernetes
|
||||||
FROM k8s.gcr.io/build-image/kube-cross:KUBE_BUILD_IMAGE_CROSS_TAG
|
ARG KUBE_BUILD_IMAGE_CROSS_TAG
|
||||||
|
|
||||||
|
FROM k8s.gcr.io/build-image/kube-cross:${KUBE_BUILD_IMAGE_CROSS_TAG}
|
||||||
|
|
||||||
# Mark this as a kube-build container
|
# Mark this as a kube-build container
|
||||||
RUN touch /kube-build-image
|
RUN touch /kube-build-image
|
||||||
|
@ -197,15 +197,6 @@ function kube::build::ensure_rsync() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function kube::build::update_dockerfile() {
|
|
||||||
if kube::build::is_gnu_sed; then
|
|
||||||
sed_opts=(-i)
|
|
||||||
else
|
|
||||||
sed_opts=(-i '')
|
|
||||||
fi
|
|
||||||
sed "${sed_opts[@]}" "s/KUBE_BUILD_IMAGE_CROSS_TAG/${KUBE_BUILD_IMAGE_CROSS_TAG}/" "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile"
|
|
||||||
}
|
|
||||||
|
|
||||||
function kube::build::ensure_docker_in_path() {
|
function kube::build::ensure_docker_in_path() {
|
||||||
if [[ -z "$(which docker)" ]]; then
|
if [[ -z "$(which docker)" ]]; then
|
||||||
kube::log::error "Can't find 'docker' in PATH, please fix and retry."
|
kube::log::error "Can't find 'docker' in PATH, please fix and retry."
|
||||||
@ -367,8 +358,7 @@ function kube::build::build_image() {
|
|||||||
dd if=/dev/urandom bs=512 count=1 2>/dev/null | LC_ALL=C tr -dc 'A-Za-z0-9' | dd bs=32 count=1 2>/dev/null > "${LOCAL_OUTPUT_BUILD_CONTEXT}/rsyncd.password"
|
dd if=/dev/urandom bs=512 count=1 2>/dev/null | LC_ALL=C tr -dc 'A-Za-z0-9' | dd bs=32 count=1 2>/dev/null > "${LOCAL_OUTPUT_BUILD_CONTEXT}/rsyncd.password"
|
||||||
chmod go= "${LOCAL_OUTPUT_BUILD_CONTEXT}/rsyncd.password"
|
chmod go= "${LOCAL_OUTPUT_BUILD_CONTEXT}/rsyncd.password"
|
||||||
|
|
||||||
kube::build::update_dockerfile
|
kube::build::docker_build "${KUBE_BUILD_IMAGE}" "${LOCAL_OUTPUT_BUILD_CONTEXT}" 'false' "--build-arg=KUBE_BUILD_IMAGE_CROSS_TAG=${KUBE_BUILD_IMAGE_CROSS_TAG}"
|
||||||
kube::build::docker_build "${KUBE_BUILD_IMAGE}" "${LOCAL_OUTPUT_BUILD_CONTEXT}" 'false'
|
|
||||||
|
|
||||||
# Clean up old versions of everything
|
# Clean up old versions of everything
|
||||||
kube::build::docker_delete_old_containers "${KUBE_BUILD_CONTAINER_NAME_BASE}" "${KUBE_BUILD_CONTAINER_NAME}"
|
kube::build::docker_delete_old_containers "${KUBE_BUILD_CONTAINER_NAME_BASE}" "${KUBE_BUILD_CONTAINER_NAME}"
|
||||||
@ -384,11 +374,13 @@ function kube::build::build_image() {
|
|||||||
# $1 is the name of the image to build
|
# $1 is the name of the image to build
|
||||||
# $2 is the location of the "context" directory, with the Dockerfile at the root.
|
# $2 is the location of the "context" directory, with the Dockerfile at the root.
|
||||||
# $3 is the value to set the --pull flag for docker build; true by default
|
# $3 is the value to set the --pull flag for docker build; true by default
|
||||||
|
# $4 is the set of --build-args for docker.
|
||||||
function kube::build::docker_build() {
|
function kube::build::docker_build() {
|
||||||
local -r image=$1
|
local -r image=$1
|
||||||
local -r context_dir=$2
|
local -r context_dir=$2
|
||||||
local -r pull="${3:-true}"
|
local -r pull="${3:-true}"
|
||||||
local -ra build_cmd=("${DOCKER[@]}" build -t "${image}" "--pull=${pull}" "${context_dir}")
|
local -r build_args=$4
|
||||||
|
local -ra build_cmd=("${DOCKER[@]}" build -t "${image}" "--pull=${pull}" "${build_args}" "${context_dir}")
|
||||||
|
|
||||||
kube::log::status "Building Docker image ${image}"
|
kube::log::status "Building Docker image ${image}"
|
||||||
local docker_output
|
local docker_output
|
||||||
|
Loading…
Reference in New Issue
Block a user