【问题标题】:Docker runner on Gitlab CI - Proxy only for specific stageGitlab CI 上的 Docker 运行器 - 仅适用于特定阶段的代理
【发布时间】:2020-11-11 17:25:18
【问题描述】:

对于“部署”阶段,我需要一个代理。但是阶段“测试”从业力测试开始的地方不起作用。有没有办法,我可以定义:使用代理设置阶段“部署”而不是“测试”?

我试图从代理中排除 Karma 正在使用的 IP,但 Ip 每次都在变化。

variables:
      http_proxy: "$CODE_PROXY"
      https_proxy: "$CODE_PROXY"
      no_proxy: "127.0.0.1,localhost"

stages:
  - test
  - deploy


test:
  stage: test
  image: node:erbium
  services:
    - selenium/standalone-chrome:3.141.59
  script:
    - npm ci
    - npm run lint
    - npm run lint:sass
    - npm run lint:editorconfig
    - npm run test -- --progress=false --code-coverage
    - npm run e2e -- --host=$(hostname -i)
    - npm run build:prod -- --progress=false
  coverage: '/Statements\s*:\s*(\d+\.?\d+)\%/'
  artifacts:
    expire_in: 3h
    paths:
      - dist/
    reports:
      junit: dist/reports/app-name/test-*.xml
      cobertura: dist/coverage/app-name/cobertura-coverage.xml
  tags:
    - DOCKER

deploy:
  stage: deploy
  image: python:latest
  script:
  - pip install awscli
  - aws s3 rm s3://$S3_BUCKET_NAME --recursive
  - aws s3 cp ./dist/app-name s3://$S3_BUCKET_NAME/ --recursive
  only:
  - master

【问题讨论】:

    标签: docker continuous-integration gitlab gitlab-ci


    【解决方案1】:

    两种方式

    1. 混合变量
    .proxy-variables: &proxy-variables
          http_proxy: "$CODE_PROXY"
          https_proxy: "$CODE_PROXY"
          no_proxy: "127.0.0.1,localhost"
    
    deploy:
      stage: deploy
      image: python:latest
      variables:
        - *proxy-variables
      script:
        - pip install awscli
        - aws s3 rm s3://$S3_BUCKET_NAME --recursive
        - aws s3 cp ./dist/app-name s3://$S3_BUCKET_NAME/ --recursive
      only:
        - master
    
    
    1. 扩展作业模板
    .proxied-job:
      variables:
          http_proxy: "$CODE_PROXY"
          https_proxy: "$CODE_PROXY"
          no_proxy: "127.0.0.1,localhost"
    
    deploy:
      extends: .proxied-job
      stage: deploy
      image: python:latest
      script:
        - pip install awscli
        - aws s3 rm s3://$S3_BUCKET_NAME --recursive
        - aws s3 cp ./dist/app-name s3://$S3_BUCKET_NAME/ --recursive
      only:
        - master
    
    

    【讨论】:

    • 非常感谢。我像爬虫一样用谷歌搜索,但没有找到类似的东西。您的解决方案正是我所寻找的。​​span>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-06
    • 2021-11-30
    • 1970-01-01
    • 2021-07-31
    • 2019-09-21
    • 1970-01-01
    • 2021-10-29
    相关资源
    最近更新 更多