Shell 错误:本地不存在应用程序版本。将war工件上载到aws beanstalk环境时出错

Shell 错误:本地不存在应用程序版本。将war工件上载到aws beanstalk环境时出错,shell,amazon-web-services,amazon-elastic-beanstalk,ebcli,Shell,Amazon Web Services,Amazon Elastic Beanstalk,Ebcli,将war文件上载到暂存环境时遇到错误。 已经编写了一个shell脚本,它使用eb-cli将工件部署到环境中 config.yml如下所示: branch-defaults: default: environment: testseries-stag-env deploy: artifact: temp/servercp/testseries/testseries-service/target/testseries-service-1.0.0.war environment-def

将war文件上载到暂存环境时遇到错误。 已经编写了一个shell脚本,它使用eb-cli将工件部署到环境中

config.yml如下所示:

branch-defaults:
  default:
    environment: testseries-stag-env
deploy:
  artifact: temp/servercp/testseries/testseries-service/target/testseries-service-1.0.0.war
environment-defaults:
  testseries-stag-env:
    branch: null
    repository: null
global:
  application_name: testseries
  default_ec2_keyname: testseries-stag
  default_platform: arn:aws:elasticbeanstalk:us-east-1::platform/Tomcat 8 with Java
    8 running on 64bit Amazon Linux/2.7.5
  default_region: us-east-1
  instance_profile: null
  platform_name: null
  platform_version: null
  profile: null
  sc: null
  workspace_type: Application
#!/usr/bin/env bash

# Takes a fresh clone of the dependent repositories and installs them locally.
# Deploys test-series to staging env. See .elasticbeanstalk for more details on this
# Access key Id and secret must be configured in the system to use this shell script
# If you have key and secret with you but system is not configured with it, this script will do it for you. You will
# need to provide the values when requested

# This may contain system dependent bugs. Please report any to devops@adda247.com

timestamp() {
  date +"%d-%h_%H:%M:%S"
}

function installHomeBrew()
{
   /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
}

function installEbCliMac()
{
    brew install awsebcli
}

function installEbCliLinux()
{
    pip install --upgrade --user awsebcli
}

function installPip()
{
    curl -O https://bootstrap.pypa.io/get-pip.py
    if [[ -x $(command -v python) ]]; then
        echo "Python found"
        python get-pip.py --user
    else
        if [[ -x $(command -v python3) ]]; then
            echo "Python3 found"
            python3 get-pip.py --user
        else
#           Only valid for nix instances which support python3. Fails on other systems
            echo "Python not found. Installing..."
            sudo apt-get install python3
            python3 get-pip.py --user
        fi
    fi
    echo "Installing pip with python"
    pip install --upgrade --user pip
}

function installAWSCLI()
{
    if [[ ${OSTYPE} == 'linux-gnu' ]]; then
        pip install awscli --upgrade --user
    elif [[ ${OSTYPE} == 'darwin'* ]]; then
        brew install awscli
    fi
}

function ifEnvVariablesExist()
{
    if [[  -z ${AWS_ACCESS_KEY_ID} || -z ${AWS_SECRET_ACCESS_KEY} ]]; then
        echo false
    else
        echo true
    fi
}

function ifConfigExists()
{
    if [[ -e ${HOME}/.aws/credentials ]]; then
        echo true
    else
        echo false
    fi
}

function deployWar()
{
    version_label=testseries-dev-$(timestamp)
    eb deploy --label=${version_label}
}

function credentialsExist()
{
    env_var=$(ifEnvVariablesExist)
    if [[ ${env_var} == true ]]; then
        echo "reading from environment variables"
    else
        config_file=$(ifConfigExists)
        if [[ ${config_file} == true ]]; then
            echo "reading from config file"
        else
            echo "Neither environment variables nor config file found"
            echo "******   Configuring AWS for you. Please enter aws id and secret when prompted  ******"
            aws_exists=$(command -v aws)
            if [[ -x ${aws_exists} ]]; then
                echo "aws cli is present. Configuring"
            else
                echo "aws cli is absent. Installing"
                installAWSCLI
            fi
            aws configure
            if [[ $? -ne 0 ]]; then
                echo "Unsuccessful configuration. Exiting"
                exit $?
            fi
        fi
    fi
}

function proceedForMac()
{
    eb_cli_exists=$(command -v eb)
    if [[ -x ${eb_cli_exists} ]]; then
        echo "eb cli is present"
    else
        echo "eb cli is absent. Installing with HomeBrew"
        brew_exists=$(command -v brew)
        if [[ -x ${brew_exists} ]]; then
            echo "HomeBrew is present"
        else
            echo "HomeBrew is absent. Installing"
            installHomeBrew
        fi
        installEbCliMac
    fi

    credentialsExist
    deployWar
}

