-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
73 lines (68 loc) · 2.65 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
VERSION := 0.3.3
TAG := v$(VERSION)
REGISTRY ?= quay.io
ORG ?= rh-nfv-int
CONTAINER_CLI ?= podman
CLUSTER_CLI ?= oc
INDEX_NAME := nfv-example-cnf-catalog
INDEX_IMG ?= $(REGISTRY)/$(ORG)/$(INDEX_NAME):$(TAG)
BUILD_PATH ?= ./build
OPM_VERSION ?= latest
OPM_REPO ?= https://github.com/operator-framework/operator-registry
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m | sed 's/x86_64/amd64/')
OPERATORS_LIST := operators.cfg
SHELL := /bin/bash
all: index-build index-push
# Clean up
clean:
@rm -rf $(BUILD_PATH)
# Build the index image
index-build: opm
@{ \
set -e ;\
mkdir -p $(BUILD_PATH)/$(INDEX_NAME) ;\
cp "$(INDEX_NAME).Dockerfile" $(BUILD_PATH)/ ;\
source ./$(OPERATORS_LIST) ;\
for OPERATOR in $${OPERATORS[@]}; do \
operator_bundle=$${OPERATOR/:*}-bundle ;\
operator_version=$${OPERATOR/*:} ;\
operator_name=$${OPERATOR/:*} ;\
operator_manifest=$$(skopeo inspect docker://$(REGISTRY)/$(ORG)/$${operator_bundle}:$${operator_version}) ;\
operator_digest=$$(jq -r '.Digest' <<< $${operator_manifest}) ;\
bundle_digest=$(REGISTRY)/$(ORG)/$${operator_bundle}@$${operator_digest} ;\
echo "operator = $${operator_name}, operator_digest = $${operator_digest}" ;\
default_channel=$$(jq -r '.Labels."operators.operatorframework.io.bundle.channel.default.v1"' <<< $${operator_manifest}) ;\
channel="---\nschema: olm.channel\npackage: $${operator_name}\nname: $${default_channel}\nentries:\n - name: $${operator_name}.$${operator_version}" ;\
$(OPM) init $${operator_name} --default-channel=$${default_channel} --output=yaml >> $(BUILD_PATH)/$(INDEX_NAME)/index.yml ;\
$(OPM) render $${bundle_digest} --output=yaml >> $(BUILD_PATH)/$(INDEX_NAME)/index.yml ;\
echo -e $${channel} >> $(BUILD_PATH)/$(INDEX_NAME)/index.yml ;\
done ;\
echo "validating the catalog" ;\
$(OPM) validate $(BUILD_PATH)/$(INDEX_NAME) ;\
BUILDAH_FORMAT=docker podman build $(BUILD_PATH) -f $(BUILD_PATH)/$(INDEX_NAME).Dockerfile -t $(INDEX_IMG) ;\
rm -rf $(BUILD_PATH) ;\
}
# Push the index image
index-push:
$(CONTAINER_CLI) push $(INDEX_IMG)
# Installs opm if is not available
.PHONY: opm
OPM = $(shell pwd)/bin/opm
opm:
ifeq (,$(wildcard $(OPM)))
ifeq (,$(shell which opm 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(OPM)) ;\
OPM_TAG=v$(OPM_VERSION) ;\
if [[ $(OPM_VERSION) == "latest" ]]; then \
OPM_TAG=$$(curl -sI $(OPM_REPO)/releases/latest | awk '/^location:/ {print $$2}' | xargs basename | tr -d '\r') ;\
fi ;\
curl -sLo $(OPM) $(OPM_REPO)/releases/download/$${OPM_TAG}/$(OS)-$(ARCH)-opm ;\
chmod u+x $(OPM) ;\
}
else
OPM=$(shell which opm)
endif
endif