-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
176 lines (164 loc) · 4.68 KB
/
.gitlab-ci.yml
File metadata and controls
176 lines (164 loc) · 4.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# GitLab CI configuration for go-dcgm
# Uses Docker for building and testing based on the existing Dockerfile
# Define the stages of the pipeline
stages:
- build
- test
# Define global variables
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: "/certs"
# Build arguments for the Dockerfile
CUDA_VERSION: "12.5.1"
DISTRO_FLAVOR: "ubuntu24.04"
GO_VERSION: "1.24.4"
DCGM_VERSION: "4.5.0-1"
# Image names
BUILD_IMAGE: "$CI_REGISTRY_IMAGE/build:$CI_COMMIT_SHA"
TEST_IMAGE: "$CI_REGISTRY_IMAGE/test:$CI_COMMIT_SHA"
# Use Docker-in-Docker service
services:
- docker:dind
# Use Docker image
image: docker:latest
before_script:
- docker info
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
# Build Docker image and compile Go code
build:
stage: build
script:
- echo "Building Docker image with go-dcgm..."
# Build the samples stage which includes the compiled binaries
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
- docker build
--target samples
--build-arg CUDA_VERSION=$CUDA_VERSION
--build-arg DISTRO_FLAVOR=$DISTRO_FLAVOR
--build-arg GO_VERSION=$GO_VERSION
--build-arg DCGM_VERSION=$DCGM_VERSION
--tag $BUILD_IMAGE
.
# Push the built image for use in test stage
- docker push $BUILD_IMAGE
rules:
- if: $CI_COMMIT_BRANCH == "main"
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
# Run tests inside the built Docker container
test:
stage: test
tags:
- docker
- gpu-enabled
image: $BUILD_IMAGE
needs: ["build"]
before_script: []
script:
# Create test reports directory
- mkdir -p test-reports
- echo '=== Installing test dependencies ==='
- go install github.com/jstemmer/go-junit-report/v2@latest
- echo '=== Running Go tests ==='
- mkdir -p test-reports
- >
go test -v ./tests 2>&1
| /root/go/bin/go-junit-report -set-exit-code
> test-reports/go-tests.xml &&
- echo '=== Tests completed successfully! ==='
artifacts:
reports:
junit:
- test-reports/go-tests.xml
paths:
- test-reports/
expire_in: 1 week
when: always
rules:
- if: $CI_COMMIT_BRANCH == "main"
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
# Run race tests inside the built Docker container
test-race:
stage: test
tags:
- docker
- gpu-enabled
image: $BUILD_IMAGE
needs: ["build"]
before_script: []
script:
# Create test reports directory
- mkdir -p test-reports
- echo '=== Installing test dependencies ==='
- go install github.com/jstemmer/go-junit-report/v2@latest
- echo '=== Running Go race tests ==='
- mkdir -p test-reports
- >
go test -race -v ./tests 2>&1
| /root/go/bin/go-junit-report -set-exit-code
> test-reports/go-race-tests.xml
- echo '=== Race Tests completed successfully! ==='
artifacts:
reports:
junit:
- test-reports/go-race-tests.xml
paths:
- test-reports/
expire_in: 1 week
when: always
rules:
- if: $CI_COMMIT_BRANCH == "main"
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
# Code format check inside Docker
format-check:
stage: test
needs: ["build"]
before_script: []
tags:
- docker
- gpu-disabled
image: $BUILD_IMAGE
script:
- echo "Checking code format in Docker container..."
# Install gofumpt
- echo 'Installing gofumpt...'
- go install mvdan.cc/gofumpt@latest
# Run format check
- echo 'Checking code format...'
- make check-format
rules:
- if: $CI_COMMIT_BRANCH == "main"
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
.go:
tags:
- docker
- gpu-disabled
image: golang
# Full linting inside Docker (optional)
lint-full:
extends:
- .go
stage: test
before_script: []
needs: ["build"]
script:
- echo "Running full linting..."
# Install golangci-lint and run full linting
- echo 'Installing golangci-lint...'
- wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s v2.1.6
- echo 'Running full linting...'
- ./bin/golangci-lint run ./... --timeout 10m --fix
rules:
- if: $CI_COMMIT_BRANCH == "main"
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
allow_failure: true
# Build matrix for different configurations (optional)
build-matrix:
stage: build
script:
- echo "Building Docker images with docker-bake for matrix configurations..."
- docker context create go-dcgm
- docker buildx create --use go-dcgm
- docker buildx bake --load
rules:
- if: $CI_COMMIT_BRANCH == "main"
- if: $CI_PIPELINE_SOURCE == "merge_request_event"