Skip to content

Commit ff78b63

Browse files
authored
[Don't merge] Have options in release scripts to make AMI's public (docker-archive#462)
Have options in release scripts to make AMI's public
1 parent da94d29 commit ff78b63

File tree

9 files changed

+76
-17
lines changed

9 files changed

+76
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ To run the automated release process:
4343
- make sure the file is made public.
4444
7. Run the release script: (change variables to match the release)
4545
- `cd aws/release/`
46-
- example: `./run_release.sh -d 1.12.1-rc1 -e beta5 -a ami-61f6b501 -r us-west-1 -c beta`
46+
- example: `./run_release.sh -d 1.12.1-rc1 -e beta5 -a ami-61f6b501 -r us-west-1 -c beta -p no`
4747
8. Get the URL output from release script, give to person creating release notes and sending emails.
4848
9. Test out CloudFormation template before sending out emails.
4949
10. Update beta docs site

aws/release/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
default:
2-
./run_release.sh -d $(EDITIONS_DOCKER_VERSION) -e $(EDITIONS_TAG) -a $(AMI) -r $(REGION) -c $(CHANNEL) -u $(CHANNEL_CLOUD)
2+
./run_release.sh -d $(EDITIONS_DOCKER_VERSION) -e $(EDITIONS_TAG) -a $(AMI) -r $(REGION) -c $(CHANNEL) -u $(CHANNEL_CLOUD) -p $(MAKE_AMI_PUBLIC)

aws/release/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ This script will take some parameters and then it will do the following.
2020
1. Checkout the master branch from `https://github.com/docker/editions` and make sure local copy is up to date.
2121
2. Calling `aws/release/run_release.sh` script, passing in correct variables. For example:
2222

23-
$ aws/release/run_release.sh -d docker_version -e edition_version -a ami_id -r ami_src_region
23+
$ aws/release/run_release.sh -d docker_version -e edition_version -a ami_id -r ami_src_region -p no
2424

25-
$ aws/release/run_release.sh -d "1.12.0" -e "beta4" -a "ami-148c4e74" -r "us-west-2"
25+
$ aws/release/run_release.sh -d "1.12.0" -e "beta4" -a "ami-148c4e74" -r "us-west-2" -p no
2626

2727
optional fields:
2828
-c channel (defaults to beta) [beta, nightly, alpha, etc]
2929
-l AWS account list url, url for the list of Answers4AWS accounts we want to give access to the AMI.
30+
-p make the ami public? (yes, no)
3031

3132
3. Look at the logs and find the CloudFormation s3 url, and give that to who needs it.
3233
4. Tag the code and push tags to github, and create release from tag.

aws/release/files/aws_release.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
import argparse
44

55
from utils import (
6-
get_ami, wait_for_ami_to_be_available, copy_amis, strip_and_padd, get_account_list,
6+
copy_amis, get_account_list, set_ami_public,
77
approve_accounts, ACCOUNT_LIST_FILE_URL, create_cfn_template)
88

99

1010
CFN_TEMPLATE = '/home/docker/docker_for_aws.template'
1111
CFN_CLOUD_TEMPLATE = '/home/docker/docker_for_aws_cloud.template'
1212

13+
1314
def main():
1415
parser = argparse.ArgumentParser(description='Release Docker for AWS')
1516
parser.add_argument('-d', '--docker_version',
@@ -33,6 +34,9 @@ def main():
3334
parser.add_argument('-l', '--account_list_url',
3435
dest='account_list_url', default=ACCOUNT_LIST_FILE_URL,
3536
help="The URL for the aws account list for ami approvals")
37+
parser.add_argument('-p', '--public',
38+
dest='make_ami_public', default="no",
39+
help="Make the AMI public")
3640

3741
args = parser.parse_args()
3842

@@ -53,36 +57,55 @@ def main():
5357
print(u"ami_id={}".format(args.ami_id))
5458
print(u"ami_src_region={}".format(args.ami_src_region))
5559
print(u"account_list_url={}".format(args.account_list_url))
60+
print(u"make_ami_public={}".format(args.make_ami_public))
5661
if not args.account_list_url:
5762
print("account_list_url parameter is None, defaulting")
5863
account_list_url = ACCOUNT_LIST_FILE_URL
5964
else:
6065
account_list_url = args.account_list_url
6166
print(u"account_list_url={}".format(account_list_url))
6267

68+
if not args.make_ami_public:
69+
make_ami_public = False
70+
else:
71+
make_ami_public = args.make_ami_public
72+
if make_ami_public.lower() == 'yes':
73+
make_ami_public = True
74+
else:
75+
make_ami_public = False
76+
print(u"make_ami_public={}".format(make_ami_public))
77+
6378
print("Copy AMI to each region..")
6479
ami_list = copy_amis(args.ami_id, args.ami_src_region,
6580
image_name, image_description, release_channel)
6681
ami_list_json = json.dumps(ami_list, indent=4, sort_keys=True)
6782
print(u"AMI copy complete. AMI List: \n{}".format(ami_list_json))
68-
print("Get account list..")
69-
account_list = get_account_list(account_list_url)
70-
print(u"Approving AMIs for {} accounts..".format(len(account_list)))
71-
approve_accounts(ami_list, account_list)
83+
84+
if make_ami_public:
85+
print("Make AMI's public.")
86+
# we want to make this public.
87+
set_ami_public(ami_list)
88+
print("Finished making AMI's public.")
89+
else:
90+
print("Get account list..")
91+
account_list = get_account_list(account_list_url)
92+
print(u"Approving AMIs for {} accounts..".format(len(account_list)))
93+
approve_accounts(ami_list, account_list)
7294
print("Accounts have been approved.")
7395

7496
print("Create CloudFormation template..")
7597
s3_url = create_cfn_template(ami_list, release_channel, docker_version,
7698
docker_for_aws_version, edition_version, CFN_TEMPLATE,
7799
docker_for_aws_version)
78100
s3_cloud_url = create_cfn_template(ami_list, release_cloud_channel, docker_version,
79-
docker_for_aws_version, edition_version, CFN_CLOUD_TEMPLATE,
80-
docker_for_aws_version)
101+
docker_for_aws_version, edition_version, CFN_CLOUD_TEMPLATE,
102+
docker_for_aws_version)
81103

82104
# TODO: git commit, tag release. requires github keys, etc.
83105

84106
print("------------------")
85-
print(u"Finshed.. CloudFormation \n\t URL={0} \n\t CLOUD_URL={1} \n".format(s3_url, s3_cloud_url))
107+
print(u"Finshed.. CloudFormation \n\t URL={0} \n\t CLOUD_URL={1} \n".format(
108+
s3_url, s3_cloud_url))
86109
print("Don't forget to tag the code (git tag -a v{0}-{1} -m {0}; git push --tags)".format(
87110
docker_version, flat_edition_version))
88111
print("------------------")

aws/release/files/release.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
# EDITION_VERSION
88
# AMI_ID
99
# AMI_SRC_REGION
10+
# MAKE_AMI_PUBLIC
1011

1112
# don't buffer the output
1213
export PYTHONUNBUFFERED=1
1314

1415
python /home/docker/aws_release.py --docker_version="$DOCKER_VERSION" \
1516
--edition_version="$EDITION_VERSION" --ami_id="$AMI_ID" \
16-
--ami_src_region="$AMI_SRC_REGION" --channel="$CHANNEL" --channel_cloud="$CHANNEL_CLOUD" --account_list_url="$AWS_ACCOUNT_LIST_URL"
17+
--ami_src_region="$AMI_SRC_REGION" --channel="$CHANNEL" \
18+
--channel_cloud="$CHANNEL_CLOUD" --account_list_url="$AWS_ACCOUNT_LIST_URL" \
19+
--public="$MAKE_AMI_PUBLIC"

aws/release/files/utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,25 @@ def approve_accounts(ami_list, account_list):
147147
return ami_list
148148

149149

150+
def set_ami_public(ami_list):
151+
""" set the AMI's to public """
152+
for ami in ami_list:
153+
print(u"Set AMI public: {}".format(ami))
154+
region = ami
155+
ami_id = ami_list.get(region).get('HVM64')
156+
print(u"Set public AMI: {} ; Region: {} ".format(ami_id, region))
157+
con = ec2.connect_to_region(region, aws_access_key_id=AWS_ACCESS_KEY_ID,
158+
aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
159+
160+
print("Wait until the AMI is available before we continue.")
161+
wait_for_ami_to_be_available(con, ami_id)
162+
163+
con.modify_image_attribute(ami_id,
164+
operation='add',
165+
attribute='launchPermission',
166+
groups='all')
167+
168+
150169
def upload_cfn_template(release_channel, cloudformation_template_name, tempfile, cfn_type=''):
151170

152171
# upload to s3, make public, return s3 URL

aws/release/full_aws_release.sh

100644100755
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ DOCKER_VERSION=
1212
EDITION_VERSION=
1313
CHANNEL=
1414
DOCKER_AWS_ACCOUNT_URL=
15+
MAKE_AMI_PUBLIC="no"
1516

1617
usage()
1718
{
@@ -32,10 +33,11 @@ OPTIONS:
3233
-b Docker Bin URL (location where tar.gz file can be downloaded)
3334
-c Release Channel (beta, nightly, etc)
3435
-l AWS account list URL
36+
-p Make AMI public (yes, no)
3537
EOF
3638
}
3739

38-
while getopts "hc:l:d:e:b:" OPTION
40+
while getopts "hc:l:d:e:b:p:" OPTION
3941
do
4042
case $OPTION in
4143
h)
@@ -57,6 +59,9 @@ do
5759
l)
5860
DOCKER_AWS_ACCOUNT_URL=$OPTARG
5961
;;
62+
p)
63+
MAKE_AMI_PUBLIC=$OPTARG
64+
;;
6065
?)
6166
usage
6267
exit
@@ -99,6 +104,7 @@ echo "AMI_SRC_REGION=$AMI_SRC_REGION"
99104
echo "CHANNEL=$CHANNEL"
100105
echo "DOCKER_AWS_ACCOUNT_URL=$DOCKER_AWS_ACCOUNT_URL"
101106
echo "Docker Hub Login ID=$HUB_LOGIN_ID"
107+
echo "MAKE_AMI_PUBLIC=$MAKE_AMI_PUBLIC"
102108
echo "-------"
103109
echo "== Checking Hub login =="
104110

