簡體   English   中英

在 GitLab-ci Docker build 中執行外部 bash 腳本

[英]Execute external bash script inside GitLab-ci Docker build

我想從 gitlab-ci.yml 執行一個外部(在本地機器上)bash 腳本,它使用 docker:stable 圖像。 我想執行位於 gitlab docker 映像之外的 startup.sh。 這是可能的還是有更好的選擇?

gitlab-ci.yaml

image: docker:stable

#Build script

variables:
  CI_DEBUG_TRACE: "true"
  DOCKER_DRIVER: overlay

before_script:
  - docker --version

build:
  services:
  - docker:dind
  script:
    - docker build --no-cache -t <tag> .
    - docker login -u root -p <pass> <registry>
    - docker tag ...
    - docker push ...
    - echo "build completed"
  stage: build
  tags:
    - <tag>

deploy_staging:
  stage: deploy
  script:
    - ./sh startup.sh

bash 腳本

#!/bin/bash

docker login -u root -p <pass>
docker pull <image>
docker-compose up -d

我不確定這是否是您的用例的最佳實踐,但與圖像共享文件的簡單方法是通過編輯 config.toml 文件添加卷並將此代碼共享到圖像。

將此行添加到 [runners.docker] 下的 config.toml

volumes = ["/cache", startup.sh 的路徑:/root/scripts"]

然后在 your.gilatb.yml

    deploy_staging:
      stage: deploy
      script:
        - chmod +x /root/scripts/startup.sh     
        - ./sh /root/scripts/startup.sh

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM