-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMODULE.bazel
More file actions
162 lines (136 loc) · 5.8 KB
/
MODULE.bazel
File metadata and controls
162 lines (136 loc) · 5.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
"""Attic IaC - Bazel Module Configuration
Generic infrastructure-as-code modules, SvelteKit app, and build rules.
Bazel handles validation, artifact bundling, and toolchain management.
Nix handles binary builds and container images via rules_nixpkgs.
This module can be consumed by downstream Bazel modules via bazel_dep().
"""
module(
name = "attic-iac",
version = "0.1.0",
)
# =============================================================================
# Core Bazel Rules
# =============================================================================
bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "rules_pkg", version = "1.1.0")
bazel_dep(name = "rules_python", version = "1.4.1")
bazel_dep(name = "rules_shell", version = "0.6.0")
bazel_dep(name = "platforms", version = "0.0.10")
# Allow rules_python hermetic interpreter to run as root (CI containers)
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
ignore_root_user_error = True,
python_version = "3.11",
)
# =============================================================================
# JavaScript / TypeScript Rules (aspect_rules_js)
# =============================================================================
# SvelteKit app build pipeline via pnpm + Vite
bazel_dep(name = "aspect_rules_js", version = "2.9.2")
bazel_dep(name = "aspect_rules_ts", version = "3.8.3")
bazel_dep(name = "aspect_bazel_lib", version = "2.22.5")
bazel_dep(name = "rules_nodejs", version = "6.7.3")
# =============================================================================
# pnpm / npm Integration
# =============================================================================
# Translate pnpm-lock.yaml into Bazel-managed node_modules
npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True)
npm.npm_translate_lock(
name = "npm",
pnpm_lock = "//:pnpm-lock.yaml",
verify_node_modules_ignored = ".bazelignore",
)
use_repo(npm, "npm")
# Node.js toolchain (from rules_nodejs)
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node", dev_dependency = True)
node.toolchain(
name = "nodejs",
node_version = "22.13.1",
)
# =============================================================================
# Container Image Rules (rules_img)
# =============================================================================
# OCI container image building: layer creation, manifest assembly, and push.
# Used alongside Nix container builds (nix2container) for the Dashboard image.
bazel_dep(name = "rules_img", version = "0.3.4")
img = use_extension("@rules_img//img:extensions.bzl", "img")
img.pull(
name = "node22_alpine",
registry = "docker.io",
repository = "library/node",
tag = "22-alpine",
platforms = ["linux/amd64"],
)
use_repo(img, "node22_alpine")
# =============================================================================
# rules_nixpkgs - Nix Toolchain Integration
# =============================================================================
# Provides reproducible toolchains from Nix for Bazel builds.
# All build tools come from the flake.nix, ensuring consistency with
# NixOS/nix-darwin/devShell environments.
bazel_dep(name = "rules_nixpkgs_core", version = "0.13.0")
# Language-specific Nix toolchain rules (add as needed)
# bazel_dep(name = "rules_nixpkgs_cc", version = "0.13.0")
# bazel_dep(name = "rules_nixpkgs_go", version = "0.13.0")
# bazel_dep(name = "rules_nixpkgs_python", version = "0.13.0")
# bazel_dep(name = "rules_nixpkgs_rust", version = "0.13.0")
# =============================================================================
# Nix Repository Configuration
# =============================================================================
# Configure nixpkgs from the flake.lock for reproducibility
nix_repo = use_extension("@rules_nixpkgs_core//nixpkgs:extensions.bzl", "nix_repo")
# Use the project's flake.lock as the Nix source
nix_repo.file(
name = "nixpkgs",
file = "//:flake.lock",
file_deps = ["//:flake.nix"],
)
use_repo(nix_repo, "nixpkgs")
# =============================================================================
# Nix Package Imports
# =============================================================================
# Import specific packages from nixpkgs for use in Bazel rules
nix_pkg = use_extension("@rules_nixpkgs_core//nixpkgs:extensions.bzl", "nix_pkg")
# OpenTofu for module validation
nix_pkg.package(
name = "tofu",
attribute_path = "opentofu",
repository = "@nixpkgs",
)
# kubectl for K8s manifest validation
nix_pkg.package(
name = "kubectl",
attribute_path = "kubectl",
repository = "@nixpkgs",
)
# yq for YAML processing
nix_pkg.package(
name = "yq",
attribute_path = "yq-go",
repository = "@nixpkgs",
)
use_repo(nix_pkg, "kubectl", "tofu", "yq")
# =============================================================================
# Build Configuration Notes
# =============================================================================
#
# This module supports both IaC validation and the Runner Dashboard app.
# Binary builds (Attic server) are handled by Nix:
# - nix build .#attic
# - nix build .#container
#
# Container images can be built via rules_img (OCI) or Nix (nix2container):
# - bazel build //app:image (rules_img)
# - bazel run //app:push (push to GHCR)
# - nix build .#runner-dashboard-image
#
# Bazel focuses on:
# 1. Validating OpenTofu modules (//tofu/modules:all_validate)
# 2. Checking file formatting (//tofu/modules:all_fmt_test)
# 3. Bundling deployment artifacts (//:deployment_bundle)
# 4. Running configuration tests (//tests:*)
# 5. Building the Runner Dashboard SvelteKit app (//app:build)
# 6. Building OCI container images (//app:image)
#
# Remote caching via bazel-remote (when deployed):
# bazel build --config=ci-cached //...