function proceedForLinux()
{
    eb_cli_exists=$(command -v eb)
    if [[ -x ${eb_cli_exists} ]]; then
        echo "eb cli is present"
    else
        echo "eb cli is absent. Installing with pip"
        pip_exists=$(command -v pip)
        if [[ -x ${pip_exists} ]]; then
            echo "pip is present"
        else
            echo "pip is absent. Installing"
            installPip
        fi
        export PATH=~/.local/bin:$PATH
        if [ -f ~/.bash_profile ]; then
            source ~/.bash_profile
        fi
        installEbCliLinux
    fi

    credentialsExist
    deployWar
}

WD=$(pwd)
BUILD_DIR=$(pwd)/temp

if [[ -d ${BUILD_DIR} ]]; then
    rm -rf ${BUILD_DIR}
fi

mkdir ${BUILD_DIR}
chmod 777 ${BUILD_DIR}

cd ${BUILD_DIR}
SSH_KEY_PATH=~/.ssh/id_rsa.pub

if [[ -f ${SSH_KEY_PATH} ]]; then
    git clone git@github.com:metiseduventures/servercp.git
else
    git clone https://github.com/metiseduventures/servercp.git
fi


echo "Building servercp"
cd ${BUILD_DIR}/servercp/testseries
git checkout dev
mvn clean install
if [[ $? -ne 0 ]]; then
    echo "Project build unsuccessful. Please correct testseries project in servercp and run again"
    exit $?
fi

echo "Build Successful. Deploying Artifact"
if [[ ${OSTYPE} == 'linux-gnu' ]]; then
    proceedForLinux
elif [[ ${OSTYPE} == 'darwin'* ]]; then
    proceedForMac
fi
build.sh如下所示:

branch-defaults:
  default:
    environment: testseries-stag-env
deploy:
  artifact: temp/servercp/testseries/testseries-service/target/testseries-service-1.0.0.war
environment-defaults:
  testseries-stag-env:
    branch: null
    repository: null
global:
  application_name: testseries
  default_ec2_keyname: testseries-stag
  default_platform: arn:aws:elasticbeanstalk:us-east-1::platform/Tomcat 8 with Java
    8 running on 64bit Amazon Linux/2.7.5
  default_region: us-east-1
  instance_profile: null
  platform_name: null
  platform_version: null
  profile: null
  sc: null
  workspace_type: Application
#!/usr/bin/env bash

# Takes a fresh clone of the dependent repositories and installs them locally.
# Deploys test-series to staging env. See .elasticbeanstalk for more details on this
# Access key Id and secret must be configured in the system to use this shell script
# If you have key and secret with you but system is not configured with it, this script will do it for you. You will
# need to provide the values when requested

# This may contain system dependent bugs. Please report any to devops@adda247.com

timestamp() {
  date +"%d-%h_%H:%M:%S"
}

function installHomeBrew()
{
   /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
}

function installEbCliMac()
{
    brew install awsebcli
}

function installEbCliLinux()
{
    pip install --upgrade --user awsebcli
}

function installPip()
{
    curl -O https://bootstrap.pypa.io/get-pip.py
    if [[ -x $(command -v python) ]]; then
        echo "Python found"
        python get-pip.py --user
    else
        if [[ -x $(command -v python3) ]]; then
            echo "Python3 found"
            python3 get-pip.py --user
        else
#           Only valid for nix instances which support python3. Fails on other systems
            echo "Python not found. Installing..."
            sudo apt-get install python3
            python3 get-pip.py --user
        fi
    fi
    echo "Installing pip with python"
    pip install --upgrade --user pip
}

function installAWSCLI()
{
    if [[ ${OSTYPE} == 'linux-gnu' ]]; then
        pip install awscli --upgrade --user
    elif [[ ${OSTYPE} == 'darwin'* ]]; then
        brew install awscli
    fi
}

function ifEnvVariablesExist()
{
    if [[  -z ${AWS_ACCESS_KEY_ID} || -z ${AWS_SECRET_ACCESS_KEY} ]]; then
        echo false
    else
        echo true
    fi
}

function ifConfigExists()
{
    if [[ -e ${HOME}/.aws/credentials ]]; then
        echo true
    else
        echo false
    fi
}

function deployWar()
{
    version_label=testseries-dev-$(timestamp)
    eb deploy --label=${version_label}
}

function credentialsExist()
{
    env_var=$(ifEnvVariablesExist)
    if [[ ${env_var} == true ]]; then
        echo "reading from environment variables"
    else
        config_file=$(ifConfigExists)
        if [[ ${config_file} == true ]]; then
            echo "reading from config file"
        else
            echo "Neither environment variables nor config file found"
            echo "******   Configuring AWS for you. Please enter aws id and secret when prompted  ******"
            aws_exists=$(command -v aws)
            if [[ -x ${aws_exists} ]]; then
                echo "aws cli is present. Configuring"
            else
                echo "aws cli is absent. Installing"
                installAWSCLI
            fi
            aws configure
            if [[ $? -ne 0 ]]; then
                echo "Unsuccessful configuration. Exiting"
                exit $?
            fi
        fi
    fi
}

