| load("@pydeps//:requirements.bzl", "requirement") |
| load("@rules_python//python:defs.bzl", "py_binary") |
| load("@io_bazel_rules_docker//python:image.bzl", "py_layer") |
| load("@io_bazel_rules_docker//python3:image.bzl", "py3_image") |
| load("@io_bazel_rules_docker//container:container.bzl", "container_image", "container_layer") |
| load("@io_bazel_rules_docker//docker/util:run.bzl", "container_run_and_commit_layer", "container_run_and_extract") |
| load("@io_bazel_rules_docker//docker/package_managers:download_pkgs.bzl", "download_pkgs") |
| load("@io_bazel_rules_docker//docker/package_managers:install_pkgs.bzl", "install_pkgs") |
| |
| # - - base docker stuff - - |
| |
| download_pkgs( |
| name = "apt_py_is_py3", |
| image_tar = "@python-debian//image", |
| packages = [ |
| # rules_docker python wants /usr/bin/python |
| "python-is-python3", |
| ], |
| ) |
| |
| install_pkgs( |
| name = "base_image", |
| image_tar = "@python-debian//image", |
| installables_tar = ":apt_py_is_py3.tar", |
| installation_cleanup_commands = "rm -rf /var/lib/apt/lists/* /usr/share/doc && apt remove -y libbluetooth3 mariadb-common tk && apt autoremove -y", |
| output_image_name = "base_image", |
| ) |
| |
| BASE_IMAGE = ":base_image" |
| |
| # overkill rube goldberg setup to build static files begins |
| # - - - - |
| |
| container_run_and_extract( |
| name = "static_pack", |
| commands = [ |
| "tar cpJvf /out.tar.xz -C /opt/mailman/web/static ./", |
| ], |
| extract_file = "/out.tar.xz", |
| image = ":static_build_image.tar", |
| ) |
| |
| container_image( |
| name = "static_build_image", |
| base = BASE_IMAGE, |
| layers = [":static_build_layer"], |
| ) |
| |
| # this will also contain .pyc files, but the python binary will be the same |
| # on prod, so it's fine |
| container_run_and_commit_layer( |
| name = "static_build_layer", |
| commands = [ |
| "./app/mailman-web/manage collectstatic", |
| "./app/mailman-web/manage compress", |
| # gettext is cursed, TODO make this work |
| #"./app/mailman-web/manage compilemessages", |
| ], |
| docker_run_flags = ["--entrypoint="], |
| image = ":build_container.tar", |
| ) |
| |
| py3_image( |
| name = "build_container", |
| srcs = [":manage"], |
| base = ":build_tools_container", |
| layers = [":deps_layer"], |
| main = "manage.py", |
| # this doesn't work for some reason - this is always rebuilt, unless |
| # you pass --nostamp globally |
| stamp = 0, |
| ) |
| |
| download_pkgs( |
| name = "build_tools", |
| image_tar = "@python-debian//image", |
| packages = [ |
| "gettext", |
| "sassc", |
| ], |
| ) |
| |
| install_pkgs( |
| name = "build_tools_container", |
| image_tar = BASE_IMAGE + ".tar", |
| installables_tar = ":build_tools.tar", |
| installation_cleanup_commands = "rm -rf /var/lib/apt/lists/* /usr/share/doc", |
| output_image_name = "build_tools_container", |
| ) |
| |
| # - - - - |
| # overkill rube goldberg setup to build static files ends |
| |
| # - - python stuff - - |
| |
| # this is purely a build optimization - put the pip deps into a separate layer |
| py_layer( |
| name = "deps_layer", |
| deps = [ |
| requirement("Django"), |
| requirement("postorius"), |
| requirement("hyperkitty"), |
| requirement("gunicorn"), |
| requirement("psycopg2-binary"), |
| ], |
| ) |
| |
| py_library( |
| name = "django_base", |
| srcs = [ |
| "settings.py", |
| "urls.py", |
| ] + glob([ |
| "upstream_settings/*.py", |
| ]), |
| deps = [ |
| requirement("Django"), |
| requirement("postorius"), |
| requirement("hyperkitty"), |
| requirement("gunicorn"), |
| requirement("psycopg2-binary"), |
| ], |
| ) |
| |
| py_binary( |
| name = "manage", |
| srcs = ["manage.py"], |
| deps = [":django_base"], |
| ) |
| |
| py_binary( |
| name = "serve", |
| srcs = ["serve.py"], |
| deps = [":django_base"], |
| ) |
| |
| # prod docker image |
| |
| py3_image( |
| name = "mailman-web", |
| srcs = ["container_main.py"], |
| #base = ":base_container" |
| base = ":static_build_image", |
| layers = [ |
| ":deps_layer", |
| ], |
| main = "container_main.py", |
| deps = [ |
| ":django_base", |
| ":manage", |
| ":serve", |
| ], |
| ) |