Got docker push working
This commit is contained in:
parent
77a4545496
commit
b0d66f2929
2
.bazelrc
Normal file
2
.bazelrc
Normal file
|
@ -0,0 +1,2 @@
|
|||
build --incompatible_use_python_toolchains
|
||||
test --incompatible_use_python_toolchains
|
51
BUILD
51
BUILD
|
@ -1,9 +1,19 @@
|
|||
load("@io_bazel_rules_docker//container:container.bzl", "container_push")
|
||||
load(
|
||||
"@io_bazel_rules_docker//container:container.bzl",
|
||||
"container_image",
|
||||
"container_push",
|
||||
)
|
||||
#load("@docker_config//:push.bzl", my_container_push = "container_push")
|
||||
load(
|
||||
"@io_bazel_rules_docker//python3:image.bzl",
|
||||
"py3_image",
|
||||
)
|
||||
load("@rules_python//python:defs.bzl", "py_library", "py_test")
|
||||
load("@my_deps//:requirements.bzl", "requirement")
|
||||
|
||||
# python library with my website code
|
||||
py_library(
|
||||
name = "shillerben-homepage",
|
||||
name = "shillerben-homepage-lib",
|
||||
srcs = ["my_homepage/__init__.py"],
|
||||
data = glob(["my_homepage/templates/*"]),
|
||||
deps = [
|
||||
|
@ -17,21 +27,48 @@ py_library(
|
|||
]
|
||||
)
|
||||
|
||||
# test my website with pytest
|
||||
py_test(
|
||||
name = "website_test",
|
||||
main = "test_website.py",
|
||||
srcs = ["tests/test_website.py"],
|
||||
name = "website-test",
|
||||
main = "my_homepage/test/run_pytest.py",
|
||||
args = ["-s", "-v", "my_homepage"],
|
||||
srcs = [
|
||||
"my_homepage/test/run_pytest.py",
|
||||
"my_homepage/test/test_website.py",
|
||||
],
|
||||
deps = [
|
||||
":shillerben-homepage",
|
||||
":shillerben-homepage-lib",
|
||||
requirement("pytest"),
|
||||
],
|
||||
)
|
||||
|
||||
# custom base image layer to set envs and cmd
|
||||
container_image(
|
||||
name = "website-base-py3",
|
||||
base = "@py3_image_base//image",
|
||||
ports = ["4040"],
|
||||
)
|
||||
|
||||
py3_image(
|
||||
name = "shillerben-homepage-img",
|
||||
base = ":website-base-py3",
|
||||
main = "main/__main__.py",
|
||||
args = ["-b", "0.0.0.0:4040", "my_homepage:create_app()"],
|
||||
srcs = [
|
||||
"main/__main__.py",
|
||||
],
|
||||
deps = [
|
||||
":shillerben-homepage-lib",
|
||||
],
|
||||
)
|
||||
|
||||
# push new website image
|
||||
container_push(
|
||||
name = "push-image",
|
||||
image = ":shillerben-homepage",
|
||||
image = ":shillerben-homepage-img",
|
||||
format = "Docker",
|
||||
registry = "docker.shillerben.com",
|
||||
repository = "shillerben-homepage",
|
||||
tag = "latest",
|
||||
#extract_config = ":.docker-config.json",
|
||||
)
|
||||
|
|
50
WORKSPACE
50
WORKSPACE
|
@ -1,19 +1,6 @@
|
|||
#workspace("my-homepage")
|
||||
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
load("@rules_python//python:repositories.bzl", "python_register_toolchains")
|
||||
load("@python310//:defs.bzl", "interpreter")
|
||||
load("@rules_python//python:pip.bzl", "pip_install")
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
load("@io_bazel_rules_docker//toolchains/docker:toolchain.bzl",
|
||||
docker_toolchain_configure="toolchain_configure"
|
||||
)
|
||||
load(
|
||||
"@io_bazel_rules_docker//repositories:repositories.bzl",
|
||||
container_repositories = "repositories",
|
||||
)
|
||||
load("@io_bazel_rules_docker//repositories:deps.bzl", container_deps = "deps")
|
||||
|
||||
# Python stuff
|
||||
http_archive(
|
||||
name = "rules_python",
|
||||
sha256 = "b593d13bb43c94ce94b483c2858e53a9b811f6f10e1e0eedc61073bd90e58d9c",
|
||||
|
@ -21,28 +8,53 @@ http_archive(
|
|||
url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.12.0.tar.gz",
|
||||
)
|
||||
|
||||
load("@rules_python//python:repositories.bzl", "python_register_toolchains")
|
||||
load("@rules_python//python:pip.bzl", "pip_install")
|
||||
|
||||
python_register_toolchains(
|
||||
name = "python310",
|
||||
python_version = "3.10.6",
|
||||
name = "python39",
|
||||
python_version = "3.9.12",
|
||||
)
|
||||
|
||||
load("@python39//:defs.bzl", "interpreter")
|
||||
|
||||
pip_install(
|
||||
name = "my_deps",
|
||||
python_interpreter_target = interpreter,
|
||||
requirements = "//:requirements.txt"
|
||||
)
|
||||
|
||||
|
||||
# Docker stuff
|
||||
http_archive(
|
||||
name = "io_bazel_rules_docker",
|
||||
sha256 = "b1e80761a8a8243d03ebca8845e9cc1ba6c82ce7c5179ce2b295cd36f7e394bf",
|
||||
urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.25.0/rules_docker-v0.25.0.tar.gz"],
|
||||
)
|
||||
|
||||
docker_toolchain_configure(
|
||||
name = "docker_config",
|
||||
client_config = ":.docker-config.json",
|
||||
# load("@io_bazel_rules_docker//toolchains/docker:toolchain.bzl",
|
||||
# docker_toolchain_configure = "toolchain_configure"
|
||||
# )
|
||||
|
||||
# docker_toolchain_configure(
|
||||
# name = "docker_config",
|
||||
# client_config = "@//:.docker-config.json",
|
||||
# )
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_docker//repositories:repositories.bzl",
|
||||
container_repositories = "repositories",
|
||||
)
|
||||
|
||||
container_repositories()
|
||||
|
||||
load("@io_bazel_rules_docker//repositories:deps.bzl", container_deps = "deps")
|
||||
|
||||
container_deps()
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_docker//python3:image.bzl",
|
||||
_py_image_repos = "repositories",
|
||||
)
|
||||
|
||||
_py_image_repos()
|
||||
|
|
9
main/__main__.py
Executable file
9
main/__main__.py
Executable file
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from gunicorn.app.wsgiapp import run
|
||||
|
||||
run()
|
||||
# from my_homepage import create_app
|
||||
|
||||
# app = create_app()
|
||||
# app.run("0.0.0.0", "4040")
|
6
my_homepage/test/run_pytest.py
Normal file
6
my_homepage/test/run_pytest.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
import sys
|
||||
import pytest
|
||||
|
||||
# if using 'bazel test ...'
|
||||
if __name__ == "__main__":
|
||||
sys.exit(pytest.main(sys.argv[1:]))
|
Loading…
Reference in New Issue
Block a user