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

feat: Build bunq2ynab image with nix and Bazel #544

Merged
merged 92 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
0982817
Try building docker base image with nix
mvgijssel Sep 21, 2023
f7f4975
Really hacky working python image
mvgijssel Sep 25, 2023
0acd1e8
Undo some changes
mvgijssel Sep 26, 2023
b6278f5
use custom docker image
mvgijssel Sep 26, 2023
34c77c4
fix for rbe
mvgijssel Sep 26, 2023
fbe1e23
Merge branch 'master' of github.com:mvgijssel/setup into mg/451/try-b…
mvgijssel Sep 26, 2023
1aad121
ensure nix exists
mvgijssel Sep 26, 2023
d08067b
without systemd
mvgijssel Sep 26, 2023
3edb00a
better
mvgijssel Sep 26, 2023
414b87b
add debugging
mvgijssel Sep 26, 2023
c2947ef
more debugging
mvgijssel Sep 26, 2023
642d9f9
hacky hacky
mvgijssel Sep 26, 2023
cc2a648
try local nix-build binary
mvgijssel Sep 26, 2023
39961c2
try nix-portable
mvgijssel Sep 26, 2023
8922b65
update
mvgijssel Sep 26, 2023
74b2500
completely uninstall
mvgijssel Sep 26, 2023
2b95292
try
mvgijssel Sep 26, 2023
24c9ec2
try
mvgijssel Sep 26, 2023
05d00f7
try
mvgijssel Sep 26, 2023
4dab466
more debugging
mvgijssel Sep 26, 2023
231d334
use proot
mvgijssel Sep 26, 2023
b36c172
use sudo?
mvgijssel Sep 26, 2023
2895e73
Merge branch 'master' into mg/451/try-building-docker-with-nix
mvgijssel Oct 8, 2023
9f5269d
Try something new
mvgijssel Oct 8, 2023
21b72cc
Remove sudo
mvgijssel Oct 8, 2023
9c69d3a
Add debugging
mvgijssel Oct 8, 2023
4905767
check if docker exists
mvgijssel Oct 8, 2023
5d99f27
Try to use docker proxy
mvgijssel Oct 8, 2023
340eeb1
Make it work
mvgijssel Oct 8, 2023
819860b
Again use installer
mvgijssel Oct 8, 2023
b16247e
More debugging
mvgijssel Oct 8, 2023
bc0e42f
debug
mvgijssel Oct 8, 2023
78da3a3
root
mvgijssel Oct 8, 2023
740cbcd
find
mvgijssel Oct 8, 2023
d59c1b8
Try even more
mvgijssel Oct 8, 2023
04f01b9
where is the binary
mvgijssel Oct 8, 2023
06045ea
Try
mvgijssel Oct 8, 2023
4f600d3
try
mvgijssel Oct 8, 2023
e16a1ac
more
mvgijssel Oct 8, 2023
2e54806
use regular nix-build
mvgijssel Oct 8, 2023
92fde7b
make global available
mvgijssel Oct 8, 2023
b2bc902
remove proper
mvgijssel Oct 8, 2023
ae47272
chown
mvgijssel Oct 8, 2023
c1f1fa0
recursive
mvgijssel Oct 8, 2023
019c4cd
Use different architecture
mvgijssel Oct 8, 2023
12f1d35
cleanup
mvgijssel Oct 8, 2023
4da13a7
Merge branch 'master' of github.com:vgijssel/setup into mg/451/try-bu…
mvgijssel Oct 8, 2023
5fad461
Working local image
mvgijssel Oct 8, 2023
4e3a3d4
Setup basic image test
mvgijssel Oct 8, 2023
2e04aa4
Pick right architecture
mvgijssel Oct 8, 2023
599d6f4
basic python image
mvgijssel Oct 8, 2023
2d8b3d9
Working docker image test
mvgijssel Oct 19, 2023
3749c96
fix buildbuddy
mvgijssel Oct 19, 2023
8780b92
Extra debugging
mvgijssel Oct 19, 2023
06bf8b6
better way to archive py_binary with aspect rule
mvgijssel Oct 19, 2023
182591d
Update rule a little bit
mvgijssel Oct 19, 2023
60d710f
Merge branch 'master' into mg/451/try-building-docker-with-nix
mvgijssel Oct 25, 2023
a9f505c
cleanup
mvgijssel Oct 25, 2023
6956856
Lint js files
mvgijssel Oct 25, 2023
a93db87
Update prettier
mvgijssel Oct 25, 2023
243199e
Working test
mvgijssel Oct 25, 2023
5fad6f0
WIP py_image
mvgijssel Oct 25, 2023
ca583cb
Implement py_image macro
mvgijssel Oct 26, 2023
3f677b2
Setup proper Python platform for container
mvgijssel Oct 26, 2023
8e46557
Almost working
mvgijssel Oct 26, 2023
365cb5d
hacky but working
mvgijssel Oct 26, 2023
387152f
Without transitioned binary
mvgijssel Oct 26, 2023
754be70
Setup proper python container platform
mvgijssel Oct 26, 2023
46463e6
Cleanup
mvgijssel Oct 26, 2023
4a7e4c3
Use higher python version
mvgijssel Oct 26, 2023
cbd6a35
Fix list user test
mvgijssel Oct 26, 2023
517f3b0
Merge branch 'master' of github.com:vgijssel/setup into mg/451/try-bu…
mvgijssel Oct 26, 2023
2ca4317
Make it work on macOS
mvgijssel Oct 26, 2023
5a1a6b2
Working local bunq2ynab image
mvgijssel Oct 26, 2023
2c04e5f
Working cross compile
mvgijssel Oct 26, 2023
d109f77
rename python
mvgijssel Oct 26, 2023
75853dd
Fix requirement helper
mvgijssel Oct 26, 2023
bfd61e4
Try pip downloader somoe more
mvgijssel Oct 28, 2023
7c8c009
Try setup pycross with pdm
mvgijssel Oct 28, 2023
6ee88a6
Created "pdm-setup_lock.bzl" file
mvgijssel Oct 29, 2023
03ab85b
Use pycross for python requirements
mvgijssel Oct 29, 2023
0aac124
Download arm64 wheels instead of building
mvgijssel Oct 29, 2023
d8645d9
Download wheel for home assistant bluetooth for amd64
mvgijssel Oct 29, 2023
359a4e4
Fix building sdists
mvgijssel Oct 29, 2023
f2381b7
Working //occupancy_component:test build
mvgijssel Oct 29, 2023
ac3f155
Fix building docker image with tar
mvgijssel Oct 30, 2023
7ac0edd
Cleanup
mvgijssel Oct 30, 2023
62feb1b
Remove dependencies
mvgijssel Oct 30, 2023
e5e3d4b
Remove packages from base image
mvgijssel Oct 30, 2023
d118cbf
Setup diff test
mvgijssel Oct 30, 2023
3c7f21b
More cleanup
mvgijssel Oct 30, 2023
53d5500
Merge branch 'master' into mg/451/try-building-docker-with-nix
mvgijssel Oct 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.3.2
6.4.0
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": false
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"editor.defaultFormatter": "ms-azuretools.vscode-docker"
},
"python.formatting.provider": "none",
"devbox.autoShellOnTerminal": false
"devbox.autoShellOnTerminal": true,
"nix.enableLanguageServer": false
}
179 changes: 159 additions & 20 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@rules_task//tools:defs.bzl", "compile_pip_requirements")
load("@rules_task//:defs.bzl", "cmd", "task")
load(
"@jvolkman_rules_pycross//pycross:defs.bzl",
"pycross_lock_file",
"pycross_pdm_lock_model",
"pycross_target_environment",
)
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")

