如何填写这个YML文件?

问题描述 投票:0回答:1

我有一个 Flask 身份验证应用程序的代码,我必须通过本地 SonarQube 运行它(我就是这么做的),并且必须通过 gitlab 管道运行。它应该有四个阶段:构建、测试、SAST 和部署。但是,只向我展示了如何使用 Apache Maven 命令执行 YML,而我当前的问题是在 Python 中,所以我不确定如何填写它。我几乎整个周末都在这样做,我唯一能做的就是构建阶段。测试阶段是空白的,所以总是会通过,但我现在最大的问题是 SAST 阶段。

这是我的 YML 文件:

stages:
  - build
  - test
  - sast
  - deploy

variables:
  SONAR_TOKEN: "squ_1b804d297730d729fd6b7f90f019b33fdb2c2afe"
  SONAR_HOST_URL: "http://sonarqube:9000"  # Update with your SonarQube server URL

# image: gitlab/dind

# services:
#   - docker:dind

# before_script:
#   # - python -V
#   - pip install -r requirements.txt

build:
  stage: build
  image: python:3.8-slim-buster
  script:
    - apt-get update -q -y
    - apt-get install -y python-pip
    - python -V
    - echo "hello world"
    - pip install -r requirements.txt

test:
  stage: test
  script:
    - echo "Running tests"



sonarqube-check:
  stage: sast
  image: python:3.8-slim-buster
  cache:
    paths:
      - .sonar/cache
  script:
    - echo "SONAR_ORGANIZATION ${SONAR_ORGANIZATION}"
    - echo "CI_PROJECT_NAME ${CI_PROJECT_NAME}"
    - echo "SONAR_HOST_URL ${SONAR_HOST_URL}"
    - docker run --rm --network gitlab-network -e SONAR_HOST_URL="http://sonarqube:9000/" -e SONAR_LOGIN="squ_1b804d297730d729fd6b7f90f019b33fdb2c2afe" -v "./:/usr/src" sonarsource/sonar-scanner-cli

deploy:
  stage: deploy
  script:
    - echo "Deploying with Docker Compose"
    - docker-compose up -d


这是它给我的错误:

$ docker run --rm --network gitlab-network -e SONAR_HOST_URL="http://sonarqube:9000/" -e SONAR_LOGIN="squ_1b804d297730d729fd6b7f90f019b33fdb2c2afe" -v "./:/usr/src" sonarsource/sonar-scanner-cli
/bin/bash: line 153: docker: command not found
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

我认为问题出在SAST阶段。我可能放错了图像,而且命令也错误。谁能帮我完成这三个阶段吗?

sonarqube gitlab-ci gitlab-ci-runner sast
1个回答
0
投票

我同意czende的观点。看来 docker 命令在您在该阶段运行的容器上不可用。这需要你在 docker 设置中有一个 docker。如果您想使用它,另一种方法是使用 ngrok 将本地声纳实例公开到互联网。我已将课程中的这一章免费提供,因此您可以查看其工作原理:udemy.com/course/domina-sonarqube。虽然是西班牙语,但你可能会说西班牙语

© www.soinside.com 2019 - 2024. All rights reserved.