-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathBUILD.bazel
105 lines (91 loc) · 3.2 KB
/
BUILD.bazel
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
# Copyright 2020 Adobe. All rights reserved.
# Copyright 2023 rules_gitops authors. All rights reserved.
# This file is licensed to you under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. You may obtain a copy
# of the License at http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
# OF ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
load("@rules_gitops//gitops:defs.bzl", "k8s_deploy", "k8s_test_setup")
load("@rules_gitops//lang:go.bzl", "go_image")
go_library(
name = "go_default_library",
srcs = ["helloworld.go"],
importpath = "github.com/fasterci/rules_gitops/examples/helloworld",
visibility = ["//visibility:private"],
)
go_test(
name = "go_default_test",
srcs = ["helloworld_test.go"],
embed = [":go_default_library"],
)
go_binary(
name = "helloworld",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)
go_image(
name = "image",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)
DEV = "gke_rules-gitops-demo_us-central1_cluster-demo"
PROD_WEST = "gke_rules-gitops-demo_us-west1_cluster-demo"
PROD_CENTRAL = "gke_rules-gitops-demo_us-central1_cluster-demo"
PROD_EAST = "gke_rules-gitops-demo_us-east1_cluster-demo"
REGISTRY = "us-central1-docker.pkg.dev/rules-gitops-demo/it"
[
k8s_deploy(
name = NAME,
cluster = CLUSTER,
configmaps_srcs = glob([
"configmaps/%s/**/*" % ENVTYPE,
]),
deployment_branch = ENVTYPE,
gitops = (NAME != "mynamespace"),
image_registry = REGISTRY, # hide the registry in macro wrapping k8s_deploy
images = [":image"],
manifests = glob([
"manifests/*.yaml",
"manifests/{}/*.yaml".format(ENVTYPE),
]),
namespace = NAMESPACE,
patches = glob([
"overlays/{}/*.yaml".format(ENVTYPE),
]),
secrets_srcs = glob([
"secrets/{}/*.yaml".format(ENVTYPE),
]),
)
for (NAME, ENVTYPE, CLUSTER, NAMESPACE) in (
("mynamespace", "dev", DEV, None),
("dev", "dev", DEV, "helloteam"),
("canary", "prod", PROD_CENTRAL, "helloteam_canary"),
("prod_west", "prod", PROD_WEST, "helloteam"),
("prod_central", "prod", PROD_CENTRAL, "helloteam"),
("prod_east", "prod", PROD_EAST, "helloteam"),
)
]
k8s_test_setup(
name = "hello_server_it.setup",
cluster = "@k8s_test//:cluster",
kubeconfig = "@k8s_test//:kubeconfig",
kubectl = "@k8s_test//:kubectl",
objects = [
":mynamespace",
],
)
go_test(
name = "hello_server_it",
size = "large",
srcs = ["helloworld_it_test.go"],
args = [
"-setup",
"$(location :hello_server_it.setup)",
],
data = [":hello_server_it.setup"],
rundir = ".",
deps = ["@rules_gitops//client:go_default_library"],
)