@@ -17,6 +17,7 @@ const docker = require('../src/docker/docker');
1717const { initNetwork} = require ( '../src/docker/network' ) ;
1818
1919// create tar streams
20+ const streamDockerImage = tar . pack ( path . join ( __dirname , 'fixtures' , 'docker-image-project' ) ) ;
2021const streamDocker = tar . pack ( path . join ( __dirname , 'fixtures' , 'docker-project' ) ) ;
2122const streamNode = tar . pack ( path . join ( __dirname , 'fixtures' , 'node-project' ) ) ;
2223const streamNodeLock = tar . pack ( path . join ( __dirname , 'fixtures' , 'node-lock-project' ) ) ;
@@ -111,6 +112,52 @@ test('Should deploy simple docker project', async done => {
111112 done ( ) ;
112113} ) ;
113114
115+ test ( 'Should deploy simple project from image and image tar' , async done => {
116+ const options = Object . assign ( optionsBase , {
117+ payload : streamDockerImage ,
118+ } ) ;
119+
120+ const response = await fastify . inject ( options ) ;
121+ // parse result into lines
122+ const result = response . payload
123+ . split ( '\n' )
124+ . filter ( l => l && l . length )
125+ . map ( line => JSON . parse ( line ) ) ;
126+
127+ // find deployments
128+ const completeDeployments = result . find ( it => it . deployments && it . deployments . length ) . deployments ;
129+
130+ // check response
131+ expect ( response . statusCode ) . toEqual ( 200 ) ;
132+ expect ( completeDeployments . length ) . toEqual ( 1 ) ;
133+ expect ( completeDeployments [ 0 ] . Name . startsWith ( '/exo-test-image-' ) ) . toBeTruthy ( ) ;
134+
135+ // check docker services
136+ const allContainers = await docker . listContainers ( ) ;
137+ const containerInfo = allContainers . find ( c => c . Names . includes ( completeDeployments [ 0 ] . Name ) ) ;
138+ const name = completeDeployments [ 0 ] . Name . slice ( 1 ) ;
139+
140+ expect ( containerInfo ) . toBeDefined ( ) ;
141+ expect ( containerInfo . Labels [ 'exoframe.deployment' ] ) . toEqual ( name ) ;
142+ expect ( containerInfo . Labels [ 'exoframe.user' ] ) . toEqual ( 'admin' ) ;
143+ expect ( containerInfo . Labels [ 'exoframe.project' ] ) . toEqual ( 'test-image-project' ) ;
144+ expect ( containerInfo . Labels [ 'traefik.backend' ] ) . toEqual ( `${ name } .test` ) ;
145+ expect ( containerInfo . Labels [ 'traefik.docker.network' ] ) . toEqual ( 'exoframe' ) ;
146+ expect ( containerInfo . Labels [ 'traefik.enable' ] ) . toEqual ( 'true' ) ;
147+ expect ( containerInfo . NetworkSettings . Networks . exoframe ) . toBeDefined ( ) ;
148+
149+ const containerData = docker . getContainer ( containerInfo . Id ) ;
150+ const container = await containerData . inspect ( ) ;
151+ expect ( container . NetworkSettings . Networks . exoframe . Aliases . includes ( 'testimage' ) ) . toBeTruthy ( ) ;
152+ expect ( container . HostConfig . RestartPolicy ) . toMatchObject ( { Name : 'no' , MaximumRetryCount : 0 } ) ;
153+
154+ // cleanup
155+ const instance = docker . getContainer ( containerInfo . Id ) ;
156+ await instance . remove ( { force : true } ) ;
157+
158+ done ( ) ;
159+ } ) ;
160+
114161test ( 'Should deploy simple node project' , async done => {
115162 const options = Object . assign ( optionsBase , {
116163 payload : streamNode ,
0 commit comments