Merge pull request #1011 from munnerz/dev-env-script
Add a 'run-dev-kind.sh' script to bring up a local dev environment
This commit is contained in:
commit
23fb27c4d9
55
hack/ci/lib/build_images.sh
Executable file
55
hack/ci/lib/build_images.sh
Executable file
@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2018 The Jetstack cert-manager contributors.
|
||||
#
|
||||
# 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
|
||||
|
||||
# build_images will build Docker images for all of cert-manager's components.
|
||||
# It will transfer them to the 'kind' docker container so they are available
|
||||
# in a testing environment.
|
||||
|
||||
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")
|
||||
source "${SCRIPT_ROOT}/lib.sh"
|
||||
|
||||
build_images() {
|
||||
# Build cert-manager binaries & docker image
|
||||
APP_VERSION="${DOCKER_TAG}" \
|
||||
DOCKER_REPO="${DOCKER_REPO}" \
|
||||
DOCKER_TAG="${DOCKER_TAG}" \
|
||||
bazel run //:images
|
||||
|
||||
local TMP_DIR=$(mktemp -d)
|
||||
local BUNDLE_FILE="${TMP_DIR}"/cmbundle.tar.gz
|
||||
|
||||
# Create an archive of docker images
|
||||
docker save \
|
||||
"${DOCKER_REPO}"/cert-manager-controller:"${DOCKER_TAG}" \
|
||||
"${DOCKER_REPO}"/cert-manager-acmesolver:"${DOCKER_TAG}" \
|
||||
"${DOCKER_REPO}"/cert-manager-webhook:"${DOCKER_TAG}" \
|
||||
-o "${BUNDLE_FILE}"
|
||||
|
||||
# Copy docker archive into the kind container
|
||||
docker cp "${BUNDLE_FILE}" "${KIND_CONTAINER_NAME}":/cmbundle.tar.gz
|
||||
|
||||
# Import file into kind docker daemon
|
||||
docker exec "${KIND_CONTAINER_NAME}" docker load -i /cmbundle.tar.gz
|
||||
|
||||
# Cleanup
|
||||
rm -Rf "${TMP_DIR}"
|
||||
}
|
||||
|
||||
build_images
|
||||
33
hack/ci/lib/cluster_create.sh
Executable file
33
hack/ci/lib/cluster_create.sh
Executable file
@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2018 The Jetstack cert-manager contributors.
|
||||
#
|
||||
# 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
|
||||
|
||||
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")
|
||||
source "${SCRIPT_ROOT}/lib.sh"
|
||||
|
||||
# deploy_kind will deploy a kubernetes-in-docker cluster
|
||||
deploy_kind() {
|
||||
# create the kind cluster
|
||||
kind create cluster \
|
||||
--name="${KIND_CLUSTER_NAME}" \
|
||||
--image="${KIND_IMAGE}" \
|
||||
--config "${REPO_ROOT}"/test/fixtures/kind-config.yaml
|
||||
}
|
||||
|
||||
deploy_kind
|
||||
24
hack/ci/lib/cluster_destroy.sh
Executable file
24
hack/ci/lib/cluster_destroy.sh
Executable file
@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2018 The Jetstack cert-manager contributors.
|
||||
#
|
||||
# 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
|
||||
|
||||
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")
|
||||
source "${SCRIPT_ROOT}/lib.sh"
|
||||
|
||||
kind delete cluster --name="${KIND_CLUSTER_NAME}"
|
||||
37
hack/ci/lib/lib.sh
Normal file
37
hack/ci/lib/lib.sh
Normal file
@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2018 The Jetstack cert-manager contributors.
|
||||
#
|
||||
# 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
|
||||
|
||||
_SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")
|
||||
REPO_ROOT="${_SCRIPT_ROOT}/../../.."
|
||||
|
||||
# This file contains common definitions that are re-used in other scripts
|
||||
|
||||
KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-cm-local-cluster}"
|
||||
KIND_CONTAINER_NAME="kind-${KIND_CLUSTER_NAME}-control-plane"
|
||||
KIND_IMAGE=${KIND_IMAGE:-eu.gcr.io/jetstack-build-infra-images/kind:1.11.2-0}
|
||||
|
||||
# DOCKER_REPO is the docker repo to use for cert-manager images, either when
|
||||
# building or deploying cert-manager using these scripts.
|
||||
DOCKER_REPO="quay.io/jetstack"
|
||||
|
||||
# DOCKER_TAG is the docker tag to use for the cert-manager images.
|
||||
# This defaults to 'build' so it doesn't conflict with images built for any
|
||||
# other purpose
|
||||
DOCKER_TAG="build"
|
||||
75
hack/ci/run-dev-kind.sh
Executable file
75
hack/ci/run-dev-kind.sh
Executable file
@ -0,0 +1,75 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2018 The Jetstack cert-manager contributors.
|
||||
#
|
||||
# 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.
|
||||
|
||||
# This script will provision a development environment using kind on your local
|
||||
# machine.
|
||||
# The end result should be an environment that can pass e2e tests.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")
|
||||
source "${SCRIPT_ROOT}/lib/lib.sh"
|
||||
|
||||
echo "+++ Creating cluster using kind"
|
||||
"${SCRIPT_ROOT}/lib/cluster_create.sh"
|
||||
|
||||
echo "+++ Building cert-manager images from source and exporting them to the development cluster"
|
||||
"${SCRIPT_ROOT}/lib/build_images.sh"
|
||||
|
||||
echo ""
|
||||
echo ""
|
||||
echo "Your development environment is now ready."
|
||||
echo
|
||||
echo "A single node Kubernetes cluster has been provisioned in a Docker container"
|
||||
echo "on your machine."
|
||||
echo ""
|
||||
echo "You should now configure your shell to use the KUBECONFIG file that has"
|
||||
echo "been generated in order to access this cluster:"
|
||||
echo ""
|
||||
echo " export KUBECONFIG=\$HOME/.kube/kind-config-${KIND_CLUSTER_NAME}"
|
||||
echo ""
|
||||
echo ""
|
||||
echo "A freshly built copy of the cert-manager images have also been exported to"
|
||||
echo "the docker daemon in this single node Kubernetes cluster."
|
||||
echo ""
|
||||
echo "You can build and export a fresh copy of these images with:"
|
||||
echo ""
|
||||
echo " ./hack/ci/lib/build_images.sh"
|
||||
echo ""
|
||||
echo ""
|
||||
echo "You should now be able to run end-to-end tests using:"
|
||||
echo ""
|
||||
echo " make e2e_test"
|
||||
echo ""
|
||||
echo ""
|
||||
echo "We have \*\*not\*\* automatically deployed cert-manager into this cluster."
|
||||
echo "To deploy cert-manager into this cluster, run:"
|
||||
echo ""
|
||||
echo " bazel run //hack/bin:helm -- install \\"
|
||||
echo " --name cert-manager \\"
|
||||
echo " --namespace cert-manager \\"
|
||||
echo " --values ./test/fixtures/cert-manager-values.yaml \\"
|
||||
echo " ./contrib/charts/cert-manager"
|
||||
echo ""
|
||||
echo ""
|
||||
echo "Each time you make a change and run build_images.sh, you will need to manually"
|
||||
echo "delete the cert-manager pod that is deployed in the cert-manager namespace."
|
||||
echo ""
|
||||
echo "Thanks for contributing!"
|
||||
echo ""
|
||||
echo ""
|
||||
@ -25,59 +25,29 @@ set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")
|
||||
REPO_ROOT="${SCRIPT_ROOT}/../.."
|
||||
source "${SCRIPT_ROOT}/lib/lib.sh"
|
||||
|
||||
KIND_CLUSTER_NAME="cm-e2e"
|
||||
# TODO: can we rely on this being fixed as such?
|
||||
KIND_CONTAINER_NAME="kind-${KIND_CLUSTER_NAME}-control-plane"
|
||||
KIND_IMAGE=${KIND_IMAGE:-eu.gcr.io/jetstack-build-infra-images/kind:1.11.2-0}
|
||||
|
||||
# cleanup will call kind delete - it will absorb errors
|
||||
cleanup() {
|
||||
# Ignore errors here
|
||||
kind delete cluster --name="${KIND_CLUSTER_NAME}" || true
|
||||
"${SCRIPT_ROOT}/lib/cluster_destroy.sh" || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# deploy_kind will deploy a kubernetes-in-docker cluster
|
||||
deploy_kind() {
|
||||
# create the kind cluster
|
||||
kind create cluster \
|
||||
--name="${KIND_CLUSTER_NAME}" \
|
||||
--image="${KIND_IMAGE}" \
|
||||
--config "${REPO_ROOT}"/test/fixtures/kind-config.yaml
|
||||
"${SCRIPT_ROOT}/lib/cluster_create.sh"
|
||||
|
||||
export KUBECONFIG="${HOME}/.kube/kind-config-${KIND_CLUSTER_NAME}"
|
||||
# copy kubectl out of the kind container if kubectl is not installed on the
|
||||
# host machine. This will *only* work on Linux :this_is_fine:
|
||||
if ! which kubectl; then
|
||||
tmp_path=$(mktemp -d)
|
||||
export PATH="${tmp_path}:${PATH}"
|
||||
docker cp "${KIND_CONTAINER_NAME}":"$(docker exec "${KIND_CONTAINER_NAME}" which kubectl)" "${tmp_path}/kubectl"
|
||||
fi
|
||||
|
||||
# copy kubectl out of the kind container if kubectl is not installed on the
|
||||
# host machine. This will *only* work on Linux :this_is_fine:
|
||||
if ! which kubectl; then
|
||||
tmp_path=$(mktemp -d)
|
||||
export PATH="${tmp_path}:${PATH}"
|
||||
docker cp "${KIND_CONTAINER_NAME}":"$(docker exec "${KIND_CONTAINER_NAME}" which kubectl)" "${tmp_path}/kubectl"
|
||||
fi
|
||||
export KUBECONFIG="${HOME}/.kube/kind-config-${KIND_CLUSTER_NAME}"
|
||||
# Ensure the apiserver is responding
|
||||
kubectl get nodes
|
||||
|
||||
# Ensure the apiserver is responding
|
||||
kubectl get nodes
|
||||
}
|
||||
|
||||
# build_images will build cert-manager docker images and copy them across to the
|
||||
# kind docker container running the cluster, so they are available to the
|
||||
# cluster's docker daemon.
|
||||
build_images() {
|
||||
# Build cert-manager binaries & docker image
|
||||
make images APP_VERSION=build
|
||||
|
||||
local TMP_DIR=$(mktemp -d)
|
||||
local BUNDLE_FILE="${TMP_DIR}"/cmbundle.tar.gz
|
||||
docker save quay.io/jetstack/cert-manager-controller:build quay.io/jetstack/cert-manager-acmesolver:build quay.io/jetstack/cert-manager-webhook:build -o "${BUNDLE_FILE}"
|
||||
docker cp "${BUNDLE_FILE}" "${KIND_CONTAINER_NAME}":/cmbundle.tar.gz
|
||||
docker exec "${KIND_CONTAINER_NAME}" docker load -i /cmbundle.tar.gz
|
||||
rm -Rf "${TMP_DIR}"
|
||||
}
|
||||
|
||||
deploy_kind
|
||||
build_images
|
||||
"${SCRIPT_ROOT}/lib/build_images.sh"
|
||||
|
||||
make e2e_test \
|
||||
KUBECONFIG=${KUBECONFIG}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user