@@ -45,6 +45,15 @@ function requireRepo(value, allowedPrefixes) {
4545}
4646
4747function createDeployService ( { config, store, git, docker, log } ) {
48+ function imageName ( serviceName , shortId ) {
49+ const localName = `self-hosted-devops/${ serviceName } :${ shortId } ` ;
50+ if ( ! config . deploy . imageRegistry ) {
51+ return localName ;
52+ }
53+
54+ return `${ config . deploy . imageRegistry . replace ( / \/ $ / , "" ) } /${ serviceName } :${ shortId } ` ;
55+ }
56+
4857 async function deployService ( payload ) {
4958 const repositoryUrl = requireRepo (
5059 payload . repo || payload . repositoryUrl ,
@@ -58,7 +67,8 @@ function createDeployService({ config, store, git, docker, log }) {
5867 const deploymentId = crypto . randomUUID ( ) ;
5968 const shortId = deploymentId . slice ( 0 , 8 ) ;
6069 const sourcePath = path . join ( config . deploy . workspace , serviceName , shortId ) ;
61- const image = `self-hosted-devops/${ serviceName } :${ shortId } ` ;
70+ const image = imageName ( serviceName , shortId ) ;
71+ const candidateName = `candidate-${ serviceName } -${ shortId } ` ;
6272 const containerName = `deployed-${ serviceName } ` ;
6373
6474 const deployment = await store . insertDeployment ( {
@@ -79,11 +89,39 @@ function createDeployService({ config, store, git, docker, log }) {
7989 await store . updateDeployment ( deployment . id , { status : "building" } ) ;
8090 await docker . buildImage ( image , sourcePath , deployment . id ) ;
8191
92+ if ( config . deploy . pushImages ) {
93+ await store . updateDeployment ( deployment . id , { status : "pushing" } ) ;
94+ await docker . pushImage ( image , deployment . id ) ;
95+ }
96+
97+ await store . updateDeployment ( deployment . id , { status : "validating" } ) ;
98+ await docker . removeContainer ( candidateName , deployment . id ) ;
99+ await docker . runContainer ( {
100+ name : candidateName ,
101+ image,
102+ containerPort,
103+ deploymentId : deployment . id ,
104+ labels : [
105+ "traefik.enable=false" ,
106+ `platform.service=${ serviceName } ` ,
107+ `platform.deployment=${ deployment . id } ` ,
108+ "platform.candidate=true" ,
109+ ] ,
110+ } ) ;
111+ await docker . waitForHttpHealth (
112+ candidateName ,
113+ containerPort ,
114+ payload . healthPath || config . deploy . healthPath ,
115+ config . deploy . healthTimeoutSeconds ,
116+ deployment . id ,
117+ ) ;
118+
82119 await store . updateDeployment ( deployment . id , {
83- status : "replacing " ,
120+ status : "switching " ,
84121 previousContainerName : containerName ,
85122 } ) ;
86123 await docker . removeContainer ( containerName , deployment . id ) ;
124+ await docker . removeContainer ( candidateName , deployment . id ) ;
87125
88126 await docker . runContainer ( {
89127 name : containerName ,
@@ -108,6 +146,7 @@ function createDeployService({ config, store, git, docker, log }) {
108146 error : error . message ,
109147 } ) ;
110148
149+ await docker . removeContainer ( candidateName , deployment . id ) ;
111150 await docker . removeContainer ( containerName , deployment . id ) ;
112151 await store . updateDeployment ( deployment . id , {
113152 status : "failed" ,
0 commit comments