diff --git a/README.md b/README.md index 4f2fc61..a4d0547 100644 --- a/README.md +++ b/README.md @@ -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. | diff --git a/bin/aws-code-deploy.sh b/bin/aws-code-deploy.sh index c02a12d..7014e2a 100644 --- a/bin/aws-code-deploy.sh +++ b/bin/aws-code-deploy.sh @@ -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 @@ -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")