forked from dell/karavi-authorization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
130 lines (116 loc) · 5.57 KB
/
Makefile
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
# Copyright © 2021-2023 Dell Inc., or its subsidiaries. All Rights Reserved.
#
# Licensed 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 CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
export DOCKER_TAG ?= 1.7.0
export SIDECAR_TAG ?= 1.7.0
# Get version and release from DOCKER_TAG
dot-delimiter = $(word $2,$(subst ., ,$1))
export VERSION = $(call dot-delimiter, ${DOCKER_TAG}, 1).$(call dot-delimiter, ${DOCKER_TAG}, 2)
export RELEASE = $(call dot-delimiter, ${DOCKER_TAG}, 3)
ifeq (${RELEASE},)
VERSION=1.7
RELEASE=0
endif
export VERSION_TAG ?= ${VERSION}-${RELEASE}
K3S_SELINUX_VERSION ?= 0.4-1
.PHONY: build
build:
-mkdir -p ./bin
cp Dockerfile ./bin/Dockerfile
CGO_ENABLED=0 go build -o ./bin ./cmd/proxy-server/
CGO_ENABLED=0 go build -o ./bin ./cmd/karavictl/
CGO_ENABLED=0 go build -o ./bin ./cmd/sidecar-proxy/
CGO_ENABLED=0 go build -o ./bin ./cmd/tenant-service/
CGO_ENABLED=0 go build -o ./bin ./cmd/role-service/
CGO_ENABLED=0 go build -o ./bin ./cmd/storage-service/
.PHONY: build-installer
build-installer:
# Requires dist artifacts
go build -tags=prod -o ./bin ./deploy/
.PHONY: rpm
rpm:
docker run --rm \
-e VERSION \
-e RELEASE \
-v $$PWD/deploy/rpm/pkg:/srv/pkg \
-v $$PWD/bin/deploy:/home/builder/rpm/deploy \
-v $$PWD/deploy/rpm:/home/builder/rpm \
rpmbuild/centos7
.PHONY: redeploy
redeploy: build docker
# proxy-server
docker save --output ./bin/proxy-server-$(DOCKER_TAG).tar proxy-server:$(DOCKER_TAG)
sudo /usr/local/bin/k3s ctr images import ./bin/proxy-server-$(DOCKER_TAG).tar
sudo /usr/local/bin/k3s kubectl set image -n karavi deploy/proxy-server proxy-server=proxy-server:$(DOCKER_TAG)
sudo /usr/local/bin/k3s kubectl rollout restart -n karavi deploy/proxy-server
# tenant-service
docker save --output ./bin/tenant-service-$(DOCKER_TAG).tar tenant-service:$(DOCKER_TAG)
sudo /usr/local/bin/k3s ctr images import ./bin/tenant-service-$(DOCKER_TAG).tar
sudo /usr/local/bin/k3s kubectl set image -n karavi deploy/tenant-service tenant-service=tenant-service:$(DOCKER_TAG)
sudo /usr/local/bin/k3s kubectl rollout restart -n karavi deploy/tenant-service
# storage-service
docker save --output ./bin/storage-service-$(DOCKER_TAG).tar storage-service:$(DOCKER_TAG)
sudo /usr/local/bin/k3s ctr images import ./bin/storage-service-$(DOCKER_TAG).tar
sudo /usr/local/bin/k3s kubectl set image -n karavi deploy/storage-service storage-service=storage-service:$(DOCKER_TAG)
sudo /usr/local/bin/k3s kubectl rollout restart -n karavi deploy/storage-service
# role-service
docker save --output ./bin/role-service-$(DOCKER_TAG).tar role-service:$(DOCKER_TAG)
sudo /usr/local/bin/k3s ctr images import ./bin/role-service-$(DOCKER_TAG).tar
sudo /usr/local/bin/k3s kubectl set image -n karavi deploy/role-service role-service=role-service:$(DOCKER_TAG)
sudo /usr/local/bin/k3s kubectl rollout restart -n karavi deploy/role-service
.PHONY: docker
docker: build
docker build -t proxy-server:$(DOCKER_TAG) --build-arg APP=proxy-server ./bin/.
docker build -t sidecar-proxy:$(SIDECAR_TAG) --build-arg APP=sidecar-proxy ./bin/.
docker build -t tenant-service:$(DOCKER_TAG) --build-arg APP=tenant-service ./bin/.
docker build -t role-service:$(DOCKER_TAG) --build-arg APP=role-service ./bin/.
docker build -t storage-service:$(DOCKER_TAG) --build-arg APP=storage-service ./bin/.
.PHONY: protoc
protoc:
protoc -I. \
--go_out=paths=source_relative:. ./pb/*.proto --go-grpc_out=paths=source_relative:. \
./pb/*.proto
.PHONY: dist
dist: docker dep
cd ./deploy/ && ./airgap-prepare.sh
curl -kL -o ./deploy/dist/microos-k3s-selinux.rpm https://rpm.rancher.io/k3s/latest/common/microos/noarch/k3s-selinux-${K3S_SELINUX_VERSION}.sle.noarch.rpm
curl -kL -o ./deploy/dist/centos7-k3s-selinux.rpm https://rpm.rancher.io/k3s/latest/common/centos/7/noarch/k3s-selinux-${K3S_SELINUX_VERSION}.el7.noarch.rpm
curl -kL -o ./deploy/dist/centos8-k3s-selinux.rpm https://rpm.rancher.io/k3s/latest/common/centos/8/noarch/k3s-selinux-${K3S_SELINUX_VERSION}.el8.noarch.rpm
.PHONY: dep
dep:
# Pulls third party docker.io images that we depend on.
for image in `grep "image: docker.io" deploy/deployment.yaml | awk -F' ' '{ print $$2 }' | xargs echo`; do \
docker pull $$image; \
done
.PHONY: distclean
distclean:
-rm -r ./deploy/dist
.PHONY: test
test: testopa
go test -count=1 -cover -race -timeout 30s -short ./...
.PHONY: testopa
testopa:
docker run --rm -it -v ${PWD}/policies:/policies/ openpolicyagent/opa test -v /policies/
.PHONY: package
package:
mkdir -p karavi_authorization_${DOCKER_TAG}
cp ./deploy/rpm/x86_64/karavi-authorization-${VERSION_TAG}.x86_64.rpm karavi_authorization_${DOCKER_TAG}/
cp ./deploy/dist/microos-k3s-selinux.rpm karavi_authorization_${DOCKER_TAG}/
cp ./deploy/dist/centos7-k3s-selinux.rpm karavi_authorization_${DOCKER_TAG}/
cp ./deploy/dist/centos8-k3s-selinux.rpm karavi_authorization_${DOCKER_TAG}/
cp ./scripts/install_karavi_auth.sh karavi_authorization_${DOCKER_TAG}/
cp ./scripts/traefik_nodeport.sh karavi_authorization_${DOCKER_TAG}/
cp -r ./policies karavi_authorization_${DOCKER_TAG}/
mkdir -p package
tar -czvf package/karavi_authorization_${DOCKER_TAG}.tar.gz karavi_authorization_${DOCKER_TAG}
rm -rf karavi_authorization_${DOCKER_TAG}