Commit 3341dd15 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

fix: normalize prefix

parent 255906e0
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -289,6 +289,11 @@ stages:
    export env=$1
    bucket=$2
    prefix=$3
    # normalize prefix with trailing slash
    if [[ "$prefix" ]] && [[ "${prefix:0:1}" != "/" ]]
    then
      prefix="/$prefix"
    fi

    # extract hostname from $CI_ENVIRONMENT_URL
    hostname=$(echo "$CI_ENVIRONMENT_URL" | awk -F[/:] '{print $4}')
@@ -300,10 +305,10 @@ stages:
    log_info "--- env: \\e[33;1m${env}\\e[0m"
    log_info "--- hostname: \\e[33;1m${hostname}\\e[0m"

    # get or create bucket
    # maybe create bucket
    if s3cmd info "s3://${bucket}" >/dev/null 2>&1
    then
      log_info "... S3 bucket \\e[33;1m${bucket}\\e[0m already created: continue"
      log_info "... S3 bucket \\e[33;1m${bucket}\\e[0m found: continue"
    else
      log_info "... S3 bucket \\e[33;1m${bucket}\\e[0m not found: create"
      # shellcheck disable=SC2086
@@ -324,7 +329,7 @@ stages:
    # sync files
    log_info "... synchronize files"
    # shellcheck disable=SC2086
    s3cmd ${TRACE+-v} $S3_DEPLOY_ARGS $S3_DEPLOY_FILES "s3://${bucket}${prefix}"
    s3cmd ${TRACE+-v} $S3_DEPLOY_ARGS $S3_DEPLOY_FILES "s3://${bucket}${prefix}/"

    # create website
    if [[ "$S3_WEBSITE_DISABLED" != "true" ]]
@@ -344,6 +349,11 @@ stages:
    export env=$1
    bucket=$2
    prefix=$3
    # normalize prefix with trailing slash
    if [[ "$prefix" ]] && [[ "${prefix:0:1}" != "/" ]]
    then
      prefix="/$prefix"
    fi

    log_info "--- \\e[32mdelete\\e[0m (env: ${env})"
    log_info "--- bucket: \\e[33;1m${bucket}\\e[0m"
@@ -359,7 +369,7 @@ stages:

    # delete files
    log_info "... delete files from \\e[33;1m${bucket}${prefix}\\e[0m"
    s3cmd ${TRACE+-v} rm --recursive --force "s3://${bucket}${prefix}"
    s3cmd ${TRACE+-v} rm --recursive --force "s3://${bucket}${prefix}/"

    # finally delete bucket if empty
    objs_count=$(s3cmd du "s3://${bucket}" | tr -s ' ' | cut -d' ' -f3)