I am trying to build a Docker image like the one described in this Dockerfile.
FROM python:2.7
WORKDIR /usr/local/src/heartbeat
ADD requirements.txt /usr/local/src/heartbeat
ADD heartbeat/heartbeat.py /usr/local/src/heartbeat
RUN pip install -r requirements.txt
CMD ["python", "heartbeat.py"]
I have found all sorts of examples that do not seem complete to me. I started with https://bazel.build/, https://github.com/bazelbuild/rules_docker and https://medium.com/bitnami-perspectives/building-docker-images-without-docker-c619061b13a9.
I have stumbled on https://github.com/google/subpar and https://github.com/bazelbuild/rules_docker#py_image but cannot seem to put it all together.
Any recommendations on where to start with learning how to build a trivial container with a python app.
Thanks
Charlie
I'd expect that to be possible by following these instructions to get your Python script working in Bazel (without Docker):
https://github.com/bazelbuild/rules_python#setup
https://github.com/bazelbuild/rules_python#importing-pip-dependencies
https://github.com/bazelbuild/rules_python#consuming-pip-dependencies
then, if you switch your py_binary to a py_image as described here:
https://github.com/bazelbuild/rules_docker#py_image
you should be able to run the same script inside a Docker container with (assuming you have `py_image(name="heartbeat", ...)`):
bazel run :heartbeat_image
Bazel's support for Python is in an early stage, so you might run into issues. If you do, describe what you did and the exact error you got, and I'll try to help. There are also a few other approaches for using Bazel for Python scripts - try searching the archive of bazel-discuss for more info.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/heartbeat_bin
Traceback (most recent call last):
File "/private/var/tmp/_bazel_brgl/ae72ec8531e850566373626f2dd415c9/execroot/__main__/bazel-out/darwin-fastbuild/bin/heartbeat_bin.runfiles/__main__/heartbeat/heartbeat.py", line 1, in <module>
from snowplow_tracker import Tracker, Emitter, logger
File "/private/var/tmp/_bazel_brgl/ae72ec8531e850566373626f2dd415c9/execroot/__main__/bazel-out/darwin-fastbuild/bin/heartbeat_bin.runfiles/pypi__snowplow_tracker_0_8_0/snowplow_tracker/__init__.py", line 3, in <module>
from snowplow_tracker.emitters import logger, Emitter, AsyncEmitter, CeleryEmitter, RedisEmitter
File "/private/var/tmp/_bazel_brgl/ae72ec8531e850566373626f2dd415c9/execroot/__main__/bazel-out/darwin-fastbuild/bin/heartbeat_bin.runfiles/pypi__snowplow_tracker_0_8_0/snowplow_tracker/emitters.py", line 33, in <module>
from celery import Celery
File "/private/var/tmp/_bazel_brgl/ae72ec8531e850566373626f2dd415c9/execroot/__main__/bazel-out/darwin-fastbuild/bin/heartbeat_bin.runfiles/pypi__celery_3_1_11/celery/__init__.py", line 130, in <module>
from celery import five
File "/private/var/tmp/_bazel_brgl/ae72ec8531e850566373626f2dd415c9/execroot/__main__/bazel-out/darwin-fastbuild/bin/heartbeat_bin.runfiles/pypi__celery_3_1_11/celery/five.py", line 51, in <module>
from kombu.five import monotonic
ImportError: No module named kombu.five
ERROR: Non-zero return code '1' from command: Process exited with status 1
~
I assume that it is not loading all the python packages correctly. That said, when I look through the files in the bazel-out directory, they all seem to be there.
--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/b650e4e2-070a-484d-b4b5-c8384427021d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "bazel-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bazel-discuss/Nt4F-_4vmJc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/b650e4e2-070a-484d-b4b5-c8384427021d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/adde9b00-ae98-4c79-9d24-f1eecce039ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and all its topics, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/adde9b00-ae98-4c79-9d24-f1eecce039ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--Google Germany GmbH | Erika-Mann-Strasse | 80636 Muenchen | GermanyAG Hamburg, HRB 86891 | Sitz der Gesellschaft: Hamburg | Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
--
You received this message because you are subscribed to a topic in the Google Groups "bazel-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bazel-discuss/Nt4F-_4vmJc/unsubscribe.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CAMnS4ZCxdpbobgJX_jHJDC_yrQAZ6zuBVNMXL9BXCj1989wC0A%40mail.gmail.com.To unsubscribe from this group and all its topics, send an email to bazel-discuss+unsubscribe@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/346c8847-8478-4bdd-a593-bc0ed12411c7%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/346c8847-8478-4bdd-a593-bc0ed12411c7%40googlegroups.com.
Correction. It does work, I just had to set those dependencies on the py_binary, the actual target I was building. Operator error on my part. Not the worst workaround that I have dealt with, but I would have had no idea on how to fix it if it were not for your help.Now I need to figure out the py_image. It is not, apparently, a straight change of py_binary to py_image
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "bazel-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bazel-discuss/Nt4F-_4vmJc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/032e7993-475b-4986-904a-f00586372ba9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Diese E-Mail ist vertraulich. Falls sie diese fälschlicherweise erhalten haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter, löschen Sie alle Kopien und Anhänge davon und lassen Sie mich bitte wissen, dass die E-Mail an die falsche Person gesendet wurde.
This e-mail is confidential. If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it has gone to the wrong person.
> https://github.com/TriggerMail/rules_pyzI wrote Bazel's code for downloading files. See ed7ced0018dc5c5ebd6fc8afc7158037ac1df00d. It's designed to be carrier grade (see also). Why reinvent this?
> The thing I've had success with is writing my own rules, which generates a zip […]Here's a Skylark rule named zip_file() that generalizes zip file creation it Bazel. It has zero dependencies. The only thing it requires is Skylark and @bazel_tools//tools/zip:zipper (which comes included in Bazel). Here are examples of it being used to create App Engine deploy .war files, with web server assets.