File tree Expand file tree Collapse file tree
apps/dokploy/__test__/compose/domain
packages/server/src/utils/docker Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -139,6 +139,55 @@ describe("addDomainToCompose enabled filtering", () => {
139139 } ,
140140 ) ;
141141
142+ it . each ( [
143+ [
144+ "docker-compose" ,
145+ `services:
146+ legacy:
147+ image: frigate
148+ labels:
149+ - traefik.http.routers.test-app-1-web.rule=Host(\`frigate.example.com\`)
150+ - traefik.http.services.test-app-1-web.loadbalancer.server.port=8971
151+ - custom.label=preserved
152+ frigate:
153+ image: frigate
154+ ` ,
155+ ] ,
156+ [
157+ "stack" ,
158+ `services:
159+ legacy:
160+ image: frigate
161+ deploy:
162+ labels:
163+ - traefik.http.routers.test-app-1-web.rule=Host(\`frigate.example.com\`)
164+ - traefik.http.services.test-app-1-web.loadbalancer.server.port=8971
165+ - custom.label=preserved
166+ frigate:
167+ image: frigate
168+ ` ,
169+ ] ,
170+ ] as const ) (
171+ "removes stale labels from the previous %s service after reassignment" ,
172+ async ( composeType , staleComposeYaml ) => {
173+ composeYaml = staleComposeYaml ;
174+
175+ const result = await addDomainToCompose ( { ...baseCompose , composeType } , [
176+ { ...baseDomain , serviceName : "frigate" , enabled : false } ,
177+ ] ) ;
178+
179+ const previousService = result ?. services ?. legacy ;
180+ const labels =
181+ composeType === "docker-compose"
182+ ? previousService ?. labels
183+ : previousService ?. deploy ?. labels ;
184+ expect ( labels ) . toContain ( "custom.label=preserved" ) ;
185+ expect (
186+ ( labels as string [ ] ) . some ( ( label ) => label . includes ( "test-app-1" ) ) ,
187+ ) . toBe ( false ) ;
188+ } ,
189+ ) ;
190+
142191 it . each ( [
143192 [
144193 "docker-compose" ,
Original file line number Diff line number Diff line change @@ -224,24 +224,21 @@ export const addDomainToCompose = async (
224224 result = randomized ;
225225 }
226226
227- for ( const domain of domains . filter ( ( d ) => ! d . enabled ) ) {
228- if ( ! domain . serviceName ) continue ;
229-
230- const service = result . services ?. [ domain . serviceName ] ;
231- if ( ! service ) continue ;
232-
233- if ( compose . composeType === "docker-compose" ) {
234- service . labels = removeDomainLabels (
235- service . labels ,
236- appName ,
237- domain . uniqueConfigKey ,
238- ) ;
239- } else if ( service . deploy ) {
240- service . deploy . labels = removeDomainLabels (
241- service . deploy . labels ,
242- appName ,
243- domain . uniqueConfigKey ,
244- ) ;
227+ for ( const domain of domains ) {
228+ for ( const service of Object . values ( result . services ?? { } ) ) {
229+ if ( compose . composeType === "docker-compose" ) {
230+ service . labels = removeDomainLabels (
231+ service . labels ,
232+ appName ,
233+ domain . uniqueConfigKey ,
234+ ) ;
235+ } else if ( service . deploy ) {
236+ service . deploy . labels = removeDomainLabels (
237+ service . deploy . labels ,
238+ appName ,
239+ domain . uniqueConfigKey ,
240+ ) ;
241+ }
245242 }
246243 }
247244
You can’t perform that action at this time.
0 commit comments