Luciano Andrade 8 vuotta sitten
vanhempi
commit
b5d1f55669
3 muutettua tiedostoa jossa 446 lisäystä ja 0 poistoa
  1. 16 0
      composer.json
  2. 73 0
      composer.lock
  3. 357 0
      src/Docker/Composer/FileFormat2.php

+ 16 - 0
composer.json

@@ -0,0 +1,16 @@
+{
+    "name": "lucciano/php-docker-lib",
+    "type": "library",
+    "require": {
+        "symfony/yaml": "^3.3"
+    },
+    "autoload": {
+        "psr-4": {"Docker\\": "src/"}
+    },
+    "authors": [
+        {
+            "name": "Luciano Andrade",
+            "email": "andrade.luciano@gmail.com"
+        }
+    ]
+}

+ 73 - 0
composer.lock

@@ -0,0 +1,73 @@
+{
+    "_readme": [
+        "This file locks the dependencies of your project to a known state",
+        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
+        "This file is @generated automatically"
+    ],
+    "content-hash": "8ec5c02a1de4ef099ad8b438e52d3d2e",
+    "packages": [
+        {
+            "name": "symfony/yaml",
+            "version": "v3.3.2",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/symfony/yaml.git",
+                "reference": "9752a30000a8ca9f4b34b5227d15d0101b96b063"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/symfony/yaml/zipball/9752a30000a8ca9f4b34b5227d15d0101b96b063",
+                "reference": "9752a30000a8ca9f4b34b5227d15d0101b96b063",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.5.9"
+            },
+            "require-dev": {
+                "symfony/console": "~2.8|~3.0"
+            },
+            "suggest": {
+                "symfony/console": "For validating YAML files using the lint command"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "3.3-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Symfony\\Component\\Yaml\\": ""
+                },
+                "exclude-from-classmap": [
+                    "/Tests/"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Fabien Potencier",
+                    "email": "fabien@symfony.com"
+                },
+                {
+                    "name": "Symfony Community",
+                    "homepage": "https://symfony.com/contributors"
+                }
+            ],
+            "description": "Symfony Yaml Component",
+            "homepage": "https://symfony.com",
+            "time": "2017-06-02T22:05:06+00:00"
+        }
+    ],
+    "packages-dev": [],
+    "aliases": [],
+    "minimum-stability": "stable",
+    "stability-flags": [],
+    "prefer-stable": false,
+    "prefer-lowest": false,
+    "platform": [],
+    "platform-dev": []
+}

+ 357 - 0
src/Docker/Composer/FileFormat2.php

