【问题标题】:AWS - Python - Flask: Building failsAWS - Python - Flask:构建失败
【发布时间】:2020-07-03 05:09:00
【问题描述】:

当我尝试安装 jq 时,我的构建过程总是失败。你能告诉我我做错了什么吗?

env:
  parameter-store:
    JWT_SECRET: JWT_SECRET

phases:
  install:
    runtime-versions:
      python: 3.8
    commands:
      - curl -sS -o aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.14.6/2019-08-22/bin/linux/amd64/aws-iam-authenticator
      - curl -sS -o kubectl https://amazon-eks.s3-us-west-2.amazonaws.com/1.14.6/2019-08-22/bin/linux/amd64/kubectl
      - chmod +x ./kubectl ./aws-iam-authenticator
      - export PATH=$PWD/:$PATH
      - apt-get update && apt-get -y install jq
      - apt-get -y install python3-pip python3-dev
      - pip3 install --upgrade awscli
      - pip3 install -r requirements.txt
      # - pip3 install -r requirements.txt
      - python3 -m pytest test_main.py
  pre_build:
      commands:
        - TAG="$REPOSITORY_NAME.$REPOSITORY_BRANCH.$ENVIRONMENT_NAME.$(date +%Y-%m-%d.%H.%M.%S).$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | head -c 8)"
        - sed -i 's@CONTAINER_IMAGE@'"$REPOSITORY_URI:$TAG"'@' simple_jwt_api.yml
        - $(aws ecr get-login --no-include-email)
        - export KUBECONFIG=$HOME/.kube/config
  build:
    commands:
      - docker build --tag $REPOSITORY_URI:$TAG .

  post_build:
    commands:
      - docker push $REPOSITORY_URI:$TAG
      - CREDENTIALS=$(aws sts assume-role --role-arn $EKS_KUBECTL_ROLE_ARN --role-session-name codebuild-kubectl --duration-seconds 900)
      - export AWS_ACCESS_KEY_ID="$(echo ${CREDENTIALS} | jq -r '.Credentials.AccessKeyId')"
      - export AWS_SECRET_ACCESS_KEY="$(echo ${CREDENTIALS} | jq -r '.Credentials.SecretAccessKey')"
      - export AWS_SESSION_TOKEN="$(echo ${CREDENTIALS} | jq -r '.Credentials.SessionToken')"
      - export AWS_EXPIRATION=$(echo ${CREDENTIALS} | jq -r '.Credentials.Expiration')
      - aws eks update-kubeconfig --name $EKS_CLUSTER_NAME
      - kubectl apply -f simple_jwt_api.yml
      - printf '[{"name":"simple_jwt_api","imageUri":"%s"}]' $REPOSITORY_URI:$TAG > build.json
      - pwd
      - ls
artifacts:
  files: build.json

错误信息:

[容器] 2020/03/22 15:57:14 等待代理 ping

[容器] 2020/03/22 15:57:16 等待DOWNLOAD_SOURCE

[Container] 2020/03/22 15:57:17 Phase is DOWNLOAD_SOURCE

[容器] 2020/03/22 15:57:17 CODEBUILD_SRC_DIR=/codebuild/output/src534423531/src

[Container] 2020/03/22 15:57:17 YAML 位置是/codebuild/output/src534423531/src/buildspec.yml

[Container] 2020/03/22 15:57:17 处理环境变量

[Container] 2020/03/22 15:57:17 解密参数存储环境变量

[Container] 2020/03/22 15:57:17 根据手动选择选择'python'运行时版本'3.8'...

[Container] 2020/03/22 15:57:17 运行命令 echo "Installing Python version 3.8 ..."

正在安装 Python 3.8 版 ...

[容器] 2020/03/22 15:57:17 运行命令 pyenv global $PYTHON_38_VERSION

[Container] 2020/03/22 15:57:17 移动到目录/codebuild/output/src534423531/src

[Container] 2020/03/22 15:57:17 注册代理

[Container] 2020/03/22 15:57:17 在 YAML 中发现的阶段:4

[容器] 2020/03/22 15:57:17 POST_BUILD: 11 个命令

[容器] 2020/03/22 15:57:17 INSTALL: 9 个命令

[容器] 2020/03/22 15:57:17 PRE_BUILD: 4 个命令

[容器] 2020/03/22 15:57:17 BUILD: 1 个命令

[容器] 2020/03/22 15:57:17 阶段完成:DOWNLOAD_SOURCE 状态:SUCCEEDED

[容器] 2020/03/22 15:57:17 阶段上下文状态码:消息:

[Container] 2020/03/22 15:57:17 进入INSTALL阶段

[容器] 2020/03/22 15:57:17 运行命令 curl -sS -o aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.14.6/2019-08-22/bin/linux/amd64/aws-iam-authenticator

[容器] 2020/03/22 15:57:19 运行命令 curl -sS -o kubectl https://amazon-eks.s3-us-west-2.amazonaws.com/1.14.6/2019-08-22/bin/linux/amd64/kubectl [容器] 2020/03/22 15:57:19 运行命令 chmod +x ./kubectl ./aws-iam-authenticator

[容器] 2020/03/22 15:57:19 运行命令export PATH=$PWD/:$PATH

[容器] 2020/03/22 15:57:19 运行命令 apt-get update && apt-get -y install jq

/codebuild/output/tmp/script.sh:第 4 行:apt-get:找不到命令

[Container] 2020/03/22 15:57:19 命令没有成功退出 apt-get update && apt-get -y install jq exit status 127

[容器] 2020/03/22 15:57:19 阶段完成:安装状态:失败

[容器] 2

【问题讨论】:

    标签: amazon-web-services aws-codebuild


    【解决方案1】:

    从这一行可以清楚地看出问题:

    /codebuild/output/tmp/script.sh: line 4: apt-get: command not found
    

    请使用将提供 Python 3.8 和“apt-get”命令的 Ubuntu 3.0/4.0 映像。在 Amazon Linux 映像中,使用“yum”命令。

    https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html

    【讨论】:

      猜你喜欢
      • 2021-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-25
      • 2023-01-31
      相关资源
      最近更新 更多