Skip to content

Commit

Permalink
Add CI, docs, and tests
Browse files Browse the repository at this point in the history
Signed-off-by: Dale Haiducek <[email protected]>
  • Loading branch information
dhaiducek committed Dec 18, 2024
1 parent 1958194 commit 2b0046e
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
groups:
github-actions:
patterns:
- "*"
5 changes: 5 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"schedule": "before 8am on Monday",
"timezone": "America/New_York"
}
34 changes: 34 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Preflight Test

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
build:
name: Image build and test
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install OPM
run: |
make opm
- name: Validate catalog
run: |
make validate-catalog
- name: Build and verify image
run: |
make build-image
make run-image &
pid=$!
make test-image
make stop-image
wait ${pid}
77 changes: 77 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
LOCAL_BIN ?= $(PWD)/bin
export PATH := $(LOCAL_BIN):$(PATH)
GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)

.PHONY: clean
clean:
-rm -rf bin/

OPM = $(LOCAL_BIN)/opm

$(OPM):
mkdir -p $(@D)

.PHONY: opm
opm: $(OPM)
# Checking installation of opm
@current_release_json=$$(curl -s "https://api.github.com/repos/operator-framework/operator-registry/releases/latest"); \
current_release=$$(printf '%s\n' "$${current_release_json}" | jq -r '.tag_name'); \
if ! $(OPM) version || [ "$$($(OPM) version | grep -o "v[0-9]\+\.[0-9]\+\.[0-9]\+" | head -1)" != "$${current_release}" ]; then \
echo "Installing opm $${current_release}"; \
download_url=$$(printf '%s\n' "$${current_release_json}" | jq -r '.assets[] | select(.name == "$(GOOS)-$(GOARCH)-opm").browser_download_url'); \
curl --fail -Lo $(OPM) $${download_url}; \
chmod +x $(OPM); \
fi

.PHONY: validate-catalog
validate-catalog:
$(OPM) validate catalog

VERSION_TAG ?= latest
IMG_REPO ?= quay.io/strolostron
IMAGE_TAG_BASE ?= $(IMG_REPO)/gatekeeper-operator-fbc
IMG ?= $(IMAGE_TAG_BASE):$(VERSION_TAG)

.PHONY: build-image
build-image:
podman build -t $(IMG) -f catalog.Dockerfile .

# ref: https://github.com/operator-framework/operator-registry?tab=readme-ov-file#using-the-catalog-locally
.PHONY: run-image
run-image:
podman run -p 50051:50051 $(IMG)

.PHONY: stop-image
stop-image:
podman stop --filter "ancestor=$(IMG)"

GRPCURL := $(LOCAL_BIN)/grpcurl

$(GRPCURL):
mkdir -p $(@D)

# gRPCurl Repo: https://github.com/fullstorydev/grpcurl
.PHONY: grpcurl
grpcurl: $(GRPCURL)
# Checking installation of grpcurl
@current_release_json=$$(curl -s "https://api.github.com/repos/fullstorydev/grpcurl/releases/latest"); \
current_release=$$(printf '%s\n' "$${current_release_json}" | jq -r '.tag_name'); \
if ! $(GRPCURL) --version || [ "$$($(GRPCURL) --version 2>&1 | grep -o "v[0-9]\+\.[0-9]\+\.[0-9]\+" | head -1)" != "$${current_release}" ]; then \
echo "Installing grpcurl $${current_release}"; \
[ "$(GOOS)" = "darwin" ] && go_os="osx" || go_os=$(GOOS); \
download_file=grpcurl_$${current_release#v}_$${go_os}_$(GOARCH).tar.gz; \
mkdir $${download_file%.tar.gz}; \
download_url=$$(printf '%s\n' "$${current_release_json}" | jq -r '.assets[] | select(.name == "'$${download_file}'").browser_download_url'); echo $${download_url}; \
if curl --fail -Lo $${download_file%.tar.gz}/$${download_file} $${download_url}; then \
tar xvzf $${download_file%.tar.gz}/$${download_file} -C $${download_file%.tar.gz}; \
mv $${download_file%.tar.gz}/grpcurl $(GRPCURL); \
chmod +x $(GRPCURL); \
rm -rf $${download_file%.tar.gz}; \
else exit 1; fi; \
fi

.PHONY: test-image
test-image: grpcurl
# Validate package list against build/packageList.json
$(GRPCURL) -plaintext localhost:50051 api.Registry.ListPackages | diff test/packageList.json - && echo "Success!"
2 changes: 0 additions & 2 deletions OWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ approvers:
- dhaiducek
- gparvin
- JustinKuli
- mprahl
- yiraeChristineKim
reviewers:
- dhaiducek
- gparvin
- JustinKuli
- mprahl
- yiraeChristineKim
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# Gatekeeper Operator File-Based Catalog

This repository houses the File-Based Catalog (FBC) for the
[Gatekeeper Operator](https://github.com/stolostron/gatekeeper-operator).

See the Operator Lifecycle Manager (OLM)
[File-based Catalogs documentation](https://olm.operatorframework.io/docs/reference/file-based-catalogs/)
and the [operator-registry repository](https://github.com/operator-framework/operator-registry) for
additional information.
3 changes: 3 additions & 0 deletions test/packageList.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "gatekeeper-operator"
}

0 comments on commit 2b0046e

Please sign in to comment.