@@ -193,6 +199,6 @@ echo "== Build Docker images =="
193199
cd $BASE_DIR
194200

195201
# run release, this will create CFN templates and push them to s3, push AMI to different regions and share with list of approved accounts.
196-
./run_release.sh -d $DOCKER_VERSION -e $EDITION_VERSION -a $AMI_ID -r $AMI_SRC_REGION -c $CHANNEL -l $DOCKER_AWS_ACCOUNT_URL -u cloud-$CHANNEL
202+
./run_release.sh -d $DOCKER_VERSION -e $EDITION_VERSION -a $AMI_ID -r $AMI_SRC_REGION -c $CHANNEL -l $DOCKER_AWS_ACCOUNT_URL -u cloud-$CHANNEL -p $MAKE_AMI_PUBLIC
197203

198204
echo "===== Done ====="

aws/release/nightly.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ cd $CURRPATH
9494
cd $BUILD_HOME/code/editions/aws/release
9595

9696
# run release
97-
./run_release.sh -d $DOCKER_VERSION -e $EDITION_VERSION -a $AMI_ID -r $AMI_SOURCE_REGION -c nightly -l $DOCKER_AWS_ACCOUNT_URL -u cloud-nightly
97+
./run_release.sh -d $DOCKER_VERSION -e $EDITION_VERSION -a $AMI_ID -r $AMI_SOURCE_REGION -c nightly -l $DOCKER_AWS_ACCOUNT_URL -u cloud-nightly -p no
9898

