Skip to content

Commit 97e265b

Browse files
authored
Modify Harbor testing to make more reliable (DataDog#21106)
* Add option to specify container to check logs from and to wait for health when running docker compose up * Add changelog * Fix tests and cover * Modify Harbor testing to make more reliable * Mark redis as healthy dependency for 2.0.5
1 parent 8bd3485 commit 97e265b

7 files changed

Lines changed: 396 additions & 318 deletions

File tree

harbor/tests/compose/harbor-1.10.0/config/nginx/nginx.conf

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ http {
2323
server core:8080;
2424
}
2525

26-
upstream portal {
27-
server portal:8080;
28-
}
29-
26+
# The following upstream block is for the Harbor Portal (UI), which has been disabled for this integration's tests.
27+
# upstream portal {
28+
# server portal:8080;
29+
# }
30+
3031
log_format timed_combined '$remote_addr - '
3132
'"$request" $status $body_bytes_sent '
3233
'"$http_referer" "$http_user_agent" '
@@ -43,41 +44,42 @@ http {
4344
# SSL
4445
ssl_certificate /etc/cert/server.crt;
4546
ssl_certificate_key /etc/cert/server.key;
46-
47+
4748
# Recommendations from https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
4849
ssl_protocols TLSv1.2;
4950
ssl_ciphers '!aNULL:kECDH+AESGCM:ECDH+AESGCM:RSA+AESGCM:kECDH+AES:ECDH+AES:RSA+AES:';
5051
ssl_prefer_server_ciphers on;
5152
ssl_session_cache shared:SSL:10m;
52-
53+
5354
# disable any limits to avoid HTTP 413 for large image uploads
5455
client_max_body_size 0;
55-
56+
5657
# required to avoid HTTP 411: see Issue #1486 (https://github.com/docker/docker/issues/1486)
5758
chunked_transfer_encoding on;
5859

5960
# Add extra headers
6061
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload";
6162
add_header X-Frame-Options DENY;
6263
add_header Content-Security-Policy "frame-ancestors 'none'";
63-
64+
6465
# costumized location config file can place to /etc/nginx dir with prefix harbor.https. and suffix .conf
6566
include /etc/nginx/conf.d/harbor.https.*.conf;
6667

67-
location / {
68-
proxy_pass http://portal/;
69-
proxy_set_header Host $http_host;
70-
proxy_set_header X-Real-IP $remote_addr;
71-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
72-
73-
# When setting up Harbor behind other proxy, such as an Nginx instance, remove the below line if the proxy already has similar settings.
74-
proxy_set_header X-Forwarded-Proto $scheme;
75-
76-
proxy_cookie_path / "/; HttpOnly; Secure";
77-
78-
proxy_buffering off;
79-
proxy_request_buffering off;
80-
}
68+
# The following location block is for the Harbor Portal (UI), which has been disabled for this integration's tests.
69+
# location / {
70+
# proxy_pass http://portal/;
71+
# proxy_set_header Host $host;
72+
# proxy_set_header X-Real-IP $remote_addr;
73+
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
74+
#
75+
# # When setting up Harbor behind other proxy, such as an Nginx instance, remove the below line if the proxy already has similar settings.
76+
# proxy_set_header X-Forwarded-Proto $scheme;
77+
#
78+
# proxy_cookie_path / "/; Secure";
79+
#
80+
# proxy_buffering off;
81+
# proxy_request_buffering off;
82+
# }
8183

8284
location /c/ {
8385
proxy_pass http://core/c/;
@@ -93,7 +95,7 @@ http {
9395
proxy_buffering off;
9496
proxy_request_buffering off;
9597
}
96-
98+
9799
location /api/ {
98100
proxy_pass http://core/api/;
99101
proxy_set_header Host $host;
@@ -104,7 +106,7 @@ http {
104106
proxy_set_header X-Forwarded-Proto $scheme;
105107

106108
proxy_cookie_path / "/; Secure";
107-
109+
108110
proxy_buffering off;
109111
proxy_request_buffering off;
110112
}
@@ -119,7 +121,7 @@ http {
119121
proxy_set_header X-Forwarded-Proto $scheme;
120122

121123
proxy_cookie_path / "/; Secure";
122-
124+
123125
proxy_buffering off;
124126
proxy_request_buffering off;
125127
}
@@ -133,7 +135,7 @@ http {
133135
proxy_set_header Host $http_host;
134136
proxy_set_header X-Real-IP $remote_addr;
135137
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
136-
138+
137139
# When setting up Harbor behind other proxy, such as an Nginx instance, remove the below line if the proxy already has similar settings.
138140
proxy_set_header X-Forwarded-Proto $scheme;
139141
proxy_buffering off;
@@ -145,7 +147,7 @@ http {
145147
proxy_set_header Host $http_host;
146148
proxy_set_header X-Real-IP $remote_addr;
147149
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
148-
150+
149151
# When setting up Harbor behind other proxy, such as an Nginx instance, remove the below line if the proxy already has similar settings.
150152
proxy_set_header X-Forwarded-Proto $scheme;
151153

@@ -163,5 +165,5 @@ http {
163165
listen 8080;
164166
#server_name harbordomain.com;
165167
return 308 https://$host$request_uri;
166-
}
168+
}
167169
}

harbor/tests/compose/harbor-1.10.0/docker-compose.yml

Lines changed: 101 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,24 @@ services:
1515
networks:
1616
- harbor-110
1717
dns_search: .
18-
registryctl:
19-
image: goharbor/harbor-registryctl:v1.10.11
20-
container_name: registryctl
21-
env_file:
22-
- ./config/registryctl/env
23-
restart: always
24-
cap_drop:
25-
- ALL
26-
cap_add:
27-
- CHOWN
28-
- SETGID
29-
- SETUID
30-
volumes:
31-
- ./config/registryctl/config.yml:/etc/registryctl/config.yml
32-
networks:
33-
- harbor-110
34-
dns_search: .
18+
# The following service is not essential for the integration tests and has been commented out to improve stability and startup time.
19+
# registryctl:
20+
# image: goharbor/harbor-registryctl:v1.10.11
21+
# container_name: registryctl
22+
# env_file:
23+
# - ./config/registryctl/env
24+
# restart: always
25+
# cap_drop:
26+
# - ALL
27+
# cap_add:
28+
# - CHOWN
29+
# - SETGID
30+
# - SETUID
31+
# volumes:
32+
# - ./config/registryctl/config.yml:/etc/registryctl/config.yml
33+
# networks:
34+
# - harbor-110
35+
# dns_search: .
3536
postgresql:
3637
image: goharbor/harbor-db:v1.10.11
3738
container_name: harbor-db
@@ -48,6 +49,11 @@ services:
4849
dns_search: .
4950
env_file:
5051
- ./config/db/env
52+
healthcheck:
53+
test: ["CMD-SHELL", "pg_isready -U postgres"]
54+
interval: 10s
55+
timeout: 5s
56+
retries: 5
5157
core:
5258
image: goharbor/harbor-core:v1.10.11
5359
container_name: harbor-core
@@ -76,45 +82,51 @@ services:
7682
- harbor-core
7783
dns_search: .
7884
depends_on:
79-
- registry
80-
- redis
81-
- postgresql
82-
portal:
83-
image: goharbor/harbor-portal:v1.10.11
84-
container_name: harbor-portal
85-
restart: always
86-
cap_drop:
87-
- ALL
88-
cap_add:
89-
- CHOWN
90-
- SETGID
91-
- SETUID
92-
- NET_BIND_SERVICE
93-
networks:
94-
- harbor-110
95-
dns_search: .
96-
97-
jobservice:
98-
image: goharbor/harbor-jobservice:v1.10.11
99-
container_name: harbor-jobservice
100-
env_file:
101-
- ./config/jobservice/env
102-
restart: always
103-
cap_drop:
104-
- ALL
105-
cap_add:
106-
- CHOWN
107-
- SETGID
108-
- SETUID
109-
volumes:
110-
- type: bind
111-
source: ./config/jobservice/config.yml
112-
target: /etc/jobservice/config.yml
113-
networks:
114-
- harbor-110
115-
dns_search: .
116-
depends_on:
117-
- core
85+
registry:
86+
condition: service_started
87+
redis:
88+
condition: service_healthy
89+
postgresql:
90+
condition: service_healthy
91+
healthcheck:
92+
test: ["CMD-SHELL", "curl -sf http://127.0.0.1:8080/api/systeminfo -o /dev/null"]
93+
interval: 10s
94+
timeout: 5s
95+
retries: 5
96+
# The following services are not essential for the integration tests and have been commented out to improve stability and startup time.
97+
# portal:
98+
# image: goharbor/harbor-portal:v1.10.11
99+
# container_name: harbor-portal
100+
# user: root
101+
# restart: always
102+
# networks:
103+
# - harbor-110
104+
# dns_search: .
105+
# depends_on:
106+
# core:
107+
# condition: service_healthy
108+
# jobservice:
109+
# image: goharbor/harbor-jobservice:v1.10.11
110+
# container_name: harbor-jobservice
111+
# env_file:
112+
# - ./config/jobservice/env
113+
# restart: always
114+
# cap_drop:
115+
# - ALL
116+
# cap_add:
117+
# - CHOWN
118+
# - SETGID
119+
# - SETUID
120+
# volumes:
121+
# - type: bind
122+
# source: ./config/jobservice/config.yml
123+
# target: /etc/jobservice/config.yml
124+
# networks:
125+
# - harbor-110
126+
# dns_search: .
127+
# depends_on:
128+
# core:
129+
# condition: service_healthy
118130
redis:
119131
image: goharbor/redis-photon:v1.10.11
120132
container_name: redis
@@ -131,6 +143,11 @@ services:
131143
aliases:
132144
- redis
133145
dns_search: .
146+
healthcheck:
147+
test: ["CMD", "redis-cli", "ping"]
148+
interval: 10s
149+
timeout: 5s
150+
retries: 5
134151
proxy:
135152
image: goharbor/nginx-photon:v1.10.11
136153
container_name: nginx
@@ -152,27 +169,34 @@ services:
152169
- 80:8080
153170
- 443:8443
154171
depends_on:
155-
- registry
156-
- core
157-
- portal
158-
chartmuseum:
159-
container_name: chartmuseum
160-
image: goharbor/chartmuseum-photon:v1.10.11
161-
restart: always
162-
cap_drop:
163-
- ALL
164-
cap_add:
165-
- CHOWN
166-
- DAC_OVERRIDE
167-
- SETGID
168-
- SETUID
169-
networks:
170-
- harbor-chartmuseum-110
171-
dns_search: .
172-
volumes:
173-
- ./config/chartserver:/etc/chartserver:z
174-
env_file:
175-
./config/chartserver/env
172+
registry:
173+
condition: service_started
174+
core:
175+
condition: service_healthy
176+
healthcheck:
177+
test: ["CMD-SHELL", "curl -sf http://core:8080/api/systeminfo -o /dev/null"]
178+
interval: 10s
179+
timeout: 5s
180+
retries: 5
181+
# The following service is not essential for the integration tests and has been commented out to improve stability and startup time.
182+
# chartmuseum:
183+
# container_name: chartmuseum
184+
# image: goharbor/chartmuseum-photon:v1.10.11
185+
# restart: always
186+
# cap_drop:
187+
# - ALL
188+
# cap_add:
189+
# - CHOWN
190+
# - DAC_OVERRIDE
191+
# - SETGID
192+
# - SETUID
193+
# networks:
194+
# - harbor-chartmuseum-110
195+
# dns_search: .
196+
# volumes:
197+
# - ./config/chartserver:/etc/chartserver:z
198+
# env_file:
199+
# ./config/chartserver/env
176200
networks:
177201
harbor-110:
178202
external: false

0 commit comments

Comments
 (0)