Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deployment steps for self-provisioned K8s via AWS and ECR #48

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add code for ECR
Signed-off-by: arcolife <archit.py@gmail.com>
arcolife committed Aug 29, 2022
commit e10044efe9c88db7c8c352fa1986374dbd4a47bd
6 changes: 6 additions & 0 deletions sample-network/network
Original file line number Diff line number Diff line change
@@ -90,6 +90,11 @@ context CONSOLE_IMAGE_LABEL latest
context DEPLOYER_IMAGE ghcr.io/ibm-blockchain/fabric-deployer
context DEPLOYER_IMAGE_LABEL latest-amd64

context AWS_PROFILE default
context AWS_ACCOUNT 999999999999
context AWS_ECR_REPO chaincodes
context CHAINCODE_REGISTRY default

export FABRIC_OPERATOR_IMAGE=${OPERATOR_IMAGE}:${OPERATOR_IMAGE_LABEL}
export FABRIC_CONSOLE_IMAGE=${CONSOLE_IMAGE}:${CONSOLE_IMAGE_LABEL}
export FABRIC_DEPLOYER_IMAGE=${DEPLOYER_IMAGE}:${DEPLOYER_IMAGE_LABEL}
@@ -141,6 +146,7 @@ function print_help() {
. scripts/test_network.sh
. scripts/channel.sh
. scripts/chaincode.sh
. scripts/aws_ecr.sh

# check for kind, kubectl, etc.
check_prereqs
30 changes: 30 additions & 0 deletions sample-network/scripts/aws_ecr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

aws_env() {
push_fn "Check AWS CLI access for ${ECR_RESOURCE}"

AWS_ACCESS_KEY_ID=$(aws configure get aws_access_key_id --profile ${AWS_PROFILE})
AWS_SECRET_ACCESS_KEY=$(aws configure get aws_secret_access_key --profile ${AWS_PROFILE})

ECR_USER=AWS
ECR_REGION=$(aws configure get region --profile ${AWS_PROFILE})

export ECR_RESOURCE=${AWS_ACCOUNT}.dkr.ecr.${ECR_REGION}.amazonaws.com

pop_fn
}

ecr_login() {
# exported variables used:
# AWS_PROFILE
# AWS_ACCOUNT

aws_env

push_fn "Login to AWS ECR ${ECR_RESOURCE}"

aws ecr get-login-password --region ${ECR_REGION} | \
$CONTAINER_CLI login --username ${ECR_USER} --password-stdin ${ECR_RESOURCE}

pop_fn
}
31 changes: 31 additions & 0 deletions sample-network/scripts/chaincode.sh
Original file line number Diff line number Diff line change
@@ -17,6 +17,34 @@
# limitations under the License.
#

function set_ecr_image_tag() {
# converts local "/" separated image name to an appropriate ECR tag used in AWS_ECR_REPO
# Example: fabric-samples/asset-transfer-basic/chaincode-java:latest -> asset-transfer-basic_java_latest

local cc_local_image=$1
ECR_IMAGE_TAG=$(python -c 'import sys; p=sys.argv[1]; p=p.split("/")[-3:]; cc=p[1]; lang=p[-1].split("-")[-1]; tag="latest"; print(f"{cc}_{lang}_{tag}")' ${cc_local_image})
}

function ecr_load_image() {
local cc_local_image=$1

ecr_login ${AWS_PROFILE} ${AWS_ACCOUNT}

local aws_ecr="${ECR_RESOURCE}/${AWS_ECR_REPO}"

set_ecr_image_tag ${cc_local_image}

CHAINCODE_IMAGE="${aws_ecr}:${ECR_IMAGE_TAG}"

push_fn "Tag chaincode image for ECR"
$CONTAINER_CLI tag ${cc_local_image} ${CHAINCODE_IMAGE}
pop_fn

push_fn "Load chaincode image into ECR"
$CONTAINER_CLI push "${CHAINCODE_IMAGE}"
pop_fn
}

# Convenience routine to "do everything" required to bring up a sample CC.
function deploy_chaincode() {
local cc_name=$1
@@ -33,8 +61,11 @@ function deploy_chaincode() {

build_chaincode_image ${cc_folder} ${CHAINCODE_IMAGE}

# push to container registry
if [ "${CLUSTER_RUNTIME}" == "kind" ]; then
kind_load_image ${CHAINCODE_IMAGE}
elif [ "${CLUSTER_RUNTIME}" == "k3s" ] && [ "${CHAINCODE_REGISTRY}" == "ecr" ]; then
ecr_load_image ${CHAINCODE_IMAGE}
fi

launch_chaincode ${cc_name} ${CHAINCODE_ID} ${CHAINCODE_IMAGE}