Skip to content

Commit

Permalink
Remove examples and use the official repo instead (#1528)
Browse files Browse the repository at this point in the history
* Remove examples and add a makefile for cloning them from the official repo

Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>

* Update provider.yaml

---------

Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
  • Loading branch information
rdimitrov authored Nov 6, 2023
1 parent 2d32ac6 commit ca84dd1
Show file tree
Hide file tree
Showing 44 changed files with 163 additions and 2,304 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ docs/.docusaurus
/deployment/helm/templates/combined.yml
/deployment/helm/charts
/deployment/helm/*.tgz

# Ignore examples cloned repo
examples/rules-and-profiles/
31 changes: 28 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

projectname?=minder

# Profile and Rule examples
include examples/Makefile

# Unfortunately, we need OS detection for docker-compose
OS := $(shell uname -s)

Expand All @@ -38,26 +41,30 @@ BUILDTAGS?=$(TARGET_ENV)

default: help

.PHONY: help gen clean-gen build run-cli run-server bootstrap test clean cover lint pre-commit migrateup migratedown sqlc mock cli-docs identity

.PHONY: help
help: ## list makefile targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: gen
gen: buf sqlc mock ## Run code generation targets (buf, sqlc, mock)

.PHONY: buf
buf: ## Run protobuf code generation
buf generate

.PHONY: clean-gen
clean-gen:
rm -rf $(shell find pkg/api -iname "*.go") & rm -rf $(shell find pkg/api -iname "*.swagger.json") & rm -rf pkg/api/protodocs

.PHONY: cli-docs
cli-docs:
@rm -rf docs/docs/ref/cli/commands
@mkdir -p docs/docs/ref/cli/commands
@echo 'label: Commands' > docs/docs/ref/cli/commands/_category_.yml
@echo 'position: 20' >> docs/docs/ref/cli/commands/_category_.yml
@go run -tags '$(BUILDTAGS)' cmd/cli/main.go docs

.PHONY: build
build: ## build golang binary
CGO_ENABLED=0 go build \
-trimpath \
Expand All @@ -67,14 +74,17 @@ build: ## build golang binary
CGO_ENABLED=0 go build -trimpath -tags '$(BUILDTAGS)' -o ./bin/$(projectname)-server ./cmd/server
CGO_ENABLED=0 go build -trimpath -tags '$(BUILDTAGS)' -o ./bin/medev ./cmd/dev

.PHONY: run-cli
run-cli: ## run the CLI, needs additional arguments
@go run -ldflags "-X main.version=$(shell git describe --abbrev=0 --tags)" -tags '$(BUILDTAGS)' ./cmd/cli

.PHONY: run-server
run-server: ## run the app
@go run -ldflags "-X main.version=$(shell git describe --abbrev=0 --tags)" -tags '$(BUILDTAGS)' ./cmd/server serve

DOCKERARCH := $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')

.PHONY: run-docker
run-docker: ## run the app under docker.
# podman (at least) doesn't seem to like multi-arch images, and sometimes picks the wrong one (e.g. amd64 on arm64)
# We also need to remove the build: directives to use ko builds
Expand All @@ -84,6 +94,7 @@ run-docker: ## run the app under docker.
$(COMPOSE) -f .resolved-compose.yaml down && $(COMPOSE) -f .resolved-compose.yaml up $(COMPOSE_ARGS) $(services)
rm .resolved-compose.yaml*

.PHONY: helm
helm: ## build the helm chart to a local archive, using ko for the image build
cd deployment/helm; \
ko resolve --platform=${KO_PLATFORMS} --base-import-paths --push=${KO_PUSH_IMAGE} -f values.yaml > values.tmp.yaml && \
Expand All @@ -93,11 +104,13 @@ helm: ## build the helm chart to a local archive, using ko for the image build
cat values.yaml
git checkout deployment/helm/values.yaml

.PHONY: helm-template
helm-template: ## renders the helm templates which is useful for debugging
cd deployment/helm; \
helm dependency update && \
helm template .

.PHONY: bootstrap
bootstrap: ## install build deps
go generate -tags tools tools/tools.go
# N.B. each line runs in a different subshell, so we don't need to undo the 'cd' here
Expand All @@ -117,42 +130,54 @@ bootstrap: ## install build deps
# Make sure the keys are readable by the docker user
chmod 644 .ssh/*

test: clean ## display test coverage
.PHONY: test
test: clean init-examples ## display test coverage
go test -json -race -v ./... | gotestfmt

.PHONY: clean
clean: ## clean up environment
rm -rf dist/* & rm -rf bin/*

.PHONY: cover
cover: ## display test coverage
go test -v -race $(shell go list ./... | grep -v /vendor/) -v -coverprofile=coverage.out
go tool cover -func=coverage.out

.PHONY: lint
lint: ## lint go files
golangci-lint run

.PHONY: pre-commit
pre-commit: ## run pre-commit hooks
pre-commit run --all-files

.PHONY: sqlc
sqlc: ## generate sqlc files
sqlc generate

.PHONY: migrateup
migrateup: ## run migrate up
@go run -tags '$(BUILDTAGS)' cmd/server/main.go migrate up --yes

.PHONY: migratedown
migratedown: ## run migrate down
@go run -tags '$(BUILDTAGS)' cmd/server/main.go migrate down

.PHONY: dbschema
dbschema: ## generate database schema with schema spy, monitor file until doc is created and copy it
mkdir -p database/schema/output && chmod a+w database/schema/output
cd database/schema && $(COMPOSE) run -u 1001:1001 --rm schemaspy -configFile /config/schemaspy.properties -imageformat png
sleep 10
cp database/schema/output/diagrams/summary/relationships.real.large.png docs/static/img/minder/schema.png
cd database/schema && $(COMPOSE) down -v && rm -rf output

.PHONY: mock
mock: ## generate mocks
mockgen -package mockdb -destination database/mock/store.go github.com/stacklok/minder/internal/db Store
mockgen -package mockgh -destination internal/providers/github/mock/github.go -source pkg/providers/v1/providers.go GitHub
mockgen -package auth -destination internal/auth/mock/jwtauth.go github.com/stacklok/minder/internal/auth JwtValidator,KeySetFetcher

.PHONY: github-login
github-login: ## setup GitHub login on Keycloak
ifndef KC_GITHUB_CLIENT_ID
$(error KC_GITHUB_CLIENT_ID is not set)
Expand Down
38 changes: 38 additions & 0 deletions cmd/dev/examples/provider.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Copyright 2023 Stacklok, Inc
#
# 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.

---
# This is a sample provider integrating minder with GitHub
# There are details which you'll need to fill in yourself.
version: v1
type: provider
name: github
context:
organization: ACME
def:
endpoint: 'https://api.github.com/'
auth:
type: oauth2
client_id: 'your-client-id'
client_secret: 'your-client-secret'
scopes: ['repo', 'read:org']
client_types:
- rest
- graphql
entities:
- repositories
- build_environments
- artifacts

24 changes: 24 additions & 0 deletions cmd/dev/examples/pull_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Copyright 2023 Stacklok, Inc
#
# 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.

url: https://api.github.com/repos/jakubtestorg/bad-npm/pulls/3
commitSHA: bd9958a63c9b95ccc2bc0cf1eef65a87529aed16
number: 3
repo_owner: jakubtestorg
repo_name: bad-npm
patches:
- name: package-lock.json
patch_Url: https://github.com/jakubtestorg/bad-npm/raw/123/package-lock.json
authorID: 144222806
24 changes: 24 additions & 0 deletions cmd/dev/examples/repository.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Copyright 2023 Stacklok, Inc
#
# 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.

---
owner: stacklok
name: Demo-Repo-Go
repoId: 605597568
HookUrl:
clone_url: "https://github.com/stacklok/Demo-Repo-Go.git"
CreatedAt: 2021-03-19T16:00:00Z
UpdatedAt: 2021-03-19T16:00:00Z
Registered: true
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
#
# Copyright 2023 Stacklok, Inc
#
# 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.

artifact:
artifactId: 5482209
name: test
Expand Down
20 changes: 20 additions & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Copyright 2023 Stacklok, Inc.
#
# 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.

default: init-examples

.PHONY: init-examples
init-examples: ## clone example rules and profiles
git clone https://github.com/stacklok/minder-rules-and-profiles.git examples/rules-and-profiles | true
8 changes: 8 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Minder examples

## Bootstrap the examples directory

Run `make` to clone the examples from the [https://github.com/stacklok/minder-rules-and-profiles](https://github.com/stacklok/minder-rules-and-profiles)
```bash
make
```
30 changes: 0 additions & 30 deletions examples/github/profiles/pr_vuln_check.yaml

This file was deleted.

Loading

0 comments on commit ca84dd1

Please sign in to comment.