@@ -0,0 +1,357 @@
+<?php
+
+namespace Docker\Composer
+use Extension;
+
+class Service{
+
+	protected $name;
+	protected $config;
+
+	function __construct($name, $){
+		$this->name = $name;
+	}
+
+	function getName($name){ return $this->name; }
+
+	protected $cap_add;
+	protected $cap_drop;
+
+	function capAdd($name){
+		if(!is_array($this->config["cap_add"])) $this->config["cap_add"] = array();
+		$this->$config["cap_add"][] = $name;
+
+		return $this;
+        }
+
+	function capDrop($name){
+		if(!is_array($this->config["cap_drop"])) $this->config["cap_drop"] = array();
+		$this->$config["cap_drop"][] = $name;
+
+		return $this;
+        }
+
+	function getCapAdd(){ return $this->config["cap_add"]; }
+	function getCapDrop(){ return $this->config["cap_drop"]; }
+
+	function buid($context, $dockerfile = null, $args = array()){
+		$this->config["build"] = 
+			  array('context'=> $context,
+				'dockerfile' => $dockerfile,
+				'args' => $args);
+		return $this;
+        }
+
+	function getBuild(){ return $this->build; }
+
+
+	function command($cmd){
+		$this->config["command"] = $cmd; 
+		return $this:
+	}
+
+	function getCommand(){ return $this->config["command"]; }
+
+        /**
+        * cgroup_parent
+        */
+	function cgroup_parent($cgroup_parent){
+		$this->config["cgroup_parent"] = $cgroup_parent;
+		return $this;
+	}
+        
+        /**
+        * container_name
+        */
+	function container_name($container_name){
+		$this->config["container_name"] = $container_name;
+		return $this;
+	}
+        
+        /**
+        * devices
+        */
+	function devices($devices){
+		$this->config["devices"] = (array)($devices);
+		return $this;
+	}
+
+	function addDevice($src $dest){
+		$this->config["devices"][] =  $src . ":" . $dest;
+		return $this;
+	}
+
+        /**
+        * depends_on
+        */
+	function depends_on($depends_on){
+		$this->config["depends_on"] = (array)($depends_on);
+		return $this;
+	}
+
+	function addDepends_on($service){
+		if(!is_array($this->config["depends_on"])) $this->config["depends_on"] = array();
+		$this->config["depends_on"][] = $service;
+		return $this;
+	}
+        
+        /**
+        * dns
+        */
+	function dns($dns){
+		$this->config["dns"] = array_values((array)($dns));
+		return $this;
+	}
+
+	function addDns($dns){
+		if(!is_array($this->config["dns"])) $this->config["dns"] = array();
+		$this->config["dns"][] = $dns;
+		return $this;
+	}
+        
+        /**
+        * dns_opt
+        */
+	function dns_opt($dns_opt){
+		$this->config["dns_opt"] = array_values((array)($dns_opt));
+		return $this;
+	}
+        
+        /**
+        * dns_search
+        */
+	function dns_search($dns_search){
+		$this->config["dns_search"] = array_values((array)$dns_search);
+		return $this;
+		
+	}
+
+	function addDns_search($dns_search){
+		if(!is_array($this->config["dns_search"])) $this->config["dns_search"] = array();
+		$this->config["dns_search"][] = $dns_search;
+		return $this;
+	}
+        
+        /**
+        * tmpfs
+        */
+	function tmpfs($tmpfs){
+		$this->config["tmpfs"] = array_values((array)($tmpfs));
+		return $this;
+	}
+
+	function addTmpfs($tmpfs){
+		if(!is_array($this->config["tmpfs"])) $this->config["tmpfs"] = array();
+		$this->config["tmpfs"][] = $tmpfs;
+		return $this;
+	}
+        
+        /**
+        * entrypoint
+        */
+	function entrypoint($entrypoint){
+		$this->config["entrypoint"] = $entrypoint;
+		return $this;
+	}
+		
+        
+        /**
+        * env_file
+        */
+	protected $env_file;
+
+        /**
+        * environment
+        */
+	protected $environment;
+
+        /**
+        * expose
+        */
+	protected $expose;
+
+        /**
+        * extends
+        */
+	protected $extends;
+
+        /**
+        * external_links
+        */
+	protected $external_links;
+
+        /**
+        * extra_hosts
+        */
+	protected $extra_hosts;
+
+        /**
+        * group_add
+        */
+	protected $group_add;
+
+        /**
+        * healthcheck
+        */
+	protected $healthcheck;
+
+        /**
+        * image
+        */
+	protected $image;
+
+        /**
+        * init
+        */
+	protected $init
+        /**
+        * isolation
+        */
+	protected $isolation;
+
+        /**
+        * labels
+        */
+	protected $labels;
+
+        /**
+        * links
+        */
+	protected $links;
+
+        /**
+        * logging
+        */
+	protected $logging;
+
+        /**
+        * network_mode
+        */
+	protected $network_mode;
+
+        /**
+        * networks
+        */
+	protected $networks;
+
+        /**
+        * aliases
+        */
+	protected $aliases;
+
+        /**
+        * ipv4_address, 
+        */
+	protected $ipv4_address;
+
+	/**
+	* ipv6_address
+        */
+	protected $ipv6_address;
+
+        /**
+        * link_local_ips
+        */
+	protected $link_local_ips;
+
+        /**
+        * pid
+        */
+	protected $pid;
+
+        /**
+        * pids_limit
+        */
+	protected $pids_limit;
+
+        /**
+        * ports
+        */
+	protected $ports;
+
+        /**
+        * security_opt
+        */
+	protected $security_opt;
+
+        /**
+        * stop_grace_period
+        */
+	protected $stop_grace_period;
+
+        /**
+        * stop_signal
+        */
+	protected $stop_signal;
+
+        /**
+        * sysctls
+        */
+	protected $sysctls;
+
+        /**
+        * ulimits
+        */
+	protected $ulimits;
+
+        /**
+        * userns_mode
+        */
+	protected $userns_mode;
+
+        /**
+        * volumes
+        */
+	protected $volumes;
+
+	/**
+	* volume_driver
+	*/
+	protected $volume_driver;
+
+        /**
+        * volumes_from
+        */
+	protected $volumes_from;
+
+        /**
+        * restart
+        */
+	protected $restart;
+}
+
+class ServiceNotFoundException extends Extension
+{
+	function __construct($name){
+		parent::__construct("Service $name not found");
+	}
+}
+
+class FileFormat2 
+{
+	/**
+         * path of the docker-compose.yml
+         */
+	protected $path;
+
+        protected $services;
+
+	function __construct($path = "."){
+		$this->path = $path;
+		$this->services = array();
+        }
+
+	function addService($name){
+ 		$this->services[$name] = new Service($name);     		
+		return $this->services[$name];
+        }
+
+	function service($name){
+		if(!$this->services[$name]) throw new ServiceNotFoundException($name);
+		return $this->services[$name]
+        }
+
+	
+}
+
+