forked from jimbobby5/docker-bases
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·43 lines (30 loc) · 990 Bytes
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash -e
if [ $# -ne 3 ]
then
echo "usage: dockerfile_dir output_image_name output_image_version"
exit 1
fi
DOCKERFILE_DIR=$1
OUTPUT_IMAGE_NAME=$2
OUTPUT_IMAGE_VERSION=$3
OUTPUT_IMAGE=${OUTPUT_IMAGE_NAME}:${OUTPUT_IMAGE_VERSION}
TAR_FILE=${OUTPUT_IMAGE_NAME}${OUTPUT_IMAGE_VERSION}.tar
BUCKET_NAME=${OUTPUT_IMAGE_NAME}${OUTPUT_IMAGE_VERSION}
echo Docker build...
docker build -t ${OUTPUT_IMAGE} ${DOCKERFILE_DIR}
echo Docker save...
docker save -o ${TAR_FILE} ${OUTPUT_IMAGE}
echo Creating S3 bucket ${BUCKET_NAME}...
aws s3api create-bucket --bucket ${BUCKET_NAME} --acl private
echo Upload to S3 bucket...
KEY=$(basename ${TAR_FILE})
aws s3api put-object --bucket ${BUCKET_NAME} --body ${TAR_FILE} --key ${KEY}
echo Give public read perms on bucket...
aws s3api put-object-acl --bucket ${BUCKET_NAME} --key ${KEY} --acl public-read
echo ${BUCKET_NAME} ${KEY}
echo Done
# todo add tags
# Custodian: roberts
# Owner: cpe
# Created by: roberts
# Attribution: cpe