Giter Club home page Giter Club logo

docker-file-generator's Introduction

Docker Compose YAML Generator

This script generates a Docker Compose YAML file based on JSON configuration files. It simplifies the process of creating a Docker Compose file for managing multi-container applications.

Disclaimer:
YAML files generated with this app might not be suitable for your production environment. Please use them after making proper adjustments.

Requirements

  • Python 3.x

Usage for cli app

  1. Ensure you have Python 3.x installed on your system.

  2. Download the dockerJson.py script from /apps/fromJson directory.

  3. Run the script with the desired command-line options:

    dockerJson.py -j config1.json config2.json -o /path/to/output -f docker-compose.yml

    The script accepts the following command-line options:

    • -j or --json: Path to one or more JSON configuration files. Separate multiple file paths with spaces.

    • -o or --output: Output directory for the Docker Compose file. (Default: current directory)

    • -f or --filename: Output filename for the Docker Compose file. (Default: docker-compose.yml)

    • -d or --json-dir: Directory path for JSON configuration files. Use this option if the JSON files are located in a different directory.

  4. The script will generate the Docker Compose YAML file based on the provided JSON configuration files and save it in the specified output directory with the specified filename.

  5. The generated Docker Compose file can be used to deploy and manage your multi-container application using Docker Compose.

Example Usage

python dockerJson.py -j flask-psql.json flask-redis.json
python dockerJson.py -j  templates/flask-psql.json templates/flask-redis.json -o ./result -f compose.yml

JSON Configuration File Format

The JSON configuration files should follow a specific format to define the services and their attributes in the Docker Compose file.

Here's an example of a valid JSON configuration file:

{
  "web":
  {
    "image": "nginx:latest",
    "ports": ["80:80"]
  },
  "db":
  {
    "image": "mysql:latest",
    "ports": ["3306:3306"],
    "command": "--default-authentication-plugin=mysql_native_password"
  }
}

Usage for Flask Web App

This is a Flask application that generates a Docker Compose YAML file based on JSON configuration files.

Requirements

  • Python 3.6 or higher

Installation

  1. Clone repo in your device

  2. Navigate to the project directory:

    cd docker-file-generator
  3. Create a virtual environment (optional but recommended):

    python3 -m venv venv
  4. Install the required dependencies:

    pip install -r requirements.txt

Usage

  1. Place your JSON configuration files in the json_templates directory. Each JSON file should contain the configuration for a Docker service like shown before. Or choose from OS file system in the browser.

  2. Run the Flask application:

    flask run
  3. Open your web browser and go to http://localhost:5000.

  4. Select the JSON configuration files you want to include in the Docker Compose file.

  5. Specify the output directory and filename for the generated Docker Compose YAML file.

  6. Click the "Generate" button.

  7. The Docker Compose YAML file will be generated and saved in the specified output directory.

  8. After the file is generated, you will be redirected to a success page with a link to return to the generate page and generate another Docker Compose file.

Notes

Each service in the Docker Compose file is defined as a key-value pair in the JSON object.

The key represents the service name, and the value is an object containing the service attributes.

Supported service attributes include:

image (string): The Docker image to use for the service. ports (list of strings): The port mappings for the service. command (string): The command to run when starting the service. You can define multiple services in a single JSON configuration file.

Note that duplicate service names are not allowed. If a duplicate service name is detected, the script will skip the duplicate entry.

Screenshots

App Screenshot Success Page Success Page with Warning

Contributing and Feedback

Contributions are always welcome! If you have any feedback, please feel free to open issue or contact me in @sevilayerkan

docker-file-generator's People

Contributors

sevilayerkan avatar

Stargazers

 avatar  avatar

Watchers

 avatar

docker-file-generator's Issues

epic: docs and templates for contribution

This epic is dedicated to establishing a robust environment for contributions.

  • Adding readme contribution section: #4
  • Choose and add proper license to the project : #6
  • Issue/Pr template: #7
  • Contribution guideline: #8

feat: readme update

We are planning to include a new screenshot in the main readme. Additionally, we must revise the usage guide for the CLI app and incorporate a dedicated section for contributions.

bug(web): Error occurs when null value given for saving directory

Describe the bug
Error occurs when null value given for saving directory

To Reproduce
Steps to reproduce the behavior:

  1. Go to mainpage in web app
  2. Give null value to directory
  3. See error

Expected behavior
We should implement error handling by adding a null check to the backend function. Simultaneously, we need to display a warning message to the user. As a preventive measure, we can redirect null directories to the root location.

Screenshots
To be added later

Desktop:

  • OS: Windows 10
  • Browser: Chrome 116.0.5845.111
  • Environment : GitHub Codespaces

Refactor app.py

Describe the bug
It's essential to refactor the 'app.py' file, breaking it down into more atomic components rather than maintaining it as a single, large file.

Main goals

  • Breakdown functions to different file
  • Breakdown class definitions to different file
  • Standalone error handling class

bug: warning message colors

Currently, all warning messages are displayed in red. However, we intend to refine the display, so that only error messages appear in red. Other messages will be color-coded differently; for instance, success messages will be shown in green, while warning messages will appear in yellow.

feat: dockerize the project

Is your feature request related to a problem? Please describe.
Dockerize project using the project itself♻️

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.