Skip to content

Commit 55ddf06

Browse files
committed
Add makefile
1 parent 86933f4 commit 55ddf06

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed

pkg/quarkus/v1alpha/scaffolds/init.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,9 @@ func (s *initScaffolder) Scaffold() error {
7575
&templates.ApplicationPropertiesFile{
7676
ProjectName: s.config.GetProjectName(),
7777
},
78+
&templates.Makefile{
79+
Image: "",
80+
KustomizeVersion: "v3.5.4",
81+
},
7882
)
7983
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// Copyright 2021 The Operator-SDK Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package templates
16+
17+
import (
18+
"errors"
19+
20+
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
21+
)
22+
23+
var _ machinery.Template = &Makefile{}
24+
25+
// Makefile scaffolds the Makefile
26+
type Makefile struct {
27+
machinery.TemplateMixin
28+
29+
// Image is controller manager image name
30+
Image string
31+
32+
// Kustomize version to use in the project
33+
KustomizeVersion string
34+
35+
// // AnsibleOperatorVersion is the version of the ansible-operator binary downloaded by the Makefile.
36+
// AnsibleOperatorVersion string
37+
}
38+
39+
// SetTemplateDefaults implements machinery.Template
40+
func (f *Makefile) SetTemplateDefaults() error {
41+
if f.Path == "" {
42+
f.Path = "Makefile"
43+
}
44+
45+
f.TemplateBody = makefileTemplate
46+
47+
f.IfExistsAction = machinery.Error
48+
49+
if f.Image == "" {
50+
f.Image = "controller:latest"
51+
}
52+
53+
if f.KustomizeVersion == "" {
54+
return errors.New("kustomize version is required in scaffold")
55+
}
56+
57+
// if f.AnsibleOperatorVersion == "" {
58+
// return errors.New("ansible-operator version is required in scaffold")
59+
// }
60+
61+
return nil
62+
}
63+
64+
const makefileTemplate = `
65+
# Image URL to use all building/pushing image targets
66+
IMG ?= {{ .Image }}
67+
68+
all: docker-build
69+
70+
##@ General
71+
72+
# The help target prints out all targets with their descriptions organized
73+
# beneath their categories. The categories are represented by '##@' and the
74+
# target descriptions by '##'. The awk commands is responsible for reading the
75+
# entire set of makefiles included in this invocation, looking for lines of the
76+
# file as xyz: ## something, and then pretty-format the target and help. Then,
77+
# if there's a line with ##@ something, that gets pretty-printed as a category.
78+
# More info on the usage of ANSI control characters for terminal formatting:
79+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
80+
# More info on the awk command:
81+
# http://linuxcommand.org/lc3_adv_awk.php
82+
83+
help: ## Display this help.
84+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
85+
86+
##@ Build
87+
88+
# run: ansible-operator ## Run against the configured Kubernetes cluster in ~/.kube/config
89+
# $(ANSIBLE_OPERATOR) run
90+
91+
docker-build: ## Build docker image with the manager.
92+
mvn package -Dquarkus.container-image.build=true -Dquarkus.container-image.image=${IMG}
93+
94+
docker-push: ## Push docker image with the manager.
95+
mvn package -Dquarkus.container-image.push=true -Dquarkus.container-image.image=${IMG}
96+
97+
##@ Deployment
98+
99+
install: kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
100+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
101+
102+
uninstall: kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
103+
$(KUSTOMIZE) build config/crd | kubectl delete -f -
104+
105+
deploy: ## Deploy controller to the K8s cluster specified in ~/.kube/config.
106+
kubectl apply -f target/kubernetes/kubernetes.yml
107+
108+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
109+
kubectl delete -f target/kubernetes/kubernetes.yml
110+
111+
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
112+
ARCH := $(shell uname -m | sed 's/x86_64/amd64/')
113+
114+
.PHONY: kustomize
115+
KUSTOMIZE = $(shell pwd)/bin/kustomize
116+
kustomize: ## Download kustomize locally if necessary.
117+
ifeq (,$(wildcard $(KUSTOMIZE)))
118+
ifeq (,$(shell which kustomize 2>/dev/null))
119+
@{ \
120+
set -e ;\
121+
mkdir -p $(dir $(KUSTOMIZE)) ;\
122+
curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/{{ .KustomizeVersion }}/kustomize_{{ .KustomizeVersion }}_$(OS)_$(ARCH).tar.gz | \
123+
tar xzf - -C bin/ ;\
124+
}
125+
else
126+
KUSTOMIZE = $(shell which kustomize)
127+
endif
128+
endif
129+
`

0 commit comments

Comments
 (0)