Giter Club home page Giter Club logo

droxy's Introduction

Droxy

create commands that proxy to docker

DROXY

Getting started

If you have go installed on your machine simply install it.
go install github.com/Oppodelldog/droxy@latest

Otherwise, download a precompiled binary from releases.

Wiki
Take a look at the wiki examples to learn how to set up custom commands
https://github.com/Oppodelldog/droxy/wiki

Configuration

In droxy.toml you define the commands you want to create.

The following example contains all possible configuration options.

droxy.toml:

    Version="1"

    [[command]]
      name = "basic command"  # name of the command
      isTemplate = true       # this command can be used as a template, no command will be created
      addGroups = true        # add current systems groups  (linux only)
      impersonate = true      # use executing user and group for execution in the container (linux only)
      workDir = "/app"        # define working directory
      autoMountWorkDir=true   # if true and workDir exists on host it will be added to volume mounts
      removeContainer=true    # remove container after command has finished
      isInteractive=true      # enable interaction with the called command
      isDetached=false        # starts the container in background
      RequireEnvVars=false    # if true, not defined env vars that are configured will lead to an error
      uniqueNames=true        # will generate unique container names for every run.
      os = "linux"            # if set this config will load if executed on linux. 
      mergeTemplateArrays = ["Volumes"] # in command config this will merge Volumes instead of overwriting them
      # volume mappings
      volumes = [
          "${HOME}:${HOME}",
          "${SSH_AUTH_SOCK}:/run/ssh.sock",
          "/etc/passwd:/etc/passwd:ro",
          "/etc/group:/etc/group:ro",
          "/run/docker.sock:/run/docker.sock"
      ]
      tmpfs = [
          "/tmpfs1"
      ]

      # environment variable mappings
      envvars = [
          "HOME=${HOME}",
          "SSH_AUTH_SOCK=/run/ssh.sock",
          "DOCKER_HOST=unix:///run/docker.sock"
      ]

      links = [
        "containerXY:aliasXY"
      ]

      ports = [
        "8080:80"
      ]

      portsFromParams = [
          "some regex where the group (\\d*) parses the port from",
      ]

    [[command]]
        template = "basic command"  # apply settings from template 'basic command' to this command
    	name = "php"                # name of the command which is created by calling 'docker-proxy symlinks'
    	entryPoint = "php"          # basic binary to execute inside the container
    	image = "php:7.1.13"        # docker image the container is run on

    [[command]]
        template = "basic command"
    	name = "phpstorm-php-unittest-integration"
    	entryPoint = "php"
    	image = "php:7.1.13"

    	# replace  127.0.0.1 with docker ip of host
        replaceArgs = [
            [
              "-dxdebug.remote_host=127.0.0.1",
              "-dxdebug.remote_host=172.17.0.1"
            ]
        ]

        # ensure xdebug will startup and communicate
        additionalArgs = ["-dxdebug.remote_autostart=1"]

Create commands

Once you have set up your config, you want to create commands out of it. To generate the command binaries, navigate next to droxy.toml file and execute:

    droxy clones

By default droxy clones will not overwrite existing files.
If you update droxy and want to update your commands as well, add flag -f which will overwrite existing files.

creation alternatives

Beside creating clones of droxy there are two other options the droxy-files can be created:

  • symlinks
  • hardlinks

Here are their pros and cons

subcommand pro con
clones the command knows its directory, will find config next to command takes more disk space
symlinks takes less disk space cannot determine the commands directory, you have to provide a config filepath by env var $DROXY_CONFIG
hardlinks takes less disk space and knows directory harder to maintain

Contribute

Feature requests and pull requests are welcome.

droxy's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

atul9

droxy's Issues

enable docker-compose

Since docker run works, why not adding docker-compose support?
extend configuration to create docker run commands and docker-compose commands.

add documentation

to fix go lint warnings, add documentation to all exportet methods and types

intercept and bypass command streams into logs

For debugging the logging feature is quite nice.
It would be more nice if the communication between caller and docker-command would be logged.

Somehow one should intercept Stdin,Stdout,Stderr to read communication, write it to the log, and bypass it to the appropriate stream.

refactoring of config command building