9999
# run cleanup, remove things that are more than X days old.
100100
python cleanup.py

aws/release/run_release.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ AMI_SRC_REGION=
1313
CHANNEL=
1414
CHANNEL_CLOUD=
1515
AWS_ACCOUNT_LIST_URL=
16+
MAKE_AMI_PUBLIC="no"
1617

1718
usage()
1819
{
@@ -35,10 +36,11 @@ OPTIONS:
3536
-c Release Channel (beta, nightly, etc)
3637
-u Cloud Release Channel (beta, nightly, etc)
3738
-l AWS account list URL
39+
-p Make AMI public (yes, no)
3840
EOF
3941
}
4042

41-
while getopts "hc:u:l:d:e:a:r:" OPTION
43+
while getopts "hc:u:l:d:e:a:r:p:" OPTION
4244
do
4345
case $OPTION in
4446
h)
@@ -66,6 +68,9 @@ do
6668
l)
6769
AWS_ACCOUNT_LIST_URL=$OPTARG
6870
;;
71+
p)
72+
MAKE_AMI_PUBLIC=$OPTARG
73+
;;
6974
?)
7075
usage
7176
exit
@@ -102,6 +107,7 @@ echo "AMI_SRC_REGION=$AMI_SRC_REGION"
102107
echo "CHANNEL=$CHANNEL"
103108
echo "CHANNEL_CLOUD=$CHANNEL_CLOUD"
104109
echo "AWS_ACCOUNT_LIST_URL=$AWS_ACCOUNT_LIST_URL"
110+
echo "MAKE_AMI_PUBLIC=$MAKE_AMI_PUBLIC"
105111
echo "-------"
106112
echo "== Prepare files =="
107113

@@ -134,6 +140,7 @@ docker run -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
134140
-e CHANNEL="$CHANNEL" \
135141
-e CHANNEL_CLOUD="$CHANNEL_CLOUD" \
136142
-e AWS_ACCOUNT_LIST_URL="$AWS_ACCOUNT_LIST_URL" \
143+
-e MAKE_AMI_PUBLIC="$MAKE_AMI_PUBLIC" \
137144
docker4x/release-$BUILD_NUMBER
138145

139146
# posthook

0 commit comments

Comments
 (0)