Skip to content

Commit dddf447

Browse files
authored
Merge branch 'master' into task/containerized-compilation
2 parents d3e3371 + 1b4da1f commit dddf447

File tree

21 files changed

+3169
-86
lines changed

21 files changed

+3169
-86
lines changed

.github/workflows/publish-coverage.yaml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@ jobs:
1010
test:
1111
name: Run tests and collect coverage
1212
runs-on: ubuntu-latest
13+
services:
14+
docker:
15+
image: docker:dind
16+
options: >-
17+
--privileged
18+
--health-cmd="docker ps"
19+
--health-interval=10s
20+
--health-timeout=5s
21+
--health-retries=5
22+
rabbitmq:
23+
image: rabbitmq:3.13-management
24+
ports:
25+
- 5672:5672
26+
- 15672:15672
27+
options: >-
28+
--health-cmd="rabbitmq-diagnostics -q ping"
29+
--health-interval=10s
30+
--health-timeout=5s
31+
--health-retries=5
1332
steps:
1433
- name: Checkout
1534
uses: actions/checkout@v4
@@ -19,15 +38,27 @@ jobs:
1938
- name: Set up Go
2039
uses: actions/setup-go@v5
2140
with:
22-
go-version: "1.23"
41+
go-version: "1.24"
2342

2443
- name: Install dependencies
2544
run: go mod download
2645

27-
- name: Run tests
28-
run: go test -coverprofile=coverage.txt ./...
46+
- name: Run unit tests with coverage
47+
run: go test -coverprofile=coverage-unit.txt -covermode=atomic ./...
48+
49+
- name: Run integration tests with coverage
50+
env:
51+
DOCKER_HOST: unix:///var/run/docker.sock
52+
run: go test -tags=integration -coverprofile=coverage-integration.txt -covermode=atomic ./...
53+
54+
- name: Merge coverage reports
55+
run: |
56+
go install github.com/wadey/gocovmerge@latest
57+
gocovmerge coverage-unit.txt coverage-integration.txt > coverage.txt
2958
3059
- name: Upload results to Codecov
3160
uses: codecov/codecov-action@v5
3261
with:
3362
token: ${{ secrets.CODECOV_TOKEN }}
63+
files: ./coverage.txt
64+
fail_ci_if_error: true

