This repository has been archived by the owner on Nov 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add way to deploy projects from image and image tar file
- Loading branch information
Showing
6 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// npm packages | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// template name | ||
exports.name = 'image'; | ||
|
||
// function to check if the template fits this recipe | ||
exports.checkTemplate = async ({config}) => { | ||
// if project has image field defined in config | ||
try { | ||
return config.image && config.image.length; | ||
} catch (e) { | ||
return false; | ||
} | ||
}; | ||
|
||
// function to execute current template | ||
exports.executeTemplate = async ({config, username, tempDockerDir, folder, resultStream, util, docker}) => { | ||
// build docker image | ||
try { | ||
const {image, imageFile} = config; | ||
util.writeStatus(resultStream, {message: `Deploying project from image: ${image}..`, level: 'info'}); | ||
|
||
// import from tar if needed | ||
if (imageFile && imageFile.length) { | ||
util.writeStatus(resultStream, {message: `Importing image from file: ${imageFile}..`, level: 'info'}); | ||
// get packed stream | ||
const tarStream = fs.createReadStream(path.join(tempDockerDir, folder, imageFile)); | ||
const importRes = await docker.daemon.loadImage(tarStream, {tag: image}); | ||
util.logger.debug('Import result:', importRes); | ||
} | ||
|
||
// start image | ||
const container = await docker.start({image, username, folder, resultStream}); | ||
util.logger.debug(container); | ||
|
||
// return new deployments | ||
util.writeStatus(resultStream, {message: 'Deployment success!', deployments: [container], level: 'info'}); | ||
resultStream.end(''); | ||
} catch (e) { | ||
util.logger.debug('build failed!', e); | ||
util.writeStatus(resultStream, {message: e.error, error: e.error, log: e.log, level: 'error'}); | ||
resultStream.end(''); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM busybox | ||
|
||
CMD ["sleep", "300"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "test-docker-image-deploy", | ||
"hostname": "testimage", | ||
"project": "test-image-project", | ||
"restart": "no", | ||
"image": "exo-test-image", | ||
"imageFile": "image.tar" | ||
} |
Binary file not shown.