Skip to content

Commit

Permalink
Merge pull request #12 from zappan/feature/tgz-bundle-support
Browse files Browse the repository at this point in the history
Feature/tgz bundle support
  • Loading branch information
virgofx authored Jan 7, 2020
2 parents 4f671aa + 3c78e47 commit 87f4b19
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ Environment variables are used to control the deployment actions. A brief summar
| `AWS_CODE_DEPLOY_EC2_TAG_FILTERS` | No | EC2 tags to filter on when creating a deployment group |
| `AWS_CODE_DEPLOY_AUTO_SCALING_GROUPS` | No | Auto Scaling groups when creating a deployment group |
| `AWS_CODE_DEPLOY_APP_SOURCE` | **Yes** | The source directory used to create the deploy archive or a pre-bundled tar, tgz, or zip |
| `AWS_CODE_DEPLOY_APP_BUNDLE_TYPE` | No | Deploy bundle type when created from source directory (`tgz` or `zip`). Default: `zip`)
| `AWS_CODE_DEPLOY_S3_BUCKET` | **Yes** | The name of the S3 bucket to deploy the revision |
| `AWS_CODE_DEPLOY_S3_KEY_PREFIX` | No | A prefix to use for the revision bucket key |
| `AWS_CODE_DEPLOY_S3_FILENAME` | **Yes** | The destination name within S3. |
Expand Down
33 changes: 25 additions & 8 deletions bin/aws-code-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ fi

# ----- Application Source -----
h1 "Step 6: Checking Application Source"
AWS_CODE_DEPLOY_APP_BUNDLE_TYPE=${AWS_CODE_DEPLOY_APP_BUNDLE_TYPE:-zip}
APP_SOURCE=$(readlink -f "${AWS_CODE_DEPLOY_APP_SOURCE:-.}")

if [ ! -d "$APP_SOURCE" -a ! -e "$APP_SOURCE" ]; then
Expand All @@ -341,19 +342,35 @@ if [ -d "$APP_SOURCE" ]; then
error "The specified source directory \"${APP_SOURCE}\" does not contain an \"appspec.yml\" in the application root."
exit 1
fi
if ! typeExists "zip"; then
note "Installing zip binaries ..."
sudo apt-get install -y zip
note "Zip binaries installed."
if [ $AWS_CODE_DEPLOY_APP_BUNDLE_TYPE == "tgz" ]; then
if ! typeExists "tar" -o ! typeExists "gzip"; then
note "Installing tar and gzip binaries ..."
sudo apt-get install -y tar gzip
note "Tar and GZip binaries installed."
fi
BUNDLE_EXTENSION="tar.gz"
else ## defaults to zip
if ! typeExists "zip"; then
note "Installing zip binaries ..."
sudo apt-get install -y zip
note "Zip binaries installed."
fi
BUNDLE_EXTENSION="zip"
fi
DEPLOYMENT_COMPRESS_ORIG_DIR_SIZE=$(du -hs $APP_SOURCE | awk '{ print $1}')
APP_LOCAL_FILE="${AWS_CODE_DEPLOY_S3_FILENAME%.*}.zip"
APP_LOCAL_FILE="${AWS_CODE_DEPLOY_S3_FILENAME%.*}.${BUNDLE_EXTENSION}"
APP_LOCAL_TEMP_FILE="/tmp/$APP_LOCAL_FILE"

runCommand "cd \"$APP_SOURCE\" && zip -rq \"${APP_LOCAL_TEMP_FILE}\" ." \
"Unable to compress \"$APP_SOURCE\""
if [ $AWS_CODE_DEPLOY_APP_BUNDLE_TYPE == "tgz" ]; then
runCommand "tar -zcvf \"${APP_LOCAL_TEMP_FILE}\" -C \"$APP_SOURCE\" ." \
"Unable to compress \"$APP_SOURCE\""
BUNDLE_TYPE="tgz"
else ## defaults to zip
runCommand "cd \"$APP_SOURCE\" && zip -rq \"${APP_LOCAL_TEMP_FILE}\" ." \
"Unable to compress \"$APP_SOURCE\""
BUNDLE_TYPE="zip"
fi
DEPLOYMENT_COMPRESS_FILESIZE=$(ls -lah "${APP_LOCAL_TEMP_FILE}" | awk '{ print $5}')
BUNDLE_TYPE="zip"
success "Successfully compressed \"$APP_SOURCE\" ($DEPLOYMENT_COMPRESS_ORIG_DIR_SIZE) into \"$APP_LOCAL_FILE\" ($DEPLOYMENT_COMPRESS_FILESIZE)"
else
APP_SOURCE_BASENAME=$(basename "$APP_SOURCE")
Expand Down

0 comments on commit 87f4b19

Please sign in to comment.