不知道如何填写这个yml文件

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

我有一个 Flask auth 应用程序的代码,我必须通过本地声纳库(我做了)运行它,并且必须通过 gitlab 管道运行。它应该有4个阶段:构建,测试,sast和部署,事情是在课堂上他们只向我们展示了一个带有maven命令的yml,这是在pyhton中,所以我不知道如何填充它,几乎一直在这样做周末,我唯一能做的就是构建阶段。测试阶段是空白的,所以它总是会通过(如果你能帮助我,我会很感激),但我现在最大的问题是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

我认为问题是在第一个阶段,我放错了图像,而且命令也是错误的,但如果你能帮助我完成这三个阶段,我会幸福地哭泣

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.