Loading templates/gitlab-ci-cf.yml +30 −42 Original line number Diff line number Diff line Loading @@ -36,15 +36,8 @@ workflow: - when: always variables: # Color code for traces COLOR_GREEN: "\e[1;32m" COLOR_RED: "\e[1;31m" COLOR_BLUE: "\e[1;34m" COLOR_NONE: "\e[0m" COLOR_YELLOW: "\e[1;33m" # variabilized tracking image TBC_TRACKING_IMAGE: "$CI_REGISTRY/to-be-continuous/tools/tracking:master" TBC_TRACKING_IMAGE: "registry.gitlab.com/to-be-continuous/tools/tracking:master" # Docker Image with CF CLI tool (can be overridden) CF_CLI_IMAGE: "registry.hub.docker.com/governmentpaas/cf-cli" Loading Loading @@ -480,6 +473,15 @@ stages: appname="$6" fi # find manifest manifestfile=$(ls -1 "$CF_SCRIPTS_DIR/${CF_MANIFEST_BASENAME}-${env}.yml" 2>/dev/null || ls -1 "$CF_SCRIPTS_DIR/${CF_MANIFEST_BASENAME}.yml" 2>/dev/null || echo "") if [[ -z "$manifestfile" ]] then log_error "Manifest not found, lookedup paths are:\n - \\e[33;1m$CF_SCRIPTS_DIR/${CF_MANIFEST_BASENAME}-${env}.yml\\e[0m\n - \\e[33;1m$CF_SCRIPTS_DIR/${CF_MANIFEST_BASENAME}.yml\\e[0m" exit 1 fi export manifestfile log_info "--- \\e[32mdeploy\\e[0m (env: \\e[33;1m${env}\\e[0m)" log_info "--- looking for CF scripts in directory: \\e[33;1m${CF_SCRIPTS_DIR}\\e[0m" Loading @@ -489,15 +491,7 @@ stages: export targetvarfile="$CF_SCRIPTS_DIR/generated-vars.yml" generate_vars_file # find manifest manifestfile=$(ls -1 "$CF_SCRIPTS_DIR/${CF_MANIFEST_BASENAME}-${env}.yml" 2>/dev/null || ls -1 "$CF_SCRIPTS_DIR/${CF_MANIFEST_BASENAME}.yml" 2>/dev/null || echo "") export manifestfile if [[ -z "$manifestfile" ]] then log_info "Manifest not found, lookedup paths are:\n - \\e[33;1m$CF_SCRIPTS_DIR/${CF_MANIFEST_BASENAME}-${env}.yml\\e[0m\n - \\e[33;1m$CF_SCRIPTS_DIR/${CF_MANIFEST_BASENAME}.yml\\e[0m\n - no app to deploy" else push_application fi check_readiness Loading Loading @@ -670,14 +664,8 @@ stages: pre_delete # delete app tobesearched="/^${appname}\$/p" sfound=$(cf apps | sed -e 1,3d | cut -d " " -f 1 | sed -ne "${tobesearched}") if [[ -z "$sfound" ]]; then log_info "--- nothing to delete" else log_info "--- \\e[32mcf delete\\e[0m" cf delete "$appname" -f -r fi post_delete } Loading Loading @@ -768,7 +756,7 @@ stages: if [[ "${notnull}" == "true" ]]; then desc_field_error="${2} should not be null: creation aborted" if [[ -n "$desc_field_error" ]]; then log_info "${smsg}${COLOR_RED}KO - skipped${COLOR_NONE} (${COLOR_BLUE}${desc_field_error}${COLOR_NONE})" log_error "${smsg}KO - skipped (${desc_field_error})" manage_services_errors=$((manage_services_errors+1)) return fi Loading Loading @@ -813,12 +801,12 @@ stages: mandatory=("true" "true" "true" "false" "false") fvalues=("" "" "" "" "") service_desc=$1 smsg="Create service instance ${COLOR_YELLOW}${service_desc}${COLOR_NONE}: " smsg="Create service instance ${service_desc}: " for fi in "${!fields[@]}" do get_desc_field "${service_desc}" "${fields[fi]}" "${mandatory[fi]}" fvalues[fi]=$(echo "${desc_field}" | tr -d '\r' | envsubst) log_info "--- ${fields[fi]}: ${COLOR_YELLOW}${fvalues[fi]}${COLOR_NONE}" log_info "--- ${fields[fi]}: ${fvalues[fi]}" done log_info "${smsg}service definition OK - proceed" tobesearched="/^${fvalues[0]}\$/p" Loading Loading @@ -846,9 +834,9 @@ stages: fi fi rm -f "${argfile}" log_info "${COLOR_GREEN}... created${COLOR_NONE}" log_info "... created" else log_info "${COLOR_BLUE}... service instance \"${fvalues[0]}\" already exist - skipped${COLOR_NONE}" log_warn "... service instance \"${fvalues[0]}\" already exist - skipped" fi } Loading @@ -856,26 +844,26 @@ stages: service_desc=$1 case ${ENV_TYPE} in staging | production) log_info "Delete service instance ${COLOR_YELLOW}${service_desc}${COLOR_NONE}: ignored (env=${ENV_TYPE})" log_info "Delete service instance ${service_desc}: ignored (env=${ENV_TYPE})" ;; *) smsg="Delete service instance ${COLOR_YELLOW}${service_desc}${COLOR_NONE}: " smsg="Delete service instance ${service_desc}: " get_desc_field "${service_desc}" "cfServiceName" "true" if [[ -n "${desc_field_error}" ]]; then log_info "${smsg}${COLOR_RED}KO - skipped${COLOR_NONE} (${COLOR_BLUE}${desc_field_error}${COLOR_NONE})" log_error "${smsg}KO - skipped (${desc_field_error})" manage_services_errors=$((manage_services_errors+1)) return fi name=$(echo "${desc_field}" | tr -d '\r') log_info "${smsg}service definition OK - proceed" log_info "--- cfServiceName: ${COLOR_YELLOW}${name}${COLOR_NONE}" log_info "--- cfServiceName: ${name}" tobesearched="/^${name}\$/p" sfound=$(cf services | sed -e 1,3d | cut -d " " -f 1 | sed -ne "${tobesearched}") if [[ -z "${sfound}" ]]; then log_info "${COLOR_BLUE}.... service instance \"${name}\" does not exist - skipped${COLOR_NONE}" log_warn ".... service instance \"${name}\" does not exist - skipped" else cf delete-service "${name}" -f >/dev/null log_info "${COLOR_GREEN}.... deleted${COLOR_NONE}" log_info ".... deleted" fi ;; esac Loading @@ -892,7 +880,7 @@ stages: service_dir="${CF_SCRIPTS_DIR}" fi log_info "Looking for service descriptor files into: ${service_dir}" service_files=$(ls -1 "${service_dir}"/*.cf-service.json) service_files=$(ls -1 "${service_dir}/*.cf-service.json" 2>/dev/null || echo "") if [[ -z "$service_files" ]] then log_info "No service found to manage, expected files are: \\e[33;1m${service_dir}/*.cf-service.json\\e[0m" Loading @@ -909,6 +897,7 @@ stages: ;; esac done log_info "Manage_services terminated with ${manage_services_errors} errors" fi } Loading @@ -926,7 +915,7 @@ stages: before_script: # forcing en-US locale so we can parse cf commands output if necessary - cf config --locale "en-US" - *cf-scripts - !reference [.cf-scripts] - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}" # Deploy job prototype Loading @@ -951,7 +940,7 @@ stages: variables: ENV_APP_SUFFIX: "-$CI_ENVIRONMENT_SLUG" before_script: - *cf-scripts - !reference [.cf-scripts] - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}" - assert_defined "${ENV_URL:-$CF_URL}" 'Missing required Cloud Foundry url' - assert_defined "${ENV_USER:-$CF_USER}" 'Missing required Cloud Foundry user' Loading @@ -963,7 +952,6 @@ stages: # use $CI_ENVIRONMENT_SLUG for appname to avoid service name constraints (<=50 chars) # use $CI_ENVIRONMENT_SLUG for hostname to avoid constraints (<=63 chars) - manage_services "create" - echo "Manage_services terminated with ${manage_services_errors} errors" - deploy "$ENV_TYPE" "${ENV_ZERODOWNTIME:-false}" "${ENV_APP_NAME:-${CF_BASE_APP_NAME}${ENV_APP_SUFFIX}}" "${ENV_HOST_NAME:-${CF_BASE_APP_NAME}${ENV_APP_SUFFIX}}" "${ENV_DOMAIN:-${CF_DEFAULT_DOMAIN}}" "${ENV_ROUTE_PATH:-${CF_DEFAULT_ROUTE_PATH}}" artifacts: name: "$ENV_TYPE env url or cf logs for $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG" Loading Loading @@ -993,7 +981,7 @@ stages: variables: ENV_APP_SUFFIX: "-$CI_ENVIRONMENT_SLUG" before_script: - *cf-scripts - !reference [.cf-scripts] - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}" - assert_defined "${ENV_URL:-$CF_URL}" 'Missing required Cloud Foundry url' - assert_defined "${ENV_USER:-$CF_USER}" 'Missing required Cloud Foundry user' Loading Loading @@ -1073,7 +1061,7 @@ cf-cleanup-all-review: stage: deploy dependencies: [] before_script: - *cf-scripts - !reference [.cf-scripts] - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}" - assert_defined "${CF_REVIEW_URL:-$CF_URL}" 'Missing required env $CF_REVIEW_URL or $CF_URL' - assert_defined "${CF_REVIEW_USER:-$CF_USER}" 'Missing required env $CF_REVIEW_USER or $CF_USER' Loading test/tests.bats +4 −4 Original line number Diff line number Diff line Loading @@ -15,13 +15,13 @@ function teardown() { echo - } #@test "deploy without manifest should fail" { @test "deploy without manifest should fail" { # WHEN # run deploy integration false acme1 my-acme-host domain.mine run deploy integration false acme1 my-acme-host domain.mine # printf "%s\n" "${lines[@]}" > /tmp/bats.out # THEN # assert_failure #} assert_failure } @test "deploy with readiness check KO should fail" { # GIVEN Loading Loading
templates/gitlab-ci-cf.yml +30 −42 Original line number Diff line number Diff line Loading @@ -36,15 +36,8 @@ workflow: - when: always variables: # Color code for traces COLOR_GREEN: "\e[1;32m" COLOR_RED: "\e[1;31m" COLOR_BLUE: "\e[1;34m" COLOR_NONE: "\e[0m" COLOR_YELLOW: "\e[1;33m" # variabilized tracking image TBC_TRACKING_IMAGE: "$CI_REGISTRY/to-be-continuous/tools/tracking:master" TBC_TRACKING_IMAGE: "registry.gitlab.com/to-be-continuous/tools/tracking:master" # Docker Image with CF CLI tool (can be overridden) CF_CLI_IMAGE: "registry.hub.docker.com/governmentpaas/cf-cli" Loading Loading @@ -480,6 +473,15 @@ stages: appname="$6" fi # find manifest manifestfile=$(ls -1 "$CF_SCRIPTS_DIR/${CF_MANIFEST_BASENAME}-${env}.yml" 2>/dev/null || ls -1 "$CF_SCRIPTS_DIR/${CF_MANIFEST_BASENAME}.yml" 2>/dev/null || echo "") if [[ -z "$manifestfile" ]] then log_error "Manifest not found, lookedup paths are:\n - \\e[33;1m$CF_SCRIPTS_DIR/${CF_MANIFEST_BASENAME}-${env}.yml\\e[0m\n - \\e[33;1m$CF_SCRIPTS_DIR/${CF_MANIFEST_BASENAME}.yml\\e[0m" exit 1 fi export manifestfile log_info "--- \\e[32mdeploy\\e[0m (env: \\e[33;1m${env}\\e[0m)" log_info "--- looking for CF scripts in directory: \\e[33;1m${CF_SCRIPTS_DIR}\\e[0m" Loading @@ -489,15 +491,7 @@ stages: export targetvarfile="$CF_SCRIPTS_DIR/generated-vars.yml" generate_vars_file # find manifest manifestfile=$(ls -1 "$CF_SCRIPTS_DIR/${CF_MANIFEST_BASENAME}-${env}.yml" 2>/dev/null || ls -1 "$CF_SCRIPTS_DIR/${CF_MANIFEST_BASENAME}.yml" 2>/dev/null || echo "") export manifestfile if [[ -z "$manifestfile" ]] then log_info "Manifest not found, lookedup paths are:\n - \\e[33;1m$CF_SCRIPTS_DIR/${CF_MANIFEST_BASENAME}-${env}.yml\\e[0m\n - \\e[33;1m$CF_SCRIPTS_DIR/${CF_MANIFEST_BASENAME}.yml\\e[0m\n - no app to deploy" else push_application fi check_readiness Loading Loading @@ -670,14 +664,8 @@ stages: pre_delete # delete app tobesearched="/^${appname}\$/p" sfound=$(cf apps | sed -e 1,3d | cut -d " " -f 1 | sed -ne "${tobesearched}") if [[ -z "$sfound" ]]; then log_info "--- nothing to delete" else log_info "--- \\e[32mcf delete\\e[0m" cf delete "$appname" -f -r fi post_delete } Loading Loading @@ -768,7 +756,7 @@ stages: if [[ "${notnull}" == "true" ]]; then desc_field_error="${2} should not be null: creation aborted" if [[ -n "$desc_field_error" ]]; then log_info "${smsg}${COLOR_RED}KO - skipped${COLOR_NONE} (${COLOR_BLUE}${desc_field_error}${COLOR_NONE})" log_error "${smsg}KO - skipped (${desc_field_error})" manage_services_errors=$((manage_services_errors+1)) return fi Loading Loading @@ -813,12 +801,12 @@ stages: mandatory=("true" "true" "true" "false" "false") fvalues=("" "" "" "" "") service_desc=$1 smsg="Create service instance ${COLOR_YELLOW}${service_desc}${COLOR_NONE}: " smsg="Create service instance ${service_desc}: " for fi in "${!fields[@]}" do get_desc_field "${service_desc}" "${fields[fi]}" "${mandatory[fi]}" fvalues[fi]=$(echo "${desc_field}" | tr -d '\r' | envsubst) log_info "--- ${fields[fi]}: ${COLOR_YELLOW}${fvalues[fi]}${COLOR_NONE}" log_info "--- ${fields[fi]}: ${fvalues[fi]}" done log_info "${smsg}service definition OK - proceed" tobesearched="/^${fvalues[0]}\$/p" Loading Loading @@ -846,9 +834,9 @@ stages: fi fi rm -f "${argfile}" log_info "${COLOR_GREEN}... created${COLOR_NONE}" log_info "... created" else log_info "${COLOR_BLUE}... service instance \"${fvalues[0]}\" already exist - skipped${COLOR_NONE}" log_warn "... service instance \"${fvalues[0]}\" already exist - skipped" fi } Loading @@ -856,26 +844,26 @@ stages: service_desc=$1 case ${ENV_TYPE} in staging | production) log_info "Delete service instance ${COLOR_YELLOW}${service_desc}${COLOR_NONE}: ignored (env=${ENV_TYPE})" log_info "Delete service instance ${service_desc}: ignored (env=${ENV_TYPE})" ;; *) smsg="Delete service instance ${COLOR_YELLOW}${service_desc}${COLOR_NONE}: " smsg="Delete service instance ${service_desc}: " get_desc_field "${service_desc}" "cfServiceName" "true" if [[ -n "${desc_field_error}" ]]; then log_info "${smsg}${COLOR_RED}KO - skipped${COLOR_NONE} (${COLOR_BLUE}${desc_field_error}${COLOR_NONE})" log_error "${smsg}KO - skipped (${desc_field_error})" manage_services_errors=$((manage_services_errors+1)) return fi name=$(echo "${desc_field}" | tr -d '\r') log_info "${smsg}service definition OK - proceed" log_info "--- cfServiceName: ${COLOR_YELLOW}${name}${COLOR_NONE}" log_info "--- cfServiceName: ${name}" tobesearched="/^${name}\$/p" sfound=$(cf services | sed -e 1,3d | cut -d " " -f 1 | sed -ne "${tobesearched}") if [[ -z "${sfound}" ]]; then log_info "${COLOR_BLUE}.... service instance \"${name}\" does not exist - skipped${COLOR_NONE}" log_warn ".... service instance \"${name}\" does not exist - skipped" else cf delete-service "${name}" -f >/dev/null log_info "${COLOR_GREEN}.... deleted${COLOR_NONE}" log_info ".... deleted" fi ;; esac Loading @@ -892,7 +880,7 @@ stages: service_dir="${CF_SCRIPTS_DIR}" fi log_info "Looking for service descriptor files into: ${service_dir}" service_files=$(ls -1 "${service_dir}"/*.cf-service.json) service_files=$(ls -1 "${service_dir}/*.cf-service.json" 2>/dev/null || echo "") if [[ -z "$service_files" ]] then log_info "No service found to manage, expected files are: \\e[33;1m${service_dir}/*.cf-service.json\\e[0m" Loading @@ -909,6 +897,7 @@ stages: ;; esac done log_info "Manage_services terminated with ${manage_services_errors} errors" fi } Loading @@ -926,7 +915,7 @@ stages: before_script: # forcing en-US locale so we can parse cf commands output if necessary - cf config --locale "en-US" - *cf-scripts - !reference [.cf-scripts] - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}" # Deploy job prototype Loading @@ -951,7 +940,7 @@ stages: variables: ENV_APP_SUFFIX: "-$CI_ENVIRONMENT_SLUG" before_script: - *cf-scripts - !reference [.cf-scripts] - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}" - assert_defined "${ENV_URL:-$CF_URL}" 'Missing required Cloud Foundry url' - assert_defined "${ENV_USER:-$CF_USER}" 'Missing required Cloud Foundry user' Loading @@ -963,7 +952,6 @@ stages: # use $CI_ENVIRONMENT_SLUG for appname to avoid service name constraints (<=50 chars) # use $CI_ENVIRONMENT_SLUG for hostname to avoid constraints (<=63 chars) - manage_services "create" - echo "Manage_services terminated with ${manage_services_errors} errors" - deploy "$ENV_TYPE" "${ENV_ZERODOWNTIME:-false}" "${ENV_APP_NAME:-${CF_BASE_APP_NAME}${ENV_APP_SUFFIX}}" "${ENV_HOST_NAME:-${CF_BASE_APP_NAME}${ENV_APP_SUFFIX}}" "${ENV_DOMAIN:-${CF_DEFAULT_DOMAIN}}" "${ENV_ROUTE_PATH:-${CF_DEFAULT_ROUTE_PATH}}" artifacts: name: "$ENV_TYPE env url or cf logs for $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG" Loading Loading @@ -993,7 +981,7 @@ stages: variables: ENV_APP_SUFFIX: "-$CI_ENVIRONMENT_SLUG" before_script: - *cf-scripts - !reference [.cf-scripts] - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}" - assert_defined "${ENV_URL:-$CF_URL}" 'Missing required Cloud Foundry url' - assert_defined "${ENV_USER:-$CF_USER}" 'Missing required Cloud Foundry user' Loading Loading @@ -1073,7 +1061,7 @@ cf-cleanup-all-review: stage: deploy dependencies: [] before_script: - *cf-scripts - !reference [.cf-scripts] - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}" - assert_defined "${CF_REVIEW_URL:-$CF_URL}" 'Missing required env $CF_REVIEW_URL or $CF_URL' - assert_defined "${CF_REVIEW_USER:-$CF_USER}" 'Missing required env $CF_REVIEW_USER or $CF_USER' Loading
test/tests.bats +4 −4 Original line number Diff line number Diff line Loading @@ -15,13 +15,13 @@ function teardown() { echo - } #@test "deploy without manifest should fail" { @test "deploy without manifest should fail" { # WHEN # run deploy integration false acme1 my-acme-host domain.mine run deploy integration false acme1 my-acme-host domain.mine # printf "%s\n" "${lines[@]}" > /tmp/bats.out # THEN # assert_failure #} assert_failure } @test "deploy with readiness check KO should fail" { # GIVEN Loading