Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python sample does not work as documented #82

Closed
DazWilkin opened this issue Jan 24, 2018 · 10 comments
Closed

Python sample does not work as documented #82

DazWilkin opened this issue Jan 24, 2018 · 10 comments

Comments

@DazWilkin
Copy link
Contributor

DazWilkin commented Jan 24, 2018

I followed the instructions (honest):

virtualenv venv
source venv/bin/activate
pip install metaparticle_pkg

pip freeze | grep metaparticle
metaparticle-pkg==0.6.3

I tried the Python sample as-is:

from metaparticle import containerize

This returns:

Traceback (most recent call last):
  File "web.py", line 5, in <module>
    from metaparticle import containerize
ImportError: No module named metaparticle

I then tried:

from metaparticle_pkg import containerize

This returns:

Traceback (most recent call last):
  File "web.py", line 27, in <module>
    'name': 'test',
TypeError: 'module' object is not callable

I briefly explored the package but it's not immediately obvious to me what needs to be done :-(

@tomkukral
Copy link
Contributor

Yes, you need to change at least packager_repo and package_name in examples/simple/example.py.

Should we document it?

@DazWilkin
Copy link
Contributor Author

Thank you.

You solved my problem but that wasn't my question :-)

I was referring to this documentation which contradicts the examples/simple/example.py

https://metaparticle.io/tutorials/python/

from metaparticle import containerize
...
@containerize(
    'docker.io/your-docker-user-goes-here',
    options={
        'ports': [8080],
        'name': 'my-image',
        'publish': True
    })
def main():
    Handler = MyHandler
    httpd = SocketServer.TCPServer(("", port), Handler)
    httpd.serve_forever()

So the documentation needs to be corrected to reflect the correct module name etc.

@DazWilkin
Copy link
Contributor Author

OK... Making progress...

Mashed-up the sample from the metaparticle.io Python page with this sample:

from metaparticle_pkg import Containerize
from six.moves import SimpleHTTPServer, socketserver

import socket

repo = 'docker.io/[[MY-DOCKER]]'
name = 'mp-python'

OK = 200
port = 8080

class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    def do_GET(self):
        self.send_response(OK)
        self.send_header("Content-type", "text/plain")
        self.end_headers()
        self.wfile.write("Hello Metaparticle [{}] @ {}\n".format(
          self.path,
          socket.gethostname()).encode('UTF-8')
        )
        print("request for {}".format(self.path))
    def do_HEAD(self):
        self.send_response(OK)
        self.send_header("Content-type", "text/plain")
        self.end_headers()

@Containerize(
    package={
        'name': name,
        'repository': repo,
        'publish': True,
    },
    runtime={
        'ports': [
            port
        ],
    }
)
def main():
    Handler = MyHandler
    httpd = socketserver.TCPServer(("", port), Handler)
    httpd.serve_forever()

if __name__ == '__main__':
    print("Starting...")
    main()

Runs under Docker locally:

curl http://localhost:8080/test
Hello Henry [/test] @ 8b31882c087c

I reviewed the code to work out -- I think !? -- the config for Kubernetes:

        'replicas': 4,
        'executor': 'metaparticle',

and this yields

Starting...
==> Detected container mp-python-c5b8b68d7-6kfvr:mp-python-0
==> Detected container mp-python-c5b8b68d7-t7ldn:mp-python-0
==> Detected container mp-python-c5b8b68d7-tqz82:mp-python-0
==> Detected container mp-python-c5b8b68d7-xvpph:mp-python-0

and:

kubectl get pods
NAME                        READY     STATUS    RESTARTS   AGE
mp-python-c5b8b68d7-gxj65   1/1       Running   0          11s
mp-python-c5b8b68d7-p5lbd   1/1       Running   0          11s
mp-python-c5b8b68d7-stvqh   1/1       Running   0          11s
mp-python-c5b8b68d7-wkwpz   1/1       Running   0          11s

kubectl get services
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
kubernetes   ClusterIP   10.63.240.1     <none>        443/TCP    1h
mp-python    ClusterIP   10.63.240.159   <none>        8080/TCP   16s

The service is a ClusterIP and would be better (can I configure?) as a LoadBalancer, so:

kubectl run curl --image=radial/busyboxplus:curl -i --tty --rm
If you don't see a command prompt, try pressing enter.
[ root@curl-6896d87888-hqr6b:/ ]$ curl mp-python:8080/test
Hello Henry [/test] @ mp-python-c5b8b68d7-wkwpz

@brendandburns
Copy link
Contributor

you need to set 'public': True in your runtime config to get an external IP address...

(at least that should work in Python, if it doesn't file another bug...)

@brendandburns
Copy link
Contributor

oops, didn't mean to close this...

@brendandburns
Copy link
Contributor

I was wrong, I think it was meant to be 'publicAddress': True

But as I mentioned in the bug, I should probably switch that to public

@DazWilkin
Copy link
Contributor Author

Apologies for my delay in replying.

That did not work. 'publicAddress': True is accepted but I continue to receive a Cluster IP:

kubectl get services
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
kubernetes   ClusterIP   10.43.240.1     <none>        443/TCP    49m
mp-python    ClusterIP   10.43.255.186   <none>        8080/TCP   2m

I did not upgrade my code.

@brendandburns
Copy link
Contributor

brendandburns commented Feb 23, 2018 via email

@DazWilkin
Copy link
Contributor Author

This is mostly my personal curiosity and no customer is being harmed by this not working as intended. Very much value your help @brendanburns and I'm inspired by metaparticle but, unless others are pestering, please don't prioritize this.

I'm headed out on vacation tomorrow and will be non-responsive for a week.

I did not update metaparticle nor refresh the repo.

I added the property as you suggested.

The code is as-above and:

@Containerize(
    package={
        'name': name,
        'repository': repo,
        'publish': True,
    },
    runtime={
        'ports': [
            port
        ],
        'replicas': 4,
        'executor': 'metaparticle',
        'publicAddress': True,
    }
)
pip freeze
backports.ssl-match-hostname==3.5.0.1
certifi==2018.1.18
chardet==3.0.4
docker==2.7.0
docker-pycreds==0.2.1
idna==2.6
ipaddress==1.0.19
metaparticle-pkg==0.6.3
requests==2.18.4
six==1.10.0
urllib3==1.22
websocket-client==0.46.0

What else can I provide that would help you repo?

Does mp-compiler report its version?

@brendandburns
Copy link
Contributor

brendandburns commented Feb 25, 2018

Ok, I fixed this in #98

The syntax is now:

runtime={'ports': [8080], 'executor': 'metaparticle', 'replicas': 3, 'public': True}

And you need to update to metaparticle_pkg version 0.6.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants