Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: how to to run dockertest in gitlab ci #229

Merged
merged 2 commits into from
Oct 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,49 @@ Sometimes container clean up fails. Check out
```go
resource.Expire(60) // Tell docker to hard kill the container in 60 seconds
```

## Running dockertest in Gitlab CI

### How to run dockertest on shared gitlab runners?

You should add docker dind service to your job which starts in sibling container.
That means database will be available on host `docker`.
You app should be able to change db host through environment variable.

Here is the simple example of `gitlab-ci.yml`:
```yaml
stages:
- test
go-test:
stage: test
image: golang:1.15
services:
- docker:dind
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
YOUR_APP_DB_HOST: docker
script:
- go test ./...
```

Plus in the `pool.Retry` method that checks for connection readiness,
you need to use `$YOUR_APP_DB_HOST` instead of localhost.

### How to run dockertest on group(custom) gitlab runners?

Gitlab runner can be run in docker executor mode to save compatibility with shared runners.
Here is the simple register command:
```shell script
gitlab-runner register -n \
--url https://gitlab.com/ \
--registration-token $YOUR_TOKEN \
--executor docker \
--description "My Docker Runner" \
--docker-image "docker:19.03.12" \
--docker-privileged
```

You only need to instruct docker dind to start with disabled tls.
Add variable `DOCKER_TLS_CERTDIR: ""` to `gitlab-ci.yml` above.
It will tell docker daemon to start on 2375 port over http.