2017-08-30 93 views
0

我正在尝试使用GitLab管道将Docker容器部署到EC2容器服务中。我已经在AWS中创建了群集,并且还运行了2个实例。问题是,一旦执行通过GitLab将Docker容器部署到EC2容器服务时出错管道

​​

命令我收到以下错误:

WARN[0000] Skipping unsupported YAML option for service... option name=build service name=testContainer 
ERRO[0001] Error registering task definition    error="ClientException: Container.image should not be null or empty.\n\tstatus code: 400, request id: 27277917-8d8e-11e7-8cb2-8d5ad96f4568" family=ecscompose-workillence 
ERRO[0001] Create task definition failed     error="ClientException: Container.image should not be null or empty.\n\tstatus code: 400, request id: 27277917-8d8e-11e7-8cb2-8d5ad96f4568" 
FATA[0001] ClientException: Container.image should not be null or empty. 

这是一个截图从我的AWS回购:

enter image description here

图像不似乎不是空的。

这是我的CI文件看起来像:

image: docker:latest 
services: 
    - docker:dind 
stages: 
    - build 
    - deploy 

testBuild: 
    stage: build 
    script: 
    - docker version 
    - docker build -t 084622260700.dkr.ecr.us-east-2.amazonaws.com/testrepo:latest app/ 
    - docker images 
    - docker login -u AWS -p <password> 084622260700.dkr.ecr.us-east-2.amazonaws.com 
    - docker push 084622260700.dkr.ecr.us-east-2.amazonaws.com/testrepo:latest 

testDeploy: 
    stage: deploy 
    image: python:3-alpine 
    variables: 
    AWS_REGION: "us-east-2" 
    AWS_ACCESS_KEY_ID: "key" 
    AWS_SECRET_ACCESS_KEY: "key" 
    PROD_TARGET_GROUP_ARN: "arn:aws:elasticloadbalancing:us-east-2:084622260700:targetgroup/TestTG/af0fbec5b9cc869f" 
    ECS_CLUSTER: "testCluster" 
    AWS_KEY_PAIR: "testKP.pem" 
    AWS_VPC: "vpc-0419416d" 
    AWS_SUBNETS: "subnet-ad6cdfe0,subnet-ad6cdfe0,subnet-0fc1aa74" 
    AWS_INSTANCE_TYPE: "t2.micro" 
    AWS_INSTANCE_COUNT: "2" #Number of instances to scale to 
    AWS_ROLE: "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceRole" 
    before_script: 
##### Install AWS ECS-CLI ##### 
    - apk add --update curl 
    - curl -o /usr/local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest 
    - chmod +x /usr/local/bin/ecs-cli 
    script: 
##### Configure ECS-CLI, run the container and scale to 2 instances ##### 
    - ecs-cli configure --region $AWS_REGION --access-key $AWS_ACCESS_KEY_ID --secret-key $AWS_SECRET_ACCESS_KEY --cluster $ECS_CLUSTER 
    - ecs-cli up --keypair $AWS_KEY_PAIR --capability-iam -c $ECS_CLUSTER --instance-type t2.micro --size 2 --vpc $AWS_VPC --subnets $AWS_SUBNETS --force 
##### This docker-compose.yml is the one described above ##### 
    - ecs-cli compose --file docker-compose.yml service up --target-group-arn $PROD_TARGET_GROUP_ARN --container-name app --container-port 8080 --role $AWS_ROLE 
    - ecs-cli compose --file docker-compose.yml service scale 2 
    environment: 
    name: ci 
##### This is the URL seen under 'DNS name' when the LB was created ##### 
    url: TestLB-1717492587.us-east-2.elb.amazonaws.com 
    only: 
    - aws 

这是撰写文件的样子:

app: 
    image: 084622260700.dkr.ecr.us-east-2.amazonaws.com/testrepo:latest 
    command: yarn run start-dev 
    links: 
     - mongodb 
     - redis 
     - elasticsearch 
    ports: 
     - '8000:8000' 
     - '5858:5858' 
     - '9229:9229' 
     - '80:8080' 
    environment: 
     NODE_ENV: local 
    volumes: 
     - ./testrepo/.:/opt/app 
    mongodb: 
    build: docker/definitions/mongo 
    ports: 
     - "27017:27017" 
    redis: 
    build: docker/definitions/redis 
    ports: 
     - "6379:6379" 
    elasticsearch: 
    build: docker/definitions/elasticsearch 
    ports: 
     - "9200:9200" 
     - "9300:9300" 

你曾经面临相同或相似的问题,可能是如何做你解决了吗?

回答

1

问题很明显。您撰写的文件是构建和没有图像

WARN[0000] Skipping unsupported YAML option for service... option name=build service name=testContainer 
ERRO[0001] Error registering task definition    error="ClientException: Container.image should not be null or empty.\n\tstatus code: 400, request id: 27277917-8d8e-11e7-8cb2-8d5ad96f4568" family=ecscompose-workillence 
ERRO[0001] Create task definition failed     error="ClientException: Container.image should not be null or empty.\n\tstatus code: 400, request id: 27277917-8d8e-11e7-8cb2-8d5ad96f4568" 
FATA[0001] ClientException: Container.image should not be null or empty. 

所以,你需要的是

mongodb: 
    build: docker/definitions/mongo 
    image: <image from aws or docker hub> 
    ports: 
     - "27017:27017" 
    redis: 
    build: docker/definitions/redis 
    image: <image from aws or docker hub> 
    ports: 
     - "6379:6379" 
    elasticsearch: 
    build: docker/definitions/elasticsearch 
    image: <image from aws or docker hub> 
    ports: 
     - "9200:9200" 
     - "9300:9300" 

一旦你添加它应该工作。如果有build值会产生问题,那么您可以使用两个单独的撰写文件。一个带有构建值,另一个带有图像值

+0

我没有猜测那些服务将在此错误中扮演任何角色,我没有描述,但我将使用外部提供程序来执行mongo,redis和elasticsearch。这意味着它们不会在Docker包内部构建,而且我已经在本地测试了环境并且它可以工作,我可以连接它们中的三个。 有什么办法可以在撰写文件中声明它们是外部的吗? –

+0

如果它们是外部的,则将它们从撰写中删除。保留两个组合'-test.yml'和'-prod.yml'。使用'prod'进行AWS部署 –

+0

好的,我测试了它,并再次发生了相同的错误。 我用下面的代码: 'testContainer: 编译:084622260700.dkr.ecr.us-east-2.amazonaws.com/testrepo:latest 命令:丝线行进启动开发 端口: - “8000 :8000' - '5858:5858' - '9229:9229' - '80:8080' 环境: NODE_ENV:本地 卷: - ./testrepo /.:/选择/ app' –

相关问题