cmd/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ func main() {
4141
workerChannel := rabbitmq.NewRabbitMQChannel(conn)
4242

4343
// Initialize the services
44-
storage := storage.NewStorage(config.StorageBaseUrl)
45-
packager := packager.NewPackager(storage)
44+
storageService := storage.NewStorage(config.StorageBaseUrl)
45+
fileCache := storage.NewFileCache(config.CacheDirPath)
46+
if err := fileCache.InitCache(); err != nil {
47+
logger.Fatalf("Failed to initialize file cache: %v", err)
48+
}
49+
packager := packager.NewPackager(storageService, fileCache)
4650
executor := executor.NewExecutor(dCli)
4751
verifier := verifier.NewVerifier(config.VerifierFlags)
4852
responder := responder.NewResponder(workerChannel, config.PublishChanSize)

generate_mocks.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ INTERFACES=(
1818
"internal/storage Storage"
1919
"internal/pipeline Worker"
2020
"internal/docker DockerClient"
21+
"internal/storage FileCache"
2122
)
2223

2324

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/joho/godotenv v1.5.1
1010
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
1111
github.com/rabbitmq/amqp091-go v1.10.0
12+
github.com/stretchr/testify v1.10.0
1213
go.uber.org/mock v0.6.0
1314
go.uber.org/zap v1.27.0
1415
gopkg.in/natefinch/lumberjack.v2 v2.2.1
@@ -17,6 +18,7 @@ require (
1718
require (
1819
github.com/Microsoft/go-winio v0.4.14 // indirect
1920
github.com/containerd/log v0.1.0 // indirect
21+
github.com/davecgh/go-spew v1.1.1 // indirect
2022
github.com/distribution/reference v0.6.0 // indirect
2123
github.com/docker/go-connections v0.5.0 // indirect
2224
github.com/docker/go-units v0.5.0 // indirect
@@ -31,6 +33,7 @@ require (
3133
github.com/opencontainers/go-digest v1.0.0 // indirect
3234
github.com/opencontainers/image-spec v1.1.1 // indirect
3335
github.com/pkg/errors v0.9.1 // indirect
36+
github.com/pmezard/go-difflib v1.0.0 // indirect
3437
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
3538
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 // indirect
3639
go.opentelemetry.io/otel v1.35.0 // indirect
@@ -40,5 +43,6 @@ require (
4043
go.uber.org/multierr v1.11.0 // indirect
4144
golang.org/x/sys v0.31.0 // indirect
4245
golang.org/x/time v0.11.0 // indirect
46+
gopkg.in/yaml.v3 v3.0.1 // indirect
4347
gotest.tools/v3 v3.5.2 // indirect
4448
)

go.sum

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:C
3838
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
3939
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
4040
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
41+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
42+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
43+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
44+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
4145
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
4246
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
4347
github.com/moby/sys/atomicwriter v0.1.0 h1:kw5D/EqkBwsBFi0ss9v1VG3wIkVhzGvLklJ+w3A14Sw=
@@ -59,6 +63,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
5963
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
6064
github.com/rabbitmq/amqp091-go v1.10.0 h1:STpn5XsHlHGcecLmMFCtg7mqq0RnD+zFr4uzukfVhBw=
6165
github.com/rabbitmq/amqp091-go v1.10.0/go.mod h1:Hy4jKW5kQART1u+JkDTF9YYOQUHXqMuhrgxOEeS7G4o=
66+
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
67+
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
6268
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
6369
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
6470
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
@@ -139,6 +145,9 @@ google.golang.org/grpc v1.71.0 h1:kF77BGdPTQ4/JZWMlb9VpJ5pa25aqvVqogsxNHHdeBg=
139145
google.golang.org/grpc v1.71.0/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec=
140146
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
141147
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
148+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
149+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
150+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
142151
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
143152
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
144153
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

internal/config/worker_config.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Config struct {
1919
ConsumeQueueName string
2020
MaxWorkers int
2121
VerifierFlags []string
22+
CacheDirPath string
2223
}
2324

2425
func NewConfig() *Config {
@@ -43,6 +44,7 @@ func NewConfig() *Config {
4344
storageBaseUrl := storageConfig()
4445
workerQueueName, maxWorkers := workerConfig()
4546
verifierFlagsStr := verifierConfig()
47+
cacheDirPath := cacheConfig()
4648

4749
return &Config{
4850
RabbitMQURL: rabbitmqURL,
@@ -51,6 +53,7 @@ func NewConfig() *Config {
5153
ConsumeQueueName: workerQueueName,
5254
MaxWorkers: maxWorkers,
5355
VerifierFlags: verifierFlagsStr,
56+
CacheDirPath: cacheDirPath,
5457
}
5558
}
5659

@@ -157,3 +160,15 @@ func verifierConfig() []string {
157160

158161
return strings.Split(verifierFlagsStr, ",")
159162
}
163+
164+
func cacheConfig() string {
165+
logger := logger.NewNamedLogger("config")
166+
167+
cacheDirPath := os.Getenv("CACHE_DIR_PATH")
168+
if cacheDirPath == "" {
169+
cacheDirPath = constants.CacheDirPath
170+
logger.Warnf("CACHE_DIR_PATH is not set, using default value %s", constants.CacheDirPath)
171+
}
172+
173+
return cacheDirPath
174+
}

internal/config/worker_config_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ func TestVerifierConfig_DefaultsAndCustom(t *testing.T) {
9191
}
9292
}
9393

94+
func TestCacheConfig_DefaultsAndCustom(t *testing.T) {
95+
config := NewConfig()
96+
if config.CacheDirPath != constants.CacheDirPath {
97+
t.Fatalf("expected default cache dir path %q, got %q", constants.CacheDirPath, config.CacheDirPath)
98+
}
99+
100+
t.Setenv("CACHE_DIR_PATH", "/custom/cache/path")
101+
config2 := NewConfig()
102+
if config2.CacheDirPath != "/custom/cache/path" {
103+
t.Fatalf("expected cache dir path %q, got %q", "/custom/cache/path", config2.CacheDirPath)
104+
}
105+
}
106+
94107
func TestNewConfig_PicksUpValues(t *testing.T) {
95108
// set a variety of envs and ensure NewConfig reads them
96109
t.Setenv("RABBITMQ_HOST", "xhost")
@@ -104,6 +117,7 @@ func TestNewConfig_PicksUpValues(t *testing.T) {
104117
t.Setenv("MAX_WORKERS", "5")
105118
t.Setenv("JOBS_DATA_VOLUME", "vol-1")
106119
t.Setenv("VERIFIER_FLAGS", "-a,-b")
120+
t.Setenv("CACHE_DIR_PATH", "/test/cache")
107121

108122
cfg := NewConfig()
109123
if cfg.RabbitMQURL == "" {
@@ -122,6 +136,9 @@ func TestNewConfig_PicksUpValues(t *testing.T) {
122136
if len(cfg.VerifierFlags) != 2 || cfg.VerifierFlags[0] != "-a" || cfg.VerifierFlags[1] != "-b" {
123137
t.Fatalf("unexpected VerifierFlags: %v", cfg.VerifierFlags)
124138
}
139+
if cfg.CacheDirPath != "/test/cache" {
140+
t.Fatalf("unexpected CacheDirPath: %s", cfg.CacheDirPath)
141+
}
125142
// ensure publish chan size parsed
126143
if cfg.PublishChanSize != 4 {
127144
t.Fatalf("unexpected PublishChanSize: %d", cfg.PublishChanSize)

0 commit comments

Comments
 (0)