PageRenderTime 26ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/development/index.md

https://gitlab.com/tnir/gitlab-runner
Markdown | 307 lines | 207 code | 100 blank | 0 comment | 0 complexity | 2f27299e108faf203e233bc62532d952 MD5 | raw file
  1. ---
  2. stage: Verify
  3. group: Runner
  4. info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
  5. ---
  6. # Development environment
  7. ## 1. Install dependencies and Go runtime
  8. ### For Debian/Ubuntu
  9. ```shell
  10. sudo apt-get install -y mercurial git-core wget make build-essential
  11. wget https://storage.googleapis.com/golang/go1.17.7.linux-amd64.tar.gz
  12. sudo tar -C /usr/local -xzf go*-*.tar.gz
  13. ```
  14. ### For CentOS
  15. ```shell
  16. sudo yum install mercurial wget make
  17. sudo yum groupinstall 'Development Tools'
  18. wget https://storage.googleapis.com/golang/go1.17.7.linux-amd64.tar.gz
  19. sudo tar -C /usr/local -xzf go*-*.tar.gz
  20. ```
  21. ### For macOS
  22. Using binary package:
  23. ```shell
  24. wget https://storage.googleapis.com/golang/go1.17.7.darwin-amd64.tar.gz
  25. sudo tar -C /usr/local -xzf go*-*.tar.gz
  26. ```
  27. Using installation package:
  28. ```shell
  29. wget https://storage.googleapis.com/golang/go1.17.7.darwin-amd64.pkg
  30. open go*-*.pkg
  31. ```
  32. ### For FreeBSD
  33. ```shell
  34. pkg install go-1.17.7 gmake git mercurial
  35. ```
  36. ## 2. Install Docker Engine
  37. The Docker Engine is required to create pre-built image that is embedded into GitLab Runner and loaded when using Docker executor.
  38. To install Docker, follow the Docker [installation
  39. instructions](https://docs.docker.com/install/) for your OS.
  40. Make sure you have a `binfmt_misc` on the machine that is running your Docker Engine.
  41. This is required for building ARM images that are embedded into the GitLab Runner binary.
  42. - For Debian/Ubuntu it's sufficient to execute:
  43. ```shell
  44. sudo apt-get install binfmt-support qemu-user-static
  45. ```
  46. - For Docker for MacOS/Windows `binfmt_misc` is enabled by default.
  47. - For CoreOS (but also works on Debian and Ubuntu) you need to execute the following script on system start:
  48. ```shell
  49. #!/bin/sh
  50. set -xe
  51. /sbin/modprobe binfmt_misc
  52. mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc
  53. # Support for ARM binaries through Qemu:
  54. { echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:' > /proc/sys/fs/binfmt_misc/register; } 2>/dev/null
  55. { echo ':armeb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-armeb-static:' > /proc/sys/fs/binfmt_misc/register; } 2>/dev/null
  56. { echo ':aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-aarch64-static:CF' > /proc/sys/fs/binfmt_misc/register; } 2>/dev/null
  57. ```
  58. ## 3. Download GitLab Runner sources
  59. ```shell
  60. go get gitlab.com/gitlab-org/gitlab-runner
  61. ```
  62. ## 4. Install GitLab Runner dependencies
  63. After you clone GitLab Runner, `cd` into the `gitlab-runner` directory and download and restore all build dependencies:
  64. ```shell
  65. git clone <gitlab-runner-uri>
  66. cd gitlab-runner
  67. make deps
  68. ```
  69. **For FreeBSD use `gmake deps`**
  70. ## 5. Run GitLab Runner
  71. Normally you would use `gitlab-runner`. In order to compile and run the Go sources, use the Go toolchain:
  72. ```shell
  73. make runner-and-helper-bin-host
  74. ./out/binaries/gitlab-runner run
  75. ```
  76. You can run GitLab Runner in debug-mode:
  77. ```shell
  78. make runner-and-helper-bin-host
  79. ./out/binaries/gitlab-runner --debug run
  80. ```
  81. `make runner-and-helper-bin-host` is a superset of `make runner-bin-host` which in addition
  82. takes care of building the Runner Helper Docker archive dependencies.
  83. ### Building the Docker images
  84. If you want to build the Docker images, run `make runner-and-helper-docker-host`, which will:
  85. 1. Build `gitlab-runner-helper` and create a helper Docker image from it.
  86. 1. Compile GitLab Runner for `linux/amd64`.
  87. 1. Build a DEB package for Runner. The official GitLab Runner images are based on Alpine and Ubuntu,
  88. and the Ubuntu image build uses the DEB package.
  89. 1. Build the Alpine and Ubuntu versions of the `gitlab/gitlab-runner` image.
  90. ## 6. Run test suite locally
  91. GitLab Runner test suite consists of "core" tests and tests for executors.
  92. Tests for executors require certain binaries to be installed on your local
  93. machine. Some of these binaries cannot be installed on all operating
  94. systems. If a binary is not installed tests requiring this binary will be
  95. skipped.
  96. These are the binaries that you can install:
  97. 1. [VirtualBox](https://www.virtualbox.org/wiki/Downloads) and [Vagrant](https://www.vagrantup.com/downloads); the [Vagrant Parallels plugin](https://github.com/Parallels/vagrant-parallels) is also required
  98. 1. [kubectl](https://kubernetes.io/docs/tasks/tools/) with
  99. [minikube](https://github.com/kubernetes/minikube)
  100. 1. [Parallels Pro or Business edition](https://www.parallels.com/products/desktop/)
  101. 1. [PowerShell](https://docs.microsoft.com/en-us/powershell/)
  102. After installing the binaries run:
  103. ```shell
  104. make development_setup
  105. ```
  106. To execute the tests run:
  107. ```shell
  108. make test
  109. ```
  110. ## 7. Run tests with helper image version of choice
  111. If you are developing functionality inside a helper, you'll most likely want to run tests with
  112. the version of the Docker image that contains the newest changes.
  113. If you run tests without passing `-ldflags`, the default version in `version.go` is `development`.
  114. This means that the runner defaults to pulling a [helper image](../configuration/advanced-configuration.md#helper-image)
  115. with the `latest` tag.
  116. ### Make targets
  117. `make` targets inject `-ldflags` automatically. You can run all tests by using:
  118. ```shell
  119. make simple-test
  120. ```
  121. `make` targets also inject `-ldflags` for `parallel_test_execute`, which is most commonly used by the CI/CD jobs.
  122. ### Custom `go test` arguments
  123. In case you want a more customized `go test` command, you can use `print_ldflags` as `make` target:
  124. ```shell
  125. go test -ldflags "$(make print_ldflags)" -run TestDockerCommandBuildCancel -v ./executors/docker/...
  126. ```
  127. ### In GoLand
  128. Currently, GoLand doesn't support dynamic Go tool arguments, so you'll need to run `make print_ldflags` first
  129. and then paste it in the configuration.
  130. NOTE:
  131. To use the debugger, make sure to remove the last two flags (`-s -w`).
  132. ### Helper image
  133. Build the newest version of the helper image with:
  134. ```shell
  135. make helper-dockerarchive-host
  136. ```
  137. Then you'll have the image ready for use:
  138. ```shell
  139. REPOSITORY TAG IMAGE ID CREATED SIZE
  140. gitlab/gitlab-runner-helper x86_64-a6bc0800 f10d9b5bbb41 32 seconds ago 57.2MB
  141. ```
  142. ### Helper image with Kubernetes
  143. If you are running a local Kubernetes cluster make sure to reuse the cluster's Docker daemon to build images.
  144. For example, with minikube:
  145. ```shell
  146. eval $(minikube docker-env)
  147. ```
  148. ## 8. Install optional tools
  149. - Install `golangci-lint`, used for the `make lint` target.
  150. - Install `markdown-lint` and `vale`, used for the `make lint-docs` target.
  151. Installation instructions will pop up when running a Makefile target
  152. if a tool is missing.
  153. ## 9. Contribute
  154. You can start hacking `gitlab-runner` code.
  155. If you need an IDE to edit and debug code, there are a few free suggestions you can use:
  156. - [JetBrains GoLand IDE](https://www.jetbrains.com/go/).
  157. - Visual Studio Code using the
  158. [workspace recommended extensions](https://code.visualstudio.com/docs/editor/extension-marketplace#_workspace-recommended-extensions),
  159. located in `.vscode/extensions.json`.
  160. ## Managing build dependencies
  161. GitLab Runner uses [Go Modules](https://github.com/golang/go/wiki/Modules) to manage
  162. its dependencies.
  163. Don't add dependency from upstream default branch when version tags are available.
  164. ## Tests
  165. The Runner codebase makes a distinction between [unit](https://en.wikipedia.org/wiki/Unit_testing)
  166. and [integration tests](https://en.wikipedia.org/wiki/Integration_testing) in the following way:
  167. - Unit test files have a suffix of `_test.go` and contain the following build directive in the header:
  168. ```golang
  169. // +build !integration
  170. ```
  171. - Integration test files have a suffix of `_integration_test.go` and contain the following build directive in the header:
  172. ```golang
  173. // +build integration
  174. ```
  175. They can be run by adding `-tags=integration` to the `go test` command.
  176. To test the state of the build directives in test files, `make check_test_directives` can be used.
  177. ## Developing for Windows on a non-windows environment
  178. We provide a [Vagrantfile](https://gitlab.com/gitlab-org/gitlab-runner/tree/main/Vagrantfile)
  179. to help you run a Windows Server 2019 or Windows 10 instance, since we
  180. are using [multiple machines](https://www.vagrantup.com/docs/multi-machine) inside of Vagrant.
  181. The following are required:
  182. - [Vagrant](https://www.vagrantup.com) installed.
  183. - [Virtualbox](https://www.virtualbox.org/) installed.
  184. - Around 30GB of free hard disk space on your computer.
  185. Which virtual machine to use depends on your use case:
  186. - The Windows Server machine has Docker pre-installed and should always
  187. be used when you are developing on GitLab Runner for Windows.
  188. - The Windows 10 machine is there for you to have a windows environment
  189. with a GUI which sometimes can help you debugging some Windows
  190. features. Note that you cannot have Docker running inside of Windows
  191. 10 because nested virtualization is not supported.
  192. Running `vagrant up windows_10` will start the Windows 10 machine for
  193. you. To:
  194. - SSH inside of the Windows 10 machine, run `vagrant ssh windows_10`.
  195. - Access the GUI for the Windows 10, you can connect via
  196. RDP by running `vagrant rdp windows_10`, which will connect to the
  197. machine using a locally installed RDP program.
  198. For both machines, the GitLab Runner source code is synced
  199. bi-directionally so that you can edit from your machine with your
  200. favorite editor. The source code can be found under the `$GOROOT`
  201. environment variable. We have a `RUNNER_SRC` environment variable which
  202. you can use to find out the full path so when using PowerShell,
  203. you can use `cd $Env:RUNNER_SRC`.
  204. ## Other resources
  205. 1. [Reviewing GitLab Runner merge requests](reviewing-gitlab-runner.md)
  206. 1. [Add support for new Windows Version](add-windows-version.md)
  207. 1. [Runner Group - Team Resources](https://about.gitlab.com/handbook/engineering/development/ops/verify/runner/team-resources/#overview)