droxy\dockercmd\config.go
The part where the configuration is converted into a command using the command builder
is an important path and is currently tested by some module test which output highly depends on the system it is run.
To enable more isolated testing this file shall be refactored. For each configuration option there is the same interface used to call the command builder.
Those logic should be moved to be more generic and by this more testable.

check and ensure windows support

Should not be too much work, there should just be one system call at the moment.

docker-proxy-command automatically sets the -t flag when it detects that the command was started by a terminal. convenience stuff (should be removed if it won't work properly on windows)

For the determination if the command is spawned in a terminal session, I copied some code from the docker-cli, but only the linux part. there should be an appropriate call for windows.
If this does not work out well, we can convert the currently automatically set -t into a configuration option.

Refactor config/model.go

The use of pointers is required to reflect if the user has set a configuration option or not.
There are already descriptive helper function like hasPropertyXSet but the code using that model often accesses properties directly by *config.commandName having to check.
This should be wrapped into more convenient and meaningful functions.

include version number

add make target to build a release binary.
it should

  • checkout the latest git tag
  • build the binary
  • include version number during build
  • include version number in help output

Add go lint to makefile lint task

the go report card report does look good, but we can get a+.
seems that go lint currently is not configured to run from the make file.

droxy shall reveal itself when called as proxy command

droxy shall reveal itself when called as proxy command.

to enable the user to ensure that a created command is a droxy command, the command shall reveal itself as droxy when called with parameter

--is-it-droxy

can output a simple answer, or the default droxy help message, or version info

Improve templating

When building up on a template, it might be useful to just add volumes to the template definition.
e.g. having volume bind in a template like
${HOME}:${HOME}

it could be handy to just add a different mapping like
${SSH_AUTH_SOCK}:/run/ssh.sock

Currently the command using the template would have to
add both volumes like:
${HOME}:${HOME}
${SSH_AUTH_SOCK}:/run/ssh.sock

Option to not panic if envvar is not set

Currently if a environment variable is defined to be mapped in toml the command panics id the environment variable is not set at runtime.

This makes sense for debugging the droxy command during developing it, but the reuse of common configuration is more complicated.

So there should be a flag to prevent command from panicing if a environment variable cannot be resolved.

Sample:

[[command]]
    name="php7"
    image="php7-dbg"
    envvars=[
        "XDEBUG_CONFIG=${XDEBUG_CONFIG}"
    ]

if XDEBUG_CONFIG is not set at runtime, thge program panics.

the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty

I tired PHPStorm integration under windows using droxy, but when adding the php interpreter
droxy logs show up an error. Seems to be something with terminal detection under windows.

Here's the log:

PS C:\Users\user\PhpstormProjects\droxy-phpstorm-integration\bin> tail -f .\droxy.log time="2018-04-07T11:04:32+02:00" level=info msg="configuration load from: 'C:\\Users\\user\\PhpstormProjects\\droxy-phpstorm-integration\\bin/droxy.toml'" time="2018-04-07T11:04:32+02:00" level=info time="2018-04-07T11:04:32+02:00" level=info msg="environment variables:" time="2018-04-07T11:04:32+02:00" level=info msg="=::=::\\" time="2018-04-07T11:04:32+02:00" level=info msg="ALLUSERSPROFILE=C:\\ProgramData" time="2018-04-07T11:04:32+02:00" level=info msg="APPDATA=C:\\Users\\user\\AppData\\Roaming" time="2018-04-07T11:04:32+02:00" level=info msg="asl.log=Destination=file" time="2018-04-07T11:04:32+02:00" level=info msg="CommonProgramFiles=C:\\Program Files\\Common Files" time="2018-04-07T11:04:32+02:00" level=info msg="CommonProgramFiles(x86)=C:\\Program Files (x86)\\Common Files" time="2018-04-07T11:04:32+02:00" level=info msg="CommonProgramW6432=C:\\Program Files\\Common Files" time="2018-04-07T11:04:32+02:00" level=info msg="COMPUTERNAME=user-PC" time="2018-04-07T11:04:32+02:00" level=info msg="ComSpec=C:\\WINDOWS\\system32\\cmd.exe" time="2018-04-07T11:04:32+02:00" level=info msg="DOCKER_TOOLBOX_INSTALL_PATH=C:\\Program Files\\Docker Toolbox" time="2018-04-07T11:04:32+02:00" level=info msg="FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer" time="2018-04-07T11:04:32+02:00" level=info msg="FPS_BROWSER_USER_PROFILE_STRING=Default" time="2018-04-07T11:04:32+02:00" level=info msg="FP_NO_HOST_CHECK=NO" time="2018-04-07T11:04:32+02:00" level=info msg="GOPATH=F:\\shared-projects\\go-workspace" time="2018-04-07T11:04:32+02:00" level=info msg="GOROOT=C:\\Go\\" time="2018-04-07T11:04:32+02:00" level=info msg="GTK_BASEPATH=C:\\Program Files (x86)\\GtkSharp\\2.12\\" time="2018-04-07T11:04:32+02:00" level=info msg="HOMEDRIVE=C:" time="2018-04-07T11:04:32+02:00" level=info msg="HOMEPATH=\\Users\\user" time="2018-04-07T11:04:32+02:00" level=info msg="LOCALAPPDATA=C:\\Users\\user\\AppData\\Local" time="2018-04-07T11:04:32+02:00" level=info msg="LOGONSERVER=\\\\user-PC" time="2018-04-07T11:04:32+02:00" level=info msg="MAGICK_CONFIGURE_PATH=C:\\Program Files (x86)\\OpenShot Video Editor\\ImageMagick\\etc\\configuration" time="2018-04-07T11:04:32+02:00" level=info msg="NUMBER_OF_PROCESSORS=4" time="2018-04-07T11:04:32+02:00" level=info msg="OneDrive=C:\\Users\\user\\OneDrive" time="2018-04-07T11:04:32+02:00" level=info msg="OS=Windows_NT" time="2018-04-07T11:04:32+02:00" level=info msg="Path=C:\\Program Files\\Docker\\Docker\\Resources\\bin;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\HashiCorp\\Vagrant\\bin;C:\\Program Files (x86)\\AMD\\ATI.ACE\\Core-Static;C:\\Program Files\\Git\\cmd;C:\\Program Files\\Git\\usr\\bin;C:\\Program Files (x86)\\ATI Technologies\\ATI.ACE\\Core-Static;F:\\shared-projects\\go-workspace\\bin;C:\\Program Files (x86)\\GtkSharp\\2.12\\bin;c:\\Python27\\;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;C:\\Program Files (x86)\\Windows Live\\Shared;C:\\Go\\bin;C:\\Users\\user\\AppData\\Local\\Microsoft\\WindowsApps;;C:\\Program Files\\Docker Toolbox" time="2018-04-07T11:04:32+02:00" level=info msg="PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC" time="2018-04-07T11:04:32+02:00" level=info msg="PROCESSOR_ARCHITECTURE=AMD64" time="2018-04-07T11:04:32+02:00" level=info msg="PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 60 Stepping 3, GenuineIntel" time="2018-04-07T11:04:32+02:00" level=info msg="PROCESSOR_LEVEL=6" time="2018-04-07T11:04:32+02:00" level=info msg="PROCESSOR_REVISION=3c03" time="2018-04-07T11:04:32+02:00" level=info msg="ProgramData=C:\\ProgramData" time="2018-04-07T11:04:32+02:00" level=info msg="ProgramFiles=C:\\Program Files" time="2018-04-07T11:04:32+02:00" level=info msg="ProgramFiles(x86)=C:\\Program Files (x86)" time="2018-04-07T11:04:32+02:00" level=info msg="ProgramW6432=C:\\Program Files" time="2018-04-07T11:04:32+02:00" level=info msg="PSModulePath=C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\" time="2018-04-07T11:04:32+02:00" level=info msg="PUBLIC=C:\\Users\\Public" time="2018-04-07T11:04:32+02:00" level=info msg="QT_PLUGIN_PATH=C:\\Program Files (x86)\\OpenShot Video Editor\\" time="2018-04-07T11:04:32+02:00" level=info msg="SESSIONNAME=Console" time="2018-04-07T11:04:32+02:00" level=info msg="SystemDrive=C:" time="2018-04-07T11:04:32+02:00" level=info msg="SystemRoot=C:\\WINDOWS" time="2018-04-07T11:04:32+02:00" level=info msg="TEMP=C:\\Users\\user\\AppData\\Local\\Temp" time="2018-04-07T11:04:32+02:00" level=info msg="TMP=C:\\Users\\user\\AppData\\Local\\Temp" time="2018-04-07T11:04:32+02:00" level=info msg="USERDOMAIN=user-PC" time="2018-04-07T11:04:32+02:00" level=info msg="USERDOMAIN_ROAMINGPROFILE=user-PC" time="2018-04-07T11:04:32+02:00" level=info msg="USERNAME=user" time="2018-04-07T11:04:32+02:00" level=info msg="USERPROFILE=C:\\Users\\user" time="2018-04-07T11:04:32+02:00" level=info msg="VBOX_MSI_INSTALL_PATH=C:\\Program Files\\Oracle\\VirtualBox\\" time="2018-04-07T11:04:32+02:00" level=info msg="VS100COMNTOOLS=C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\Tools\\" time="2018-04-07T11:04:32+02:00" level=info msg="VS140COMNTOOLS=C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\Tools\\" time="2018-04-07T11:04:32+02:00" level=info msg="windir=C:\\WINDOWS" time="2018-04-07T11:04:32+02:00" level=info msg=---------------------------------------------------------------------- time="2018-04-07T11:04:32+02:00" level=info msg="origin arguments:" time="2018-04-07T11:04:32+02:00" level=info msg="C:\\Users\\user\\PhpstormProjects\\droxy-phpstorm-integration\\bin\\php7.2.exe" time="2018-04-07T11:04:32+02:00" level=info msg="C:\\Users\\user\\AppData\\Local\\Temp\\ide-phpinfo.php" time="2018-04-07T11:04:32+02:00" level=info msg=---------------------------------------------------------------------- time="2018-04-07T11:04:32+02:00" level=info msg="calling docker ro tun 'php7.2'" time="2018-04-07T11:04:32+02:00" level=info msg="docker run -t --rm --name php7.2 -v /C/Users/user/AppData/Local/Temp:/C/Users/user/AppData/Local/Temp -v /C/Users/user/PhpstormProjects/droxy-phpstorm-integration:/C/Users/user/PhpstormProjects/droxy-phpstorm-integration -e XDEBUG_CONFIG= -a STDIN -a STDOUT -a STDERR php:7.2 C:\\Users\\user\\AppData\\Local\\Temp\\ide-phpinfo.php" time="2018-04-07T11:04:32+02:00" level=info msg="StdErr:the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'\n" time="2018-04-07T11:04:32+02:00" level=info msg="docker finished with exit code '1'"

Awesome project name

Find an awesome project name.

  • docker-proxy-command is too long
  • docker-proxy has some meaning in docker in network

Caching container

To startup commands more quickly it might be an option to save time in mounting volumes.
There could be a caching container which mounts volumes.
Other commands can then use the containers volumes by using the --volumes-from option.
Since the caching container will some time get out of sync there should be an option to clear that cache or define a lifetime which then is handled at each run of a proxy command.

https://docs.docker.com/storage/volumes/

enable phpstorm debugging integration

since phpstorm docker integration does not work well it would be nice if droxy could be used
as "local php" from phpstorm.

phpstorm executes the following call for local php debugging:

php -dxdebug.remote_enable=1 \
	-dxdebug.remote_mode=req \
	-dxdebug.remote_port=9000 \
	-dxdebug.remote_host=127.0.0.1 \
	index.php

Obviously inside of the container 127.0.0.1 will not be accessible.
So one todo is:

  • enable replacement of cli arguments

During testing I found that the replacement of the remote_host parameter is not enough.
When appending an additional argument 'xdebug.remote_autostart=1' it works like a charm.
The 'autostart' option is like setting "XDEBUG_SESSION_START=1" in the query string of an url.
So the second todo is:

  • enable appending of custom cli arguments
php -dxdebug.remote_enable=1 \
	-dxdebug.remote_mode=req \
	-dxdebug.remote_port=9000 \
	-dxdebug.remote_host=172.17.0.1 \
	-dxdebug.remote_log=xdebug.log \
	-dxdebug.remote_timeout=2000 \
	-dxdebug.remote_autostart=1 \
	index.php

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.