инструмент_gitlab

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
инструмент_gitlab [2024/11/22 13:23]
val [Пример CI с использованием контейнеров]
инструмент_gitlab [2025/03/18 09:14] (current)
val [Пример shell Kubernetes]
Line 31: Line 31:
  
   * [[https://​docs.gitlab.com/​ee/​install/​docker.html#​install-gitlab-using-docker-compose|Install GitLab using Docker Compose]]   * [[https://​docs.gitlab.com/​ee/​install/​docker.html#​install-gitlab-using-docker-compose|Install GitLab using Docker Compose]]
 +  * [[https://​hub.docker.com/​r/​gitlab/​gitlab-ce/​tags/​|gitlab/​gitlab-ce tags (versions)]]
 +
   * [[Технология Docker]]   * [[Технология Docker]]
   * [[Технология Docker#​docker-compose]]   * [[Технология Docker#​docker-compose]]
Line 50: Line 52:
         gitlab_rails['​registry_enabled'​] = true         gitlab_rails['​registry_enabled'​] = true
         gitlab_rails['​registry_host'​] = "​server.corpX.un"​         gitlab_rails['​registry_host'​] = "​server.corpX.un"​
-        ​external_url '​http://​server.corpX.un'​ +        external_url '​https://​server.corpX.un'​ 
-        registry_external_url '​http://​server.corpX.un'​ +        registry_external_url '​https://​server.corpX.un:​5000'​ 
-        gitlab_rails['​registry_port'​] = "​5000"​ +        gitlab_rails['​registry_port'​] = "​5050"​ 
-        registry['​registry_http_addr'​] = "​server.corpX.un:​5000"​ +        registry['​registry_http_addr'​] = "​server.corpX.un:​5050"​
-#        ​external_url '​https://​server.corpX.un'​ +
-       ​registry_external_url '​https://​server.corpX.un:​5000'​ +
-       ​gitlab_rails['​registry_port'​] = "​5050"​ +
-       ​registry['​registry_http_addr'​] = "​server.corpX.un:​5050"​+
     ports:     ports:
-      ​- '​80:​80'​ +      - '​443:​443'​
-#      ​- '​443:​443'​+
       - '​2222:​22'​       - '​2222:​22'​
       - '​5000:​5000'​       - '​5000:​5000'​
Line 73: Line 70:
         max-size: "​2048m"​         max-size: "​2048m"​
 </​code><​code>​ </​code><​code>​
-# ### cat /​etc/​gitlab/​ssl/​gitlab.bmstu.ru.{crt,​key} 
- 
 # docker-compose up -d # docker-compose up -d
  
Line 257: Line 252:
 ===== GitLab Runner ===== ===== GitLab Runner =====
  
 +  * [[https://​stackoverflow.com/​questions/​32933174/​use-gitlab-ci-to-run-tests-locally|Use GitLab CI to run tests locally?]]
 ==== Установка из пакета ==== ==== Установка из пакета ====
  
Line 263: Line 259:
  
 <​code>​ <​code>​
-# wget http://​gate.isp.un/​unix/​Git/​gitlab-runner_amd64.deb+# wget http://​gate.isp.un/​unix/​Git/​gitlab-runner_amd64.deb ​              # Version: 17.3.1-1
  
 ##2 часа## curl -LJO "​https://​gitlab-runner-downloads.s3.amazonaws.com/​latest/​deb/​gitlab-runner_amd64.deb"​ ##2 часа## curl -LJO "​https://​gitlab-runner-downloads.s3.amazonaws.com/​latest/​deb/​gitlab-runner_amd64.deb"​
Line 282: Line 278:
 Enter tags for the runner: dhcptest, dhcpdeploy Enter tags for the runner: dhcptest, dhcpdeploy
   или   или
-Enter tags for the runner: openvpn1deploy+Enter tags for the runner: openvpn1deploy ​  или ​    ​ansible
 ... ...
 Enter an executor: shell Enter an executor: shell
Line 295: Line 291:
  
 или по инструкции в "New instance runner"​ или по инструкции в "New instance runner"​
 +<​code>​ 
 +# gitlab-runner register -n --executor "​shell"​ -u http://​server.corpX.un -t "​NNNNNNNNNNNNNNNNNNNNNNNNNNNN"​ 
 +</​code>​
 Перезапускать не нужно Перезапускать не нужно
  
Line 347: Line 345:
   --non-interactive \   --non-interactive \
   --url "​http://​server.corpX.un/"​ \   --url "​http://​server.corpX.un/"​ \
-  --registration-token "​NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN"​ \+  --token "​NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN"​ \
   --executor "​docker"​ \   --executor "​docker"​ \
   --docker-image "​docker:​stable"​ \   --docker-image "​docker:​stable"​ \
Line 364: Line 362:
 docker run --rm -v /​srv/​gitlab-runner/​config:/​etc/​gitlab-runner gitlab/​gitlab-runner register \ docker run --rm -v /​srv/​gitlab-runner/​config:/​etc/​gitlab-runner gitlab/​gitlab-runner register \
 ... ...
-  --url "​https://​server.corp20.un/" \+  --url "​https://​server.corpX.un/" \
   --tls-ca-file "/​etc/​gitlab-runner/​wild.crt"​ \   --tls-ca-file "/​etc/​gitlab-runner/​wild.crt"​ \
 ... ...
Line 420: Line 418:
 Build -> Pipeline editor -> Configure Pipelines Build -> Pipeline editor -> Configure Pipelines
 </​code><​code>​ </​code><​code>​
 +stages:
 +  - deploy
 +
 deploy_test:​ deploy_test:​
   stage: deploy   stage: deploy
Line 426: Line 427:
   tags:   tags:
     - openvpn1deploy     - openvpn1deploy
 +#    - ansible
   only:   only:
     - test     - test
Line 435: Line 437:
   tags:   tags:
     - openvpn1deploy     - openvpn1deploy
 +#    - ansible
   only:   only:
 #    - master #    - master
Line 534: Line 537:
 ==== Пример shell Kubernetes ==== ==== Пример shell Kubernetes ====
  
 +<​code>​
 +kube1:​~/​gowebd-k8s#​ cat .gitlab-ci.yml
 +</​code><​code>​
 +stages:
 +  - deploy
 +
 +#variables:
 +#  HELM_NAMESPACE:​ "​my-ns"​
 +
 +trigger-deploy:​
 +  stage: deploy
 +  rules:
 +    - if: '​$CI_PIPELINE_SOURCE == "​pipeline"​ && $VER'
 +  script:
 +    - env
 +    - envsubst < my-webd-deployment-env.yaml | kubectl apply -f - -n my-ns
 +#    - helm upgrade -i my-webd webd-chart/ --set=image.tag=$VER --create-namespace
 +  tags:
 +    - k8s-deploy
 +
 +manual-deploy:​
 +  stage: deploy
 +  when: manual
 +  variables:
 +    VER: "​$MY_WEBD_VER" ​ # New Pipeline or Settings->​CI/​CD->​Variables
 +  script:
 +    - env
 +    - envsubst < my-webd-deployment-env.yaml | kubectl apply -f - -n my-ns
 +#    - helm upgrade -i my-webd webd-chart/ --set=image.tag=$VER --create-namespace
 +  tags:
 +    - k8s-deploy
 +</​code>​
 +
 +== старый вариант ==
 <​code>​ <​code>​
 gitlab-runner@server:​~/​webd$ cp my-webd-deployment.yaml my-webd-deployment-env.yaml gitlab-runner@server:​~/​webd$ cp my-webd-deployment.yaml my-webd-deployment-env.yaml
Line 584: Line 621:
 </​code><​code>​ </​code><​code>​
 stages: stages:
 +#  - lint
   - build   - build
 #  - test #  - test
Line 619: Line 657:
     - docker push $CI_REGISTRY_IMAGE:​$CI_COMMIT_SHA     - docker push $CI_REGISTRY_IMAGE:​$CI_COMMIT_SHA
  
-#    - echo "​{\"​auths\":​{\"​${CI_REGISTRY}\":​{\"​auth\":​\"​$(printf "​%s:​%s"​ "​${CI_REGISTRY_USER}"​ "​${CI_REGISTRY_PASSWORD}" | base64 | tr -d '​\n'​)\"​},​\"​$CI_DEPENDENCY_PROXY_SERVER\":​{\"​auth\":​\"​$(printf "​%s:​%s"​ ${CI_DEPENDENCY_PROXY_USER} "​${CI_DEPENDENCY_PROXY_PASSWORD}" | base64 | tr -d '​\n'​)\"​}}}"​ > /​kaniko/​.docker/​config.json+#    - echo "​{\"​auths\":​{\"​${CI_REGISTRY}\":​{\"​auth\":​\"​$(printf "​%s:​%s"​ "​${CI_REGISTRY_USER}"​ "​${CI_REGISTRY_PASSWORD}"​ | base64 | tr -d '​\n'​)\"​}}}"​ > /​kaniko/​.docker/​config.json
 #    - /​kaniko/​executor #    - /​kaniko/​executor
 #      --insecure --skip-tls-verify #      --insecure --skip-tls-verify
Line 625: Line 663:
 #      --dockerfile "​${CI_PROJECT_DIR}/​Dockerfile"​ #      --dockerfile "​${CI_PROJECT_DIR}/​Dockerfile"​
 #      --destination "​${CI_REGISTRY_IMAGE}:​${CI_COMMIT_SHA}"​ #      --destination "​${CI_REGISTRY_IMAGE}:​${CI_COMMIT_SHA}"​
 +
 +#  except:
 +#    - tags
 +#  tags:
 +#    - build
  
 Push latest: Push latest:
Line 642: Line 685:
 #    - crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY #    - crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
 #    - crane --insecure cp $CI_REGISTRY_IMAGE:​$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:​latest #    - crane --insecure cp $CI_REGISTRY_IMAGE:​$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:​latest
 +#  tags:
 +#    - build
  
 Push tag: Push tag:
Line 659: Line 704:
 #   - crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY #   - crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
 #   - crane --insecure cp $CI_REGISTRY_IMAGE:​$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:​$CI_COMMIT_REF_NAME #   - crane --insecure cp $CI_REGISTRY_IMAGE:​$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:​$CI_COMMIT_REF_NAME
 +#  tags:
 +#    - build
 +
 +### Not work in DooD
 +#Lint test:
 +#  stage: lint
 +#  script:
 +#    - pwd
 +#    - docker run --rm -v $(pwd):/app -w /app golangci/​golangci-lint:​v1.62.2 golangci-lint run --timeout=10m
 +#  except:
 +#    - tags
  
 #Smoke test: #Smoke test:
Line 665: Line 721:
 #    - MY_ID=$(docker run -d --rm $CI_REGISTRY_IMAGE:​$CI_COMMIT_SHA) #    - MY_ID=$(docker run -d --rm $CI_REGISTRY_IMAGE:​$CI_COMMIT_SHA)
 #    - MY_IP=$(docker inspect -f '​{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}'​ $MY_ID) #    - MY_IP=$(docker inspect -f '​{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}'​ $MY_ID)
-#    - wget -qO - $MY_IP+#    - docker run --rm alpine/curl -sS $MY_IP
 #    - docker stop $MY_ID #    - docker stop $MY_ID
 +#  except:
 +#    - tags
 +
  
 #Deploy: #Deploy:
инструмент_gitlab.1732271011.txt.gz · Last modified: 2024/11/22 13:23 by val