|
6 | 6 | Your CircleCI configuration should use a dedicated VM for Testcontainers to work. You can achieve this by specifying the
|
7 | 7 | executor type in your `.circleci/config.yml` to be `machine` instead of the default `docker` executor (see [Choosing an Executor Type](https://circleci.com/docs/executor-intro/) for more info).
|
8 | 8 |
|
9 |
| -Here is a sample CircleCI configuration that does a checkout of a project and runs Maven: |
| 9 | +Here is a sample CircleCI configuration that does a checkout of a project and runs `go test` for a project. Go is installed for the `tests` job using [`gvm`](https://github.com/andrewkroh/gvm), and a workflow matrix has been defined to run the job with different Go versions. Go steps are finally executed from the `go` orb. |
10 | 10 |
|
11 | 11 | ```yml
|
| 12 | +version: 2.1 |
| 13 | + |
| 14 | +orbs: |
| 15 | + |
| 16 | + |
| 17 | +executors: |
| 18 | + machine_executor_amd64: |
| 19 | + machine: |
| 20 | + image: ubuntu-2204:2024.01.2 |
| 21 | + environment: |
| 22 | + architecture: "amd64" |
| 23 | + platform: "linux/amd64" |
| 24 | + |
12 | 25 | jobs:
|
13 |
| - build: |
14 |
| - # Check https://circleci.com/docs/executor-intro#linux-vm for more details |
15 |
| - machine: true |
16 |
| - image: ubuntu-2204:2023.04.2 |
| 26 | + tests: |
| 27 | + executor: machine_executor_amd64 |
| 28 | + parameters: |
| 29 | + go-version: |
| 30 | + type: string |
17 | 31 | steps:
|
18 |
| - # install Go 1.x |
19 |
| - # checkout the project |
20 |
| - - run: go test./... |
| 32 | + - run: |
| 33 | + name: Install GVM |
| 34 | + command: | |
| 35 | + mkdir ~/gvmbin |
| 36 | + curl -sL -o ~/gvmbin/gvm https://github.com/andrewkroh/gvm/releases/download/v0.5.2/gvm-linux-amd64 |
| 37 | + chmod +x ~/gvmbin/gvm |
| 38 | + echo 'export PATH=$PATH:~/gvmbin' >> "$BASH_ENV" |
| 39 | + - run: |
| 40 | + name: Install Go |
| 41 | + command: | |
| 42 | + eval "$(gvm << parameters.go-version >>)" |
| 43 | + echo 'eval "$(gvm << parameters.go-version >>)"' >> "$BASH_ENV" |
| 44 | + go version |
| 45 | + - checkout # checkout source code |
| 46 | + - go/load-cache # Load cached Go modules. |
| 47 | + - go/mod-download # Run 'go mod download'. |
| 48 | + - go/save-cache # Save Go modules to cache. |
| 49 | + - go/test: # Runs 'go test ./...' but includes extensive parameterization for finer tuning. |
| 50 | + covermode: atomic |
| 51 | + failfast: true |
| 52 | + race: true |
| 53 | + |
| 54 | +workflows: |
| 55 | + build-and-test: |
| 56 | + jobs: |
| 57 | + - tests: |
| 58 | + matrix: |
| 59 | + parameters: |
| 60 | + go-version: ["1.21.7", "1.22.3"] |
| 61 | + |
21 | 62 | ```
|
22 | 63 |
|
23 | 64 | You can learn more about the best practices of using Testcontainers together with CircleCI in [this article](https://www.atomicjar.com/2022/12/testcontainers-with-circleci/) for Java.
|
0 commit comments