function proceedForMac()
{
    eb_cli_exists=$(command -v eb)
    if [[ -x ${eb_cli_exists} ]]; then
        echo "eb cli is present"
    else
        echo "eb cli is absent. Installing with HomeBrew"
        brew_exists=$(command -v brew)
        if [[ -x ${brew_exists} ]]; then
            echo "HomeBrew is present"
        else
            echo "HomeBrew is absent. Installing"
            installHomeBrew
        fi
        installEbCliMac
    fi

    credentialsExist
    deployWar
}

function proceedForLinux()
{
    eb_cli_exists=$(command -v eb)
    if [[ -x ${eb_cli_exists} ]]; then
        echo "eb cli is present"
    else
        echo "eb cli is absent. Installing with pip"
        pip_exists=$(command -v pip)
        if [[ -x ${pip_exists} ]]; then
            echo "pip is present"
        else
            echo "pip is absent. Installing"
            installPip
        fi
        export PATH=~/.local/bin:$PATH
        if [ -f ~/.bash_profile ]; then
            source ~/.bash_profile
        fi
        installEbCliLinux
    fi

    credentialsExist
    deployWar
}

WD=$(pwd)
BUILD_DIR=$(pwd)/temp

if [[ -d ${BUILD_DIR} ]]; then
    rm -rf ${BUILD_DIR}
fi

mkdir ${BUILD_DIR}
chmod 777 ${BUILD_DIR}

cd ${BUILD_DIR}
SSH_KEY_PATH=~/.ssh/id_rsa.pub

if [[ -f ${SSH_KEY_PATH} ]]; then
    git clone git@github.com:metiseduventures/servercp.git
else
    git clone https://github.com/metiseduventures/servercp.git
fi


echo "Building servercp"
cd ${BUILD_DIR}/servercp/testseries
git checkout dev
mvn clean install
if [[ $? -ne 0 ]]; then
    echo "Project build unsuccessful. Please correct testseries project in servercp and run again"
    exit $?
fi

echo "Build Successful. Deploying Artifact"
if [[ ${OSTYPE} == 'linux-gnu' ]]; then
    proceedForLinux
elif [[ ${OSTYPE} == 'darwin'* ]]; then
    proceedForMac
fi
eb deploy
命令在
deployWar
函数中失败

文件夹结构是

/--* .elasticbeanstalk/config.yml
   * build.sh
build.sh
shell脚本在temp文件夹中克隆存储库,并构建成功完成的项目

运行后的控制台输出为:

Build Successful. Deploying Artifact
eb cli is present
reading from config file
ERROR: Application Version does not exist locally 
(temp/servercp/testseries/testseries-service/target/testseries-service- 
1.0.0.war). Try uploading the Application Version again.
但是,
temp/servercp/testseries/testseries服务/target/testseries-service-1.0.0.war

如果我在这之后立即运行
ebdeploy--version label=“my label”
,工件就可以正常部署了。但当从脚本内部执行相同的操作时,会出现上述错误。在执行eb deploy命令之前,我试着睡了2秒钟,但还是一无所获


谢谢你的帮助。提前感谢

您的版本是什么。sh的内容是什么?我想您可以在执行真正的部署命令之前给它一个
sleep 2
中断?

我认为问题是由于
eb部署
(无
--label
)发生的位置造成的。使用
cd${BUILD\u DIR}/servercp/testseries
,您就在项目的深处,而
temp/../../*.war
是相对于项目根的路径。我认为在
eb部署之前的
cd${WD}
应该可以解决您的问题。

只是为了确保--
temp/path/to/testseries-service-1.0.0.war
是您计算机上的路径吗?您的“文件夹结构”表示您只有
elasticbeanstalk
build.sh
。是的,脚本将创建与
build.sh
并行的
temp
文件夹,然后克隆repo并生成特定项目。好的,你能上传你的
build.sh
的相关部分吗?它在哪里执行
eb部署
和克隆
temp
?更新的问题包括build.shYeah,我想试试这个。但这仍然不是必需的。让我看看这样行不行。相同错误:/。在eb deploy命令之前,请更新问题以包含build.sh,检查文件是否存在?如果不存在,请在git clone命令之后检查文件是否存在。出了点问题,让我们找出发生的地方,明白了。似乎我要进入项目来构建它,因此部署命令在
testseries
文件夹中执行,而不是从部署脚本的路径执行。我保存了当前目录,并在执行eb deploy之前移动到它。这个上传的不错。