Skip to content

Commit

Permalink
Merge pull request jfrog#22 from jfrog/feature/docker4mac
Browse files Browse the repository at this point in the history
add docker4mac testing option
  • Loading branch information
jainishshah17 authored Sep 10, 2018
2 parents e9adb41 + 2b99ba7 commit 7fd7b01
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 7 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ lint:
$(eval export CHART_TESTING_TAG)
$(eval export CHARTS_REPO)
test/lint-charts.sh

.PHONY: test-mac
test-mac:
$(eval export CHART_TESTING_TAG)
$(eval export CHARTS_REPO)
test/e2e-docker4mac.sh
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ Now you can then run `helm search jfrog` to see the available charts.

## Contributing to JFrog Charts

Fork the `repo`, make changes and then please run `make lint` to lint charts locally, at last install the chart to see it is working. :)
Fork the `repo`, make changes and then please run `make lint` to lint charts locally, and at last install the chart to see it is working. :)

On success make a [pull request](https://help.github.com/articles/using-pull-requests) (PR).

Upon successful review, someone will give the PR a __LGTM__ (_looks good to me_) in the review thread.
Two __LGTM__ are needed to get the PR approved and merged.

## Testing charts locally

On the Mac you can run `make test-mac` which will lint, install and test changed charts on `Docker for Mac`.

## Docs

For more information on using Helm, refer to the Helm's [documentation](https://docs.helm.sh/using_helm/#quickstart-guide).
Expand Down
82 changes: 82 additions & 0 deletions test/e2e-docker4mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env bash

# Copyright 2018 The Helm Authors. All rights reserved.
#
# 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

readonly IMAGE_TAG=${CHART_TESTING_TAG}
readonly IMAGE_REPOSITORY="gcr.io/kubernetes-charts-ci/chart-testing"

main() {
local testcontainer_id
testcontainer_id=$(create_testcontainer)

# shellcheck disable=SC2064
trap "docker container rm --force $testcontainer_id > /dev/null" EXIT

configure_kubectl "$testcontainer_id"
run_test
}

lookup_apiserver_container_id() {
docker container list --filter name=k8s_kube-apiserver --format '{{ .ID }}'
}

get_apiserver_arg() {
local container_id="$1"
local arg="$2"
docker container inspect "$container_id" | jq -r ".[].Args[] | capture(\"$arg=(?<arg>.*)\") | .arg"
}

create_testcontainer() {
docker container run --interactive --tty --detach \
--volume "$(pwd):/workdir" --workdir /workdir \
"$IMAGE_REPOSITORY:$IMAGE_TAG" cat
}

configure_kubectl() {
local testcontainer_id="$1"

local apiserver_id
apiserver_id=$(lookup_apiserver_container_id)

if [[ -z "$apiserver_id" ]]; then
echo "ERROR: API-Server container not found. Make sure 'Show system containers' is enabled in Docker4Mac 'Preferences'!" >&2
exit 1
fi

local ip
ip=$(get_apiserver_arg "$apiserver_id" --advertise-address)

local port
port=$(get_apiserver_arg "$apiserver_id" --secure-port)

docker cp "$HOME/.kube" "$testcontainer_id:/root/.kube"
docker exec "$testcontainer_id" kubectl config set-cluster docker-for-desktop-cluster "--server=https://$ip:$port"
docker exec "$testcontainer_id" kubectl config set-cluster docker-for-desktop-cluster --insecure-skip-tls-verify=true
docker exec "$testcontainer_id" kubectl config use-context docker-for-desktop
}

run_test() {
git remote add k8s ${CHARTS_REPO} &> /dev/null || true
git fetch k8s
docker exec "$testcontainer_id" chart_test.sh --config test/.testenv

echo "Done Testing!"
}

main
4 changes: 1 addition & 3 deletions test/e2e-gke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ echo $GCLOUD_GKE_CLUSTER | base64 --decode -i > ${PWD}/cluster
source ${PWD}/cluster

main() {
if [[ $(git remote | grep k8s) = '' ]]; then
git remote add k8s ${CHARTS_REPO}
fi
git remote add k8s ${CHARTS_REPO} &> /dev/null || true
git fetch k8s master

local config_container_id
Expand Down
4 changes: 1 addition & 3 deletions test/lint-charts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ readonly IMAGE_REPOSITORY="gcr.io/kubernetes-charts-ci/chart-testing"
readonly REPO_ROOT="${REPO_ROOT:-$(git rev-parse --show-toplevel)}"

main() {
if [[ $(git remote | grep k8s) = '' ]]; then
git remote add k8s ${CHARTS_REPO}
fi
git remote add k8s ${CHARTS_REPO} &> /dev/null || true
git fetch k8s master

mkdir -p tmp
Expand Down

0 comments on commit 7fd7b01

Please sign in to comment.