简体   繁体   English

在gitlab CI中运行docker-compose时执行bash脚本

[英]Execute bash script when running docker-compose in gitlab CI

I've got the following .gitlab-ci.yml file: 我有以下.gitlab-ci.yml文件:

image:
  name: docker/compose:1.24.1
  entrypoint: ["/bin/sh","-l","-c"]

services:
  - docker:dind

stages:
  - test
  - deploy

pytest:
  stage: test
  script:
    - cd tests/
    - docker-compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from pytest

which runs the docker-compose.test.yml file, which looks like this: 运行docker-compose.test.yml文件,如下所示:

version: '3'

services:
  pytest:
    build: ..
    command: bash -c "/wait-for-it.sh dynamodb:8000 -- && cd /tests/ && pytest -s"
  dynamodb:
    image: amazon/dynamodb-local
    ports:
      - '8000:8000'
    command: -jar DynamoDBLocal.jar -inMemory -port 8000

In this case, pytest waits for dynamodb to be up and running and then runs the python tests. 在这种情况下, pytest等待dynamodb启动并运行,然后运行python测试。 This works well on my machine. 这在我的机器上运行良好。

However, when Gitlab CI actually runs it, I get the following error: 但是,当Gitlab CI实际运行它时,出现以下错误:

bash: /wait-for-it.sh: Permission denied

How to avoid this issue? 如何避免这个问题? Using chmod -x , file is not found. 使用chmod -x ,找不到文件。

您需要使wait-for-it.sh可执行文件,在Dockerfile添加:

RUN chmod +x /path/to/wait-for-it.sh

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

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