WsdlToPhp / PackageGenerator

Generates a PHP SDK based on a WSDL, simple and powerful, WSDL to PHP
https://providr.io
MIT License
422 stars 73 forks source link

Feature: Actual versions docker images on docker hub #221

Closed 4n70w4 closed 3 years ago

4n70w4 commented 4 years ago

Hi! I could not find on the hub docker images of this project. It would be convenient to have an images with actual versions on a docker hub.

4n70w4 commented 4 years ago

Draft Dockerfile:

ARG PHP=7.4.10
ARG WSDLTOPHP=3.2.7

FROM php:$PHP-cli

ARG WSDLTOPHP

RUN apt-get update && apt-get install -y libxml2-dev && docker-php-ext-install -j$(nproc) soap

ADD https://github.com/WsdlToPhp/PackageGenerator/releases/download/$WSDLTOPHP/wsdltophp-$WSDLTOPHP-php7.phar wsdltophp.phar

RUN chmod +x wsdltophp.phar

ENTRYPOINT /wsdltophp.phar

Build:

WSDLTOPHP=3.2.7; docker build -t wsdltophp:$WSDLTOPHP --build-arg WSDLTOPHP=$WSDLTOPHP .

Check:

docker run --rm -it wsdltophp:3.2.7 -v

Now need to automatically build images for each version and upload them to the docker hub.

It can be used in CI / CD pipelines:

docker run --entrypoint php --rm -it -v $(pwd)/gen.php:/gen.php -v $(pwd)/src:/src wsdltophp:3.2.7 gen.php

gen.php example:

<?php

require_once 'phar:///wsdltophp.phar/vendor/autoload.php';

use WsdlToPhp\PackageGenerator\ConfigurationReader\GeneratorOptions;
use WsdlToPhp\PackageGenerator\Generator\Generator;

$wsdls = [
    'ServiceV1.svc?wsdl' => [
        'src' => '/src/ServiceV1/',
        'ns' => 'ServiceV1',
    ],

];

foreach($wsdls as $wsdl => $settings) {

    $options = GeneratorOptions::instance();

    $options
        ->setOrigin($wsdl)
        ->setDestination($settings['src'])
        ->setNamespace($settings['ns'])
        // ->setSoapClientClass(SoapClientBase::class)

        // no composer.json needed
        ->setStandalone(false)

        // no tutorial.php file needed
        ->setGenerateTutorialFile(false)

        // no src folder needed for the generated package
        ->setSrcDirname('');

    $generator = new Generator($options);
    $generator->generatePackage();

    fwrite(STDOUT, PHP_EOL . $settings['src'] . ' / ' . $settings['ns']);
}
mikaelcom commented 3 years ago

Hi, after a few commits :sweat_smile: I think I finally achieved what I wanted in order to answer to your feature using Github Actions which avoids me some work. I still have an issue with the "Build and push to Docker" step which is still executed even if the current Job PHP version is not 7 :disappointed:, a few commits are coming again ;), if you have any clue, feel free to guide me ;).

Let me know if it works as expected from https://hub.docker.com/r/mikaelcom/wsdltophp. Readme is coming soon too at Docker hub.

mikaelcom commented 3 years ago

Hi, after a few commits I think I finally achieved what I wanted in order to answer to your feature using Github Actions which avoids me some work. I still have an issue with the "Build and push to Docker" step which is still executed even if the current Job PHP version is not 7 , a few commits are coming again ;), if you have any clue, feel free to guide me ;).

Let me know if it works as expected from https://hub.docker.com/r/mikaelcom/wsdltophp. Readme is coming soon too at Docker hub.

The docker image is now only built using the PHP 7 version then pushed to the Docker Hub platform :wink:.

With this setup, each time a tag will be created:

4n70w4 commented 3 years ago

Hi! It is desirable that the filename be with the phar extension.

require_once 'phar:///wsdltophp/vendor/autoload.php';
Warning: require_once(phar:///wsdltophp/vendor/autoload.php): failed to open stream: phar error: invalid url or non-existent phar "phar:///wsdltophp/vendor/autoload.php" in /gen.php on line 4
mikaelcom commented 3 years ago

So, to be clear, for me :), using the image in a command line right away without any php script would be:

$ docker run --entrypoint php --rm -it mikaelcom/wsdltophp:tagname wsdltophp.phar generate:package ... --force
mikaelcom commented 3 years ago

I reviewed my point of view as I wanted to allow to use it as the composer image, docker run --rm -it composer install for example, which I succeeded to make it usable such as:

 docker run --rm -it mikaelcom/wsdltophp generate:package ... --force

Your use case should still work, let me know when you can.

mikaelcom commented 3 years ago

Hi, did you have some time to try it out?

I think it's good to go, let me know ;) Thx

4n70w4 commented 3 years ago

Sorry, I haven't looked yet, now there are other tasks (