wsdl2phpgenerator / wsdl2phpgenerator-cli

wsdl2phpgenerator command line application *work-in-progress*
MIT License
68 stars 22 forks source link

Add dockerfile to enable running the command in a docker container. #2

Closed walle closed 9 years ago

walle commented 9 years ago

I've not been involved in the project for some time now, but last week I wrote a Dockerfile for my project gimli, https://registry.hub.docker.com/u/walle/gimli/. And it gives a nice way to run the project without versioning issues and such. So I thought that I might make one for this project too.

I don't know if people want this feature, so I'm making a pull request. Please comment to make your opinion heard. In this pull request is a Dockerfile, the foundation for one. It uses another docker repo for the base system and it runs the 2.5.5 version of wsdl2phpgenerator-cli since the 3.0.0 phar was not released yet. I think we should use a clean ubuntu image and just install the parts needed, this gives us freedom to select PHP version and so, right now we are at the mercy of the version in the darh/php-essentials repo. 5.5 at the time of writing. The version of wsdl2phpgenerator-cli should also be bumped when the new release is available.

If you think this is a good contribution, we also have to figure out how to host this on https://registry.hub.docker.com, in a good way, so it's easy to install and run. The command should just be

$ docker run -v /home/walle/wsdl2phpgenerator-output:/tmp/wsdl2php wsdl2phpgenerator/wsdl2phpgenerator-cli -i http://my.wsdl.file -o /tmp/wsdl2php

But for now, before it's in the registry, it has to be built locally first e.g.

[17:45:27] ~/wsdl2phptest $ sudo docker build .
Sending build context to Docker daemon  2.56 kB
Sending build context to Docker daemon 
Step 0 : FROM darh/php-essentials
 ---> f0f546968d09
Step 1 : MAINTAINER Fredrik Wallgren <fredrik.wallgren@gmail.com>
 ---> Using cache
 ---> c4c7bb04ef96
Step 2 : RUN apt-get install -y wget
 ---> Using cache
 ---> ccb980d2ef7b
Step 3 : RUN wget https://github.com/wsdl2phpgenerator/wsdl2phpgenerator/releases/download/2.5.5/wsdl2phpgenerator-2.5.5.phar
 ---> Using cache
 ---> 24fd93292786
Step 4 : RUN echo '#!/usr/bin/env bash\n php wsdl2phpgenerator-2.5.5.phar "$@"' > wsdl2phpgenerator
 ---> Running in 0a570196331c
 ---> 86679b21c96d
Removing intermediate container 0a570196331c
Step 5 : RUN chmod +x wsdl2phpgenerator
 ---> Running in ec371354dfab
 ---> 09d4bd4baa0f
Removing intermediate container ec371354dfab
Step 6 : ENTRYPOINT ["./wsdl2phpgenerator"]
 ---> Running in 655f9794eac6
 ---> 0bfa82e66370
Removing intermediate container 655f9794eac6
Successfully built 0bfa82e66370
[17:45:31] ~/wsdl2phptest $ sudo docker run -v /home/walle/wsdl2phptest:/tmp/wsdl2php 0bfa82e66370 -i https://raw.githubusercontent.com/wsdl2phpgenerator/wsdl2phpgenerator/2.5.5/tests/fixtures/wsdl/currencyconvertor/CurrencyConvertor.wsdl -o /tmp/wsdl2php
Generation complete

A short explanation of the command, it runs the wsdl2phpgenerator phar inside a docker container, so to be able to get the generated files we need to mount a directory inside the container so we can write to it. All arguments after the image id goes to wsdl2phpgenerator-cli so the -i and -o flags in this case. The mounting is done with the -v flag to docker -v /home/walle/wsdl2phptest:/tmp/wsdl2php mounts the directory wsdl2phptest in my home folder to the wsdl2php direcory in the containers /tmp directory. So the command writes the output to /tmp/wsdl2php and it ends up in my home folder.

And again, thank you for your work with this project @kasperg

kasperg commented 9 years ago

Interesting suggestion @walle!

I have little experience with Docker so bear with me. For example I had not considered you could use it to run CLI apps which generates output to the local file system. Very nifty!

I consider the wsdl2phpgenerator dependency chain short and not very strict. We currently require PHP 5.3 and the SOAP extension. This is required when using the tool anyway. Thus at the moment I am not sure what a Docker image brings to the table. It would also be a contribution that I personally would have a hard time supporting going forward.

However going forward this could allow us to bump our version requirements for code generation - require PHP 5.6 for example - without leaving everybody entirely behind. We would still have to ensure that the generated code is usable on the supported PHP versions.

Regarding choice of base image it seems like Docker provides official PHP images without Apache etc. Could they be of any use?

walle commented 9 years ago

Yes, it's a nifty feature. I don't have much experience with docker either, but it is really growing on me now when I've used it a bit.

Yes, I don't know if it really brings that much to the table, if you are about to develop something that will use the generated code you will eventually have to install the dependencies. I guess I'm lagging behind somewhat in PHP development. In the "good" old days between 5.2 and 5.3 I think it was when namespaces were introduced. Then it would have been good to be able to generate the code and look it over without having to change your development machine (because I remember that as being kind of tricky, I guess it is easier now), e.g. if you were developing something in 5.2. But nowadays I get the impression that version bumps goes a bit smother and that developers stay up to date more. So right now I guess the only use this would have is, "I want to see what kind of code this tool generates.". It made a lot more sense for gimli to have a docker file like this, as it is a tool that generates php documents, not code :)

Yes, we could close this for now and take it up again if a version bump brings a lot of changes.

Yes, that would be the images to use, they are locked at version also if I'm not mistaken.