@flownet/lib-to-docker
v0.3.15
Published
The **@flownet/lib-to-docker** project provides a straightforward approach for transforming your Node.js applications into Docker images. It automates the process of rendering template files and setting up the necessary project structure to produce Docker
Downloads
633
Readme
@flownet/lib-to-docker
The @flownet/lib-to-docker project provides a straightforward approach for transforming your Node.js applications into Docker images. It automates the process of rendering template files and setting up the necessary project structure to produce Docker-compatible outputs.
How It Works
@flownet/lib-to-docker streamlines the conversion of your project resources into a Docker image through a few key steps:
- Template Rendering: It utilizes specified template directories to render configuration files, informing Docker's build process.
- File Management: It ensures that all necessary project files are placed correctly within output directories in preparation for Docker image creation.
- Docker Image Creation: It automates the Docker build process using a build script, producing a Docker image ready for deployment.
Key Features
- Automated Directory Setup: Creates and organizes necessary directories for output and packaging.
- Template Integration: Renders Docker configuration files from templates, ensuring customizability and reuse.
- File Handling: Manages project files, including handling content, decoding base64, and copying files, to prepare them for the Docker image.
- Docker Build Automation: Simplifies the Docker image creation process through automated builds using shell scripts.
Conclusion
The @flownet/lib-to-docker project offers a simplistic yet effective solution to package Node.js applications into Docker images efficiently. It simplifies the often complex preparatory steps required for Dockerization, focusing on seamless integration and ease of use.
Developer Guide for @flownet/lib-to-docker
Overview
@flownet/lib-to-docker is a Node.js library designed to assist developers in creating Docker images from application source directories. Its core functionality includes setting up a Docker build by managing necessary files, rendering templates, and executing Docker commands. This library facilitates easy integration of Docker build processes into existing projects, streamlining the setup for efficient containerization.
Installation
To include @flownet/lib-to-docker in your project, you can install it using npm or yarn. It automatically handles any external dependencies, so you don't need to worry about them during installation.
npm install @flownet/lib-to-docker
or
yarn add @flownet/lib-to-docker
Usage
Using @flownet/lib-to-docker, you can convert your project into a Docker-ready directory that includes necessary configuration files and execute the Docker build command. Here’s a basic way to utilize the library in your application:
- Import the library and any required modules.
- Set up your source and destination paths.
- Configure the parameters for image generation, such as image name, base image, and any specific files to be included.
- Call the library’s functions to render templates and build your Docker image.
Examples
Below are code examples illustrating common use cases:
Example 1: Basic Docker Image Setup
Create a basic Docker image using your application's dist
directory.
import libToDocker from '@flownet/lib-to-docker';
const config = {
params: {
name: "my-docker-app",
version: "1.0.0",
image_base: "node:20-alpine",
template: "docker"
},
config: {
files: [
{ path: './config/app.json', content: '{"key": "value"}' }
]
},
src: './path/to/your/source',
dest: './output/destination'
};
libToDocker(config).then(() => {
console.log("Docker image setup complete!");
}).catch(error => {
console.error("Image setup failed:", error);
});
Example 2: Using Custom Templates
If you have custom template requirements for Docker setup, specify additional template directories:
import libToDocker from '@flownet/lib-to-docker';
const config = {
params: {
name: "custom-app",
additional_template_dir: './path/to/custom/templates'
},
config: {
files: [
{ path: './config/settings.json', content: '{"theme": "dark"}' }
]
},
src: './source',
dest: './build'
};
libToDocker(config).then(() => {
console.log("Custom Docker setup complete!");
}).catch(error => {
console.error("Setup error:", error);
});
Acknowledgement
This guide outlines the functionality of @flownet/lib-to-docker for building Docker images efficiently, recognizing the contributions of the Flownet team in its development.
Input Schema
$schema: https://json-schema.org/draft/2020-12/schema
type: object
properties:
params:
type: object
properties:
name:
type: string
description: The name of the docker project
default: docker
id:
type: string
description: The identifier for the docker project
default: com.example.docker
version:
type: string
description: The version of the docker project
default: 0.1.0
image_base:
type: string
description: The base image for the docker project
default: node:20-alpine
image_name:
type: string
description: The name of the docker image
default:
$ref: "#/properties/params/properties/name/default"
template:
type: string
description: The template for the docker project
default: docker
title:
type: string
description: The title of the docker project
default: Docker Image
package_name:
type: string
description: The package name of the docker project
default:
$ref: "#/properties/params/properties/name/default"
author:
type: string
description: The author of the docker project
default: Flownet
description:
type: string
description: The description of the docker project
default: Docker Image built with Flownet
vendor:
type: string
description: The vendor of the docker project
default: flownet.ai
package_dir:
type: string
description: The directory for docker package
default: ./.package/docker
out_dir:
type: string
description: The output directory for docker build
default: ./.out/docker
config:
type: object
properties:
files:
type: array
description: The files to handle within config
items:
type: object
properties:
path:
type: string
description: Path for a given file
srcfile:
type: string
description: Source file path
content:
type: string
description: Content of the file
base64:
type: string
description: Base64-encoded content of the file
required:
- params
- config
- src
- dest