package(default_visibility = ["//visibility:public"])

Expand All @@ -17,38 +24,170 @@ config_setting(
},
)

sh_binary(
name = "setup_ci",
srcs = [
"setup_ci.sh",
],
)

_darwin_arm64 = [
"@platforms//os:macos",
"@platforms//cpu:arm64",
]

_linux_amd64 = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
]

_linux_arm64 = [
"@platforms//os:linux",
"@platforms//cpu:arm64",
]

config_setting(
name = "is_linux_amd64",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
constraint_values = _linux_amd64,
)

config_setting(
name = "is_linux_arm64",
constraint_values = [
"@platforms//cpu:aarch64",
"@platforms//os:linux",
],
constraint_values = _linux_arm64,
)

config_setting(
name = "is_darwin_arm64",
constraint_values = [
"@platforms//cpu:aarch64",
"@platforms//os:macos",
constraint_values = _darwin_arm64,
)

platform(
name = "darwin_arm64",
constraint_values = _darwin_arm64,
)

platform(
name = "linux_x86_64",
constraint_values = _linux_amd64,
)

platform(
name = "linux_arm64",
constraint_values = _linux_arm64,
)

pycross_target_environment(
name = "python_darwin_arm64",
abis = ["cp310"],
platforms = [
"macosx_12_0_arm64",
"macosx_13_0_arm64",
"macosx_14_0_arm64",
],
python_compatible_with = _darwin_arm64,
version = "3.10.13",
)

pycross_target_environment(
name = "python_linux_amd64",
abis = ["cp310"],
platforms = [
"linux_x86_64",
"manylinux2014_x86_64",
] + [
"manylinux_2_%s_x86_64" % str(i)
for i in range(17, 35)
],
python_compatible_with = _linux_amd64,
version = "3.10.13",
)

pycross_target_environment(
name = "python_linux_arm64",
abis = ["cp310"],
platforms = [
"linux_aarch64",
"manylinux2014_aarch64",
] + [
"manylinux_2_%s_aarch64" % str(i)
for i in range(17, 35)
],
python_compatible_with = _linux_arm64,
version = "3.10.13",
)

pycross_pdm_lock_model(
name = "pdm-setup_lock_model",
dev = True,
groups = [
"default",
],
lock_file = "pdm.lock",
project_file = "pyproject.toml",
)

compile_pip_requirements(
name = "requirements",
extra_args = [
"--allow-unsafe",
pycross_lock_file(
name = "pdm-setup_lock",
out = "pdm-setup_lock_gen.bzl",
default_alias_single_version = True,
lock_model_file = ":pdm-setup_lock_model",
package_build_dependencies = {
"ulid-transform": [
"wheel",
"setuptools",
"poetry-core",
],
"python-slugify": [
"wheel",
"setuptools",
],
"mock-open": [
"wheel",
"setuptools",
],
"lru-dict": [
"wheel",
"setuptools",
"poetry-core",
],
"pytest-test-groups": [
"wheel",
"setuptools",
],
"colored": [
"wheel",
"setuptools",
],
"paho-mqtt": [
"wheel",
"setuptools",
],
"home-assistant-bluetooth": [
"wheel",
"setuptools",
"poetry-core",
],
},
pypi_index = "https://pypi.org",
target_environments = [
":python_darwin_arm64",
":python_linux_amd64",
":python_linux_arm64",
],
hidden_args = [
"--verbose",
)

task(
name = "pdm-setup.update",
cmds = [
"cp -fv $LOCK_FILE $BUILD_WORKSPACE_DIRECTORY/pdm-setup_lock.bzl",
],
requirements_in = "requirements.in",
requirements_txt = "requirements.txt",
env = {
"LOCK_FILE": cmd.file(":pdm-setup_lock"),
},
)

diff_test(
name = "pdm-setup_test",
file1 = "pdm-setup_lock.bzl",
file2 = ":pdm-setup_lock",
)
18 changes: 9 additions & 9 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ module(
version = "1.0",
)

# It's important that this toolchain is registered before the toolchains from rules_python
# so this one can be picked when we run Python inside a container.
register_toolchains(
"//tools/python:python_container_py_toolchain",
)

# ------------------------------------ platforms ------------------------------------ #
bazel_dep(name = "platforms", version = "0.0.8")

# ------------------------------------ rules_skylib ------------------------------------ #
bazel_dep(name = "bazel_skylib", version = "1.4.2")
bazel_dep(name = "aspect_bazel_lib", version = "2.0.0-rc1")

# ------------------------------------ rules_pkg ------------------------------------ #
bazel_dep(name = "rules_pkg", version = "0.9.1")
Expand All @@ -38,12 +45,5 @@ python.toolchain(

use_repo(python, "python_versions")

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")

pip.parse(
hub_name = "pip-setup",
python_version = "3.10",
requirements_lock = "//:requirements.txt",
)

use_repo(pip, "pip-setup")
# ------------------------------------ rules_oci ------------------------------------ #
bazel_dep(name = "rules_oci", version = "1.4.0")
64 changes: 64 additions & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,39 @@ container_pull(
repository = "library/python:3.10.8-bullseye",
)

# ------------------------------------ rules_pycross ------------------------------------ #
http_archive(
name = "jvolkman_rules_pycross",
sha256 = "5b51cfa4890d6de29b6a0976248e8139f69354bf29924308093a039d93ab630f",
strip_prefix = "rules_pycross-0.2",
url = "https://github.com/jvolkman/rules_pycross/archive/refs/tags/v0.2.tar.gz",
)

load("@jvolkman_rules_pycross//pycross:repositories.bzl", "rules_pycross_dependencies")
load("@rules_python~0.25.0~python~pythons_hub//:interpreters.bzl", "INTERPRETER_LABELS")

# This is necessary to get the hermetic interpreter which is defined in MODULE.bazel
# This would be simpler if rules_pycross would also use bzlmod.
interpreter_internal_target = INTERPRETER_LABELS["python_3_10"]

interpreter_target = "@rules_python~0.25.0~python~{}//:{}".format(
interpreter_internal_target.workspace_name,
interpreter_internal_target.name,
)

rules_pycross_dependencies(python_interpreter_target = interpreter_target)

load("@jvolkman_rules_pycross//pycross:defs.bzl", "pycross_lock_repo")

pycross_lock_repo(
name = "pdm-setup",
lock_file = "//:pdm-setup_lock.bzl",
)

load("@pdm-setup//:requirements.bzl", "install_deps")

install_deps()

# ------------------------------------ workstation ------------------------------------ #

# https://hub.docker.com/layers/library/ubuntu/jammy-20230425/images/sha256-ca5534a51dd04bbcebe9b23ba05f389466cf0c190f1f8f182d7eea92a9671d00?context=explore
Expand Down Expand Up @@ -262,3 +295,34 @@ git_repository(
# build_file = "//tools/bunq2ynab:BUILD.repositories.bazel.tpl",
# path = "/workspaces/bunq2ynab",
# )

# ------------------------------------ rules_nixpkgs ------------------------------------ #

http_archive(
name = "io_tweag_rules_nixpkgs",
sha256 = "b01f170580f646ee3cde1ea4c117d00e561afaf3c59eda604cf09194a824ff10",
strip_prefix = "rules_nixpkgs-0.9.0",
urls = ["https://github.com/tweag/rules_nixpkgs/archive/refs/tags/v0.9.0.tar.gz"],
)

load("@io_tweag_rules_nixpkgs//nixpkgs:repositories.bzl", "rules_nixpkgs_dependencies")

rules_nixpkgs_dependencies()

load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_git_repository", "nixpkgs_package")

nixpkgs_git_repository(
name = "nixpkgs",
revision = "23.05", # Any tag or commit hash
sha256 = "", # optional sha to verify package integrity!
)

nixpkgs_package(
name = "python310_base_image",
build_file_content = """
package(default_visibility = [ "//visibility:public" ])
exports_files(["image.tar.gz"])
""",
nix_file = "//:python310_base_image.nix",
repository = "@nixpkgs//:default.nix",
)
1 change: 1 addition & 0 deletions buildbuddy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ actions:
branches:
- "*"
bazel_commands:
- bazel run //:setup_ci
- bazel test --keep_going //... @rules_task//... --config buildbuddy --config buildbuddy_rbe
9 changes: 6 additions & 3 deletions devbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]"
"[email protected]",
"[email protected]",
"libarchive@latest",
"[email protected]",
"[email protected]"
],
"shell": {
"init_hook": ["alias bazel='bazelisk'"],
"scripts": {}
"init_hook": ["alias bazel='bazelisk'", "export PATH=$HOME/bin:$PATH"]
}
}
Loading