build:
variables:
GIT_CHECKOUT: "true"
tags:
- k8s
image: maven:3.6.3-jdk-8
stage: build
extends: .build
rules:
- when: on_success
after_script:
- ls target/
test:
before_script:
- ls target/
tags:
- k8s
image: maven:3.6.3-jdk-8
stage: test
extends: .test
rules:
- when: on_success
after_script:
- ls target/
code_analysis:
tags:
- k8s
image: sonarsource/sonar-scanner-cli:latest
stage: parallel01
script:
- ls target/
- echo $CI_MERGE_REQUEST_IID $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
- "sonar-scanner -Dsonar.projectKey=${CI_PROJECT_NAME} \
-Dsonar.projectName=${CI_PROJECT_NAME} \
-Dsonar.projectVersion=${CI_COMMIT_REF_NAME} \
-Dsonar.ws.timeout=30 \
-Dsonar.projectDescription=${CI_PROJECT_TITLE} \
-Dsonar.links.homepage=${CI_PROJECT_URL} \
-Dsonar.sources=${SCAN_DIR} \
-Dsonar.sourceEncoding=UTF-8 \
-Dsonar.java.binaries=target/classes \
-Dsonar.java.test.binaries=target/test-classes \
-Dsonar.java.surefire.report=target/surefire-reports \
-Dsonar.host.url=http://192.168.1.200:30090 \
-Dsonar.login=ee2bcb37deeb6dfe3a07fe08fb529559b00c1b7b \
-Dsonar.branch.name=${CI_COMMIT_REF_NAME}"
build_image:
before_script:
- ls target/
tags:
- k8s
image: docker:latest
services:
- name: docker:dind
stage: parallel01
extends: .build-docker
faq
$ docker build -t ${IMAGE_NAME} -f ${DOCKER_FILE_PATH} .
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
time="2020-05-12T01:41:07Z" level=error msg="failed to dial gRPC: cannot connect to the Docker daemon. Is 'docker daemon' running on this host?: dial unix /var/run/docker.sock: connect: no such file or directory"
runner配置
# add build cache
cat >>/home/gitlab-runner/.gitlab-runner/config.toml <<EOF
[[runners.kubernetes.volumes.pvc]]
name = "{{.Values.cibuild.cache.pvcName}}"
mount_path = "{{.Values.cibuild.cache.mountPath}}"
[[runners.kubernetes.volumes.pvc]]
name = "{{.Values.cibuild.builds.pvcName}}"
mount_path = "{{.Values.cibuild.builds.mountPath}}"
[[runners.kubernetes.volumes.host_path]]
name = "docker"
mount_path = "/var/run/docker.sock"
EOF
deploy_k8s:
image: lucj/kubectl:1.17.2
tags:
- k8s
- kubernetes-runner
stage: deploy
script:
- kubectl config set-cluster my-cluster --server=${KUBE_URL} --certificate-authority="${KUBE_CA_PEM_FILE}"
- kubectl config set-credentials admin --token=${KUBE_TOKEN}
- sed -i "s#__namespace__#${NAMESPACE}#g" deployment.yaml
- sed -i "s#__appname__#${APP_NAME}#g" deployment.yaml
- sed -i "s#__containerport__#${CONTAINER_PORT}#g" deployment.yaml
- sed -i "s#__nodeport__#${NODE_PORT}#g" deployment.yaml
- sed -i "s#__imagename__#${IMAGE_NAME}#g" deployment.yaml
- cat deployment.yaml
- kubectl apply -f deployment.yaml
environment:
name: $ENV_NAME
url: $ENV_URL
interfact_test:
inherit:
variables: false
stage: interface_test
extends: .interfacetest