Skip to content

Commit 407bde5

Browse files
author
Ken Simon
committed
WIP: CI Tests
Signed-off-by: Ken Simon <[email protected]>
1 parent 9f8937e commit 407bde5

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

Dockerfile.ci

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM alpine:3.5
2+
3+
RUN apk add --no-cache curl
4+
# curl kubectl instead of ADD'ing it, since we want to cache the layer
5+
RUN curl -sfL \
6+
-o /usr/local/bin/kubectl \
7+
https://storage.googleapis.com/kubernetes-release/release/v1.6.1/bin/linux/amd64/kubectl \
8+
&& chmod +x /usr/local/bin/kubectl
9+
10+
RUN mkdir -p /ci && \
11+
mkdir -p /aws && \
12+
apk add --no-cache \
13+
bash \
14+
git \
15+
ca-certificates \
16+
groff \
17+
less \
18+
python \
19+
py-pip \
20+
openssh-client \
21+
&& pip install awscli
22+
23+
VOLUME /src
24+
WORKDIR /src
25+
ENTRYPOINT ./ci/k8s-tests.sh

ci/k8s-tests.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/bin/bash
2+
3+
# Copyright 2017 by the contributors
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This runs integration tests for the local repository, deploying it to
18+
# CloudFormation and testing various bits of functionality underneath.
19+
20+
set -o errexit
21+
set -o nounset
22+
set -o pipefail
23+
set -o verbose
24+
25+
if ! grep -q Alpine /etc/issue 2>/dev/null; then
26+
echo "This script is must be run in a docker container (and will make changes to the filesystem, including /root/.ssh). Exiting."
27+
exit 1
28+
fi
29+
30+
REGION="${REGION:-us-west-2}"
31+
AZ="${AZ:-us-west-2c}"
32+
S3_BUCKET="${S3_BUCKET:-"heptio-aws-quickstart-test"}"
33+
S3_PREFIX="${S3_PREFIX:-"heptio/kubernetes"}"
34+
SSH_KEY="${SSH_KEY:-/tmp/ssh/id_rsa}"
35+
SSH_KEY_NAME="${SSH_KEY_NAME:-jenkins}"
36+
37+
STACK_NAME="${STACK_NAME:-}"
38+
if [[ -z "${STACK_NAME}" ]]; then
39+
STACK_NAME="qs-ci-$(git rev-parse --short HEAD)"
40+
fi
41+
42+
# Set/ensure env vars needed by AWS, etc
43+
export AWS_DEFAULT_REGION="${REGION}"
44+
45+
# Setup ssh. Due to SSH being incredibly paranoid about filesystem permissions
46+
# we just create our own ssh directory and set it from there. (This also
47+
# allows the docker volume mounts to be read-only.)
48+
mkdir -p /root/.ssh
49+
chmod 0700 /root/.ssh
50+
cp "${SSH_KEY}" /root/.ssh/identity
51+
export SSH_KEY=/root/.ssh/identity
52+
chmod 0600 $SSH_KEY
53+
54+
aws --version
55+
kubectl version --client
56+
57+
aws s3 sync --acl=public-read --delete ./templates "s3://${S3_BUCKET}/${S3_PREFIX}/${STACK_NAME}/templates/"
58+
aws s3 sync --acl=public-read --delete ./scripts "s3://${S3_BUCKET}/${S3_PREFIX}/${STACK_NAME}/scripts/"
59+
60+
aws cloudformation create-stack \
61+
--disable-rollback \
62+
--region "${REGION}" \
63+
--stack-name "${STACK_NAME}" \
64+
--template-url "https://${S3_BUCKET}.s3.amazonaws.com/${S3_PREFIX}/${STACK_NAME}/templates/kubernetes-cluster-with-new-vpc.template" \
65+
--parameters \
66+
ParameterKey=AvailabilityZone,ParameterValue="${AZ}" \
67+
ParameterKey=KeyName,ParameterValue="${SSH_KEY_NAME}" \
68+
ParameterKey=QSS3BucketName,ParameterValue="${S3_BUCKET}" \
69+
ParameterKey=QSS3KeyPrefix,ParameterValue="${S3_PREFIX}/${STACK_NAME}" \
70+
ParameterKey=AdminIngressLocation,ParameterValue=0.0.0.0/0 \
71+
ParameterKey=NetworkingProvider,ParameterValue=calico \
72+
--capabilities=CAPABILITY_IAM
73+
74+
aws cloudformation wait stack-create-complete --stack-name "${STACK_NAME}"
75+
76+
# Pre-load the SSH host keys
77+
BASTION_IP=$(aws cloudformation describe-stacks \
78+
--query 'Stacks[*].Outputs[?OutputKey == `BastionHostPublicIp`].OutputValue' \
79+
--output text --stack-name $STACK_NAME
80+
)
81+
MASTER_IP=$(aws cloudformation describe-stacks \
82+
--query 'Stacks[*].Outputs[?OutputKey == `MasterPrivateIp`].OutputValue' \
83+
--output text --stack-name $STACK_NAME
84+
)
85+
ssh -i "$SSH_KEY" -o StrictHostKeyChecking=no -o ProxyCommand="ssh -i ${SSH_KEY} -o StrictHostKeyChecking=no ubuntu@${BASTION_IP} nc %h %p" ubuntu@${MASTER_IP} exit 0
86+
87+
# TODO: this is a hack... GetKubeConfigCommand has a fake
88+
# "SSH_KEY=path/to/blah.pem" output, we want to override that with our actual
89+
# one.
90+
KUBECONFIG_COMMAND=$(aws cloudformation describe-stacks \
91+
--query 'Stacks[*].Outputs[?OutputKey == `GetKubeConfigCommand`].OutputValue' \
92+
--output text --stack-name $STACK_NAME \
93+
| sed "s!path/to/${SSH_KEY_NAME}.pem!${SSH_KEY}!"
94+
)
95+
eval "${KUBECONFIG_COMMAND}"
96+
export KUBECONFIG=./kubeconfig
97+
98+
# Tests start here
99+
kubectl get pods --all-namespaces

0 commit comments

Comments
 (0)