简体   繁体   English

通过 Docker、bash 将 CDK 部署到 AWS 时:cdk: command not found

[英]When Deploying CDK to AWS via Docker, bash: cdk: command not found

Present are two files, Dockerfile.infra and docker-compose-infra.yml .目前有两个文件, Dockerfile.infra和 docker docker-compose-infra.yml Firstly, docker-compose-infra.yml is built via the following command:首先,通过以下命令构建docker-compose-infra.yml

docker-compose --file docker-compose-infra.yml build

This results in no errors and finishes as expected.这不会导致错误并按预期完成。

The problem arises when trying to deploy this to AWS.尝试将其部署到 AWS 时出现问题。 The following command:以下命令:

docker-compose --file docker-compose-infra.yml run cdk

Produces this error:产生此错误:

bash: cdk: command not found

This appears to be triggered when the docker-compose-infra.yml attempts to run the cdk deploy bash command.这似乎是在docker-compose-infra.yml尝试运行cdk deploy bash 命令时触发的。

The command should run because within the Dockerfile.infra build, cdk is installed via npm install -g aws-cdk-lib .该命令应该运行,因为在Dockerfile.infra构建中,cdk 是通过npm install -g aws-cdk-lib

Dockerfile.infra file: Dockerfile.infra 文件:

FROM node:16-slim

ENV DEBIAN_FRONTEND=noninteractive

RUN npm install -g aws-cdk-lib  \
    && apt-get update -y \
    && apt-get upgrade -y \
    && apt-get install -y --no-install-recommends \
    # install Python
    python3-pip \
    # install Poetry via curl
    curl \
    && curl -k https://install.python-poetry.org | python3 - \
    && apt-get remove curl -y \
    && apt-get autoremove -y \
    && rm -rf /var/lib/apt/lists/*

COPY pyproject.toml poetry.lock /
ENV PATH=/root/.local/bin:$PATH
RUN poetry config virtualenvs.create false \
    && poetry install --no-dev

WORKDIR /app/
COPY app.py cdk.json cdk.context.json /app/
COPY stacks/ /app/stacks/

docker-compose-infra.yml: docker-compose-infra.yml:

version: "3"
    services:
      cdk:
        command: bash -c "cdk deploy --require-approval never --all --parameters my-app-${ENVIRONMENT}-service:MyServiceImageTag=${IMAGE_TAG}"
        build:
          context: ./
          dockerfile: Dockerfile.infra
        environment:
          - AWS_PROFILE=${AWS_PROFILE}
          - ENVIRONMENT=${ENVIRONMENT}
          - DEPLOY_ACCOUNT=${DEPLOY_ACCOUNT}
        volumes:
          - ~/.aws/credentials:/root/.aws/credentials

You need to install aws-cdk not aws-cdk-lib您需要安装aws-cdk而不是aws-cdk-lib

RUN npm install -g aws-cdk \

This might be a bit confusing because aws-cdk-lib is also the name of the required Python dependency when writing Python CDK apps and a valid npm package.这可能有点令人困惑,因为aws-cdk-lib也是编写 Python CDK 应用程序有效的 npm package 时所需的 Python 依赖项的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM