Push Apollo containers on push. Temporary solution

This commit is contained in:
Mustafa Gezen 2023-02-01 22:36:56 +00:00
parent 6d955c9925
commit 73655b78dc
9 changed files with 84 additions and 9 deletions

View File

@ -33,3 +33,5 @@ build:toplevel --config=inmemory
build:toplevel --experimental_remote_download_outputs=toplevel
build --stamp=true
build --workspace_status_command=build/stamp.sh
run --workspace_status_command=build/stamp.sh

25
.github/workflows/push_containers.yaml vendored Normal file
View File

@ -0,0 +1,25 @@
name: Push containers
on:
push:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: bazelbuild/setup-bazelisk@v2
- name: Mount bazel cache # Optional
uses: actions/cache@v3
with:
path: "~/.cache/bazel"
key: bazel
- name: Push containers
run: |
bazel run //apollo/server:server.push
bazel run //apollo/rpmworker:rpmworker.push
bazel run //apollo/rhworker:rhworker.push

View File

@ -142,6 +142,10 @@ 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()
# esbuild
http_archive(
name = "aspect_rules_esbuild",

View File

@ -1,8 +1,10 @@
load("@aspect_rules_py//py:defs.bzl", "py_binary", "py_library")
load("@aspect_rules_py//py:defs.bzl", "py_library")
load("//build/macros:pyimage.bzl", "pyimage")
py_binary(
pyimage(
name = "rhworker",
srcs = ["__main__.py"],
image_name = "apollo-rhworker",
imports = ["../.."],
main = "__main__.py",
visibility = ["//:__subpackages__"],

View File

@ -1,4 +1,5 @@
load("@aspect_rules_py//py:defs.bzl", "py_binary", "py_library")
load("@aspect_rules_py//py:defs.bzl", "py_library")
load("//build/macros:pyimage.bzl", "pyimage")
py_library(
name = "rpmworker_lib",
@ -20,8 +21,9 @@ py_library(
],
)
py_binary(
pyimage(
name = "rpmworker",
image_name = "apollo-rpmworker",
srcs = ["__main__.py"],
imports = ["../.."],
main = "__main__.py",

View File

@ -42,6 +42,7 @@ py_library(
fastapi_binary(
name = "server",
image_name = "apollo-server",
imports = ["../.."],
path = "apollo.server.server",
port = "9999",

View File

@ -1,6 +1,8 @@
load("@aspect_rules_py//py:defs.bzl", "py_binary")
load("@io_bazel_rules_docker//python3:image.bzl", "py3_image")
load("@io_bazel_rules_docker//container:container.bzl", "container_push")
def fastapi_binary(name, path, port, deps = [], tags = [], **kwargs):
def fastapi_binary(name, image_name, path, port, deps = [], tags = [], **kwargs):
py_binary(
name = name,
srcs = ["@pypi_hypercorn//:rules_python_wheel_entry_point_hypercorn.py"],
@ -16,10 +18,11 @@ def fastapi_binary(name, path, port, deps = [], tags = [], **kwargs):
**kwargs
)
py_binary(
name = "{}.prod".format(name),
py3_image(
name = "{}.image".format(name),
srcs = ["@pypi_hypercorn//:rules_python_wheel_entry_point_hypercorn.py"],
args = ["{}:app".format(path), "--reload", "--bind 127.0.0.1:{}".format(port)],
main = "@pypi_hypercorn//:rules_python_wheel_entry_point_hypercorn.py",
args = ["{}:app".format(path), "--bind 127.0.0.1:{}".format(port)],
visibility = ["//:__subpackages__"],
deps = deps + [
":{}_lib".format(name),
@ -30,3 +33,13 @@ def fastapi_binary(name, path, port, deps = [], tags = [], **kwargs):
],
**kwargs
)
container_push(
name = "{}.push".format(name),
format = "Docker",
image = ":{}.image".format(name),
registry = "ghcr.io",
repository = "resf/{}".format(image_name),
tag = "{BUILD_TAG}",
visibility = ["//visibility:public"],
)

22
build/macros/pyimage.bzl Normal file
View File

@ -0,0 +1,22 @@
load("@aspect_rules_py//py:defs.bzl", "py_binary")
load("@io_bazel_rules_docker//python3:image.bzl", "py3_image")
load("@io_bazel_rules_docker//container:container.bzl", "container_push")
def pyimage(name, image_name, **kwargs):
py_binary(
name = name,
**kwargs
)
py3_image(
name = "{}.image".format(name),
**kwargs
)
container_push(
name = "{}.push".format(name),
format = "Docker",
image = ":{}.image".format(name),
registry = "ghcr.io",
repository = "resf/{}".format(image_name),
tag = "{BUILD_TAG}",
visibility = ["//visibility:public"],
)

4
build/stamp.sh Executable file
View File

@ -0,0 +1,4 @@
#/usr/bin/env sh
cat<<EOF
BUILD_TAG ${GIT_COMMIT:-$(git describe --tags --long --always)}
EOF