Skip to content

Commit 1f912cc

Browse files
author
Fawad Khaliq
authored
Build and publish the controller image in the CI (#380)
1 parent fc3a6d9 commit 1f912cc

File tree

4 files changed

+90
-9
lines changed

4 files changed

+90
-9
lines changed

scripts/install-cert-manager.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66

77
set -Eo pipefail
88

9-
CERT_MANAGER_VERSION="v0.14.3"
9+
DEFAULT_CERT_MANAGER_VERSION="v0.14.3"
1010

11-
kubectl apply --validate=false -f https://github.com/jetstack/cert-manager/releases/download/${CERT_MANAGER_VERSION}/cert-manager.yaml
11+
check_is_installed kubectl "You can install kubectl with the helper scripts/install-kubectl.sh"
12+
13+
__cert_manager_version="$1"
14+
if [ "z$__cert_manager_version" == "z" ]; then
15+
__cert_manager_version=${CERT_MANAGER_VERSION:-$DEFAULT_CERT_MANAGER_VERSION}
16+
fi
17+
18+
echo -n "installing cert-manager ... "
19+
__cert_manager_url="https://github.com/jetstack/cert-manager/releases/download/${__cert_manager_version}/cert-manager.yaml"
20+
echo -n "installing cert-manager from $__cert_manager_url ... "
21+
kubectl apply --validate=false -f $__cert_manager_url
22+
echo "ok."

scripts/lib/aws.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
AWS_CLI_VERSION=$(aws --version 2>&1 | cut -d/ -f2 | cut -d. -f1)
4+
5+
# aws_check_credentials() calls the STS::GetCallerIdentity API call and
6+
# verifies that there is a local identity for running AWS commands
7+
aws_check_credentials() {
8+
echo -n "checking AWS credentials ... "
9+
aws sts get-caller-identity --query "Account" >/dev/null ||
10+
( echo "\nFATAL: No AWS credentials found. Please run \`aws configure\` to set up the CLI for your credentials." && exit 1 )
11+
echo "ok."
12+
}
13+
14+
aws_account_id() {
15+
JSON=$( aws sts get-caller-identity --output json || exit 1 )
16+
echo "${JSON}" | jq --raw-output ".Account"
17+
}
18+
19+
ecr_login() {
20+
echo -n "ecr login ... "
21+
local __aws_region=$1
22+
local __ecr_url=$2
23+
local __err_msg="Failed ECR login. Please make sure you have IAM permissions to access ECR."
24+
if [ $AWS_CLI_VERSION -gt 1 ]; then
25+
( aws ecr get-login-password --region $__aws_region | \
26+
docker login --username AWS --password-stdin $__ecr_url ) ||
27+
( echo "\n$__err_msg" && exit 1 )
28+
else
29+
$( aws ecr get-login --no-include-email ) || ( echo "\n$__err_msg" && exit 1 )
30+
fi
31+
echo "ok."
32+
}

scripts/lib/common.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ is_installed() {
3535
fi
3636
}
3737

38+
# vpc_id fetches the vpc id of the GitHub Actions runner/EC2 instance.
39+
# vpc id is needed for setting up AWS CloudMap namespaces
40+
vpc_id() {
41+
local __md_url="http://169.254.169.254/latest/meta-data/network/interfaces"
42+
local __macid=$( curl $__md_url/macs/ || exit 1 )
43+
local __vpcid=$( curl $__md_url/macs/${macid}/vpc-id || exit 1 )
44+
echo "$__vpcid"
45+
46+
}
47+
3848
DEFAULT_DEBUG_PREFIX="DEBUG: "
3949

4050
# debug_msg prints out a supplied message if the DEBUG environs variable is

scripts/test-with-kind.sh

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,18 @@ SCRIPTS_DIR=$(cd "$(dirname "$0")" || exit 1; pwd)
1010
ROOT_DIR="$SCRIPTS_DIR/.."
1111
INT_TEST_DIR="$ROOT_DIR/test/integration"
1212

13+
AWS_ACCOUNT_ID=${AWS_ACCOUNT_ID:-""}
14+
AWS_REGION=${AWS_REGION:-"us-west-2"}
15+
IMAGE_NAME=amazon/appmesh-controller
16+
ECR_URL=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com
17+
IMAGE=${ECR_URL}/${IMAGE_NAME}
18+
19+
1320
CLUSTER_NAME_BASE="test"
1421
K8S_VERSION="1.17"
1522
TMP_DIR=""
1623

24+
source "$SCRIPTS_DIR/lib/aws.sh"
1725
source "$SCRIPTS_DIR/lib/common.sh"
1826

1927
check_is_installed curl
@@ -36,21 +44,42 @@ function setup_kind_cluster {
3644
}
3745

3846
function install_crds {
39-
make install
47+
echo "installing CRDs ... "
48+
make install
49+
echo "ok."
4050
}
4151

4252
function build_and_publish_controller {
43-
echo "Not implemented"
53+
echo -n "building and publishing appmesh controller ... "
54+
AWS_ACCOUNT=$AWS_ACCOUNT_ID AWS_REGION=$AWS_REGION make docker-build
55+
AWS_ACCOUNT=$AWS_ACCOUNT_ID AWS_REGION=$AWS_REGION make docker-push
56+
echo "ok."
4457
}
4558

46-
function install_controller {
47-
echo "Not implemented"
59+
function run_integration_tests {
60+
echo "Not implemented"
4861
}
4962

50-
function run_integration_tests {
51-
echo "Not implemented"
63+
function clean_up {
64+
if [ -v "$TMP_DIR" ]; then
65+
"${SCRIPTS_DIR}"/delete-kind-cluster.sh -c "$TMP_DIR" || :
66+
fi
67+
return
5268
}
5369

70+
trap "clean_up" EXIT
71+
72+
aws_check_credentials
73+
74+
if [ -z "$AWS_ACCOUNT_ID" ]; then
75+
AWS_ACCOUNT_ID=$( aws_account_id )
76+
fi
77+
78+
ecr_login $AWS_REGION $ECR_URL
79+
80+
# Build and publish the controller image
81+
build_and_publish_controller
82+
5483
setup_kind_cluster
5584
export KUBECONFIG="${TMP_DIR}/kubeconfig"
5685

@@ -60,6 +89,5 @@ install_crds
6089
# Install cert-manager
6190
$SCRIPTS_DIR/install-cert-manager.sh
6291

63-
6492
# Show the installed CRDs
6593
kubectl get crds

0 commit comments

Comments
 (0)