Skip to content

Commit

Permalink
configs and readme
Browse files Browse the repository at this point in the history
feat: Add makefile target for deps, add licensei

Signed-off-by: Bence Csati <[email protected]>
  • Loading branch information
csatib02 committed Aug 16, 2024
1 parent d618574 commit 928249b
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 10 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,46 @@ jobs:
- name: Check commit messages
run: nix develop --impure .#ci -c pre-commit run --hook-stage manual

license-check:
name: License check
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2

- name: Set up Nix
uses: cachix/install-nix-action@8887e596b4ee1134dae06b98d573bd674693f47c # v26
with:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- name: Set up magic Nix cache
uses: DeterminateSystems/magic-nix-cache-action@eeabdb06718ac63a7021c6132129679a8e22d0c7 # v3

- name: Cache license information
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 # v4.0.1
with:
path: .licensei.cache
key: licensei-v1-${{ github.ref_name }}-${{ hashFiles('go.sum') }}
restore-keys: |
licensei-v1-${{ github.ref_name }}
licensei-v1-main
licensei-v1
- name: Prepare Nix shell
run: nix develop --impure .#ci

- name: Populate license cache
run: nix develop --impure .#ci -c licensei cache
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check licenses
run: nix develop --impure .#ci -c make license-check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

dev:
name: Developer environment
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/.direnv/
/.env.local
/.pre-commit-config.yaml
/bin/
/build/
/config.yaml
/tmp/
Expand Down
55 changes: 55 additions & 0 deletions .licensei.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
approved = [
"apache-2.0",
"mit",
"mit-0",
"bsd-2-clause",
"bsd-3-clause",
"mpl-2.0",
"isc",
"epl-2.0",
"richard-crowley",
]

ignored = [
"github.com/xeipuuv/gojsonpointer", # Apache 2.0
"github.com/xeipuuv/gojsonreference", # Apache 2.0
"github.com/xeipuuv/gojsonschema", # Apache 2.0
"github.com/couchbase/gocbcoreps", # Apache 2.0
"github.com/confluentinc/confluent-kafka-go/v2", # Apache 2.0
"github.com/JohnCGriffin/overflow", # MIT
"github.com/invopop/yaml", # MIT
"github.com/form3tech-oss/jwt-go", #MIT
"github.com/russross/blackfriday/v2", # 2-Clause BSD
"github.com/gogo/protobuf", # 3-Clause BSD
"github.com/rcrowley/go-metrics", # Richard Crowley

"cuelang.org/go", # Apache 2.0
"go.mongodb.org/mongo-driver", # Apache 2.0

# Unsupported VCS
"google.golang.org/protobuf", # 3-Clause BSD
"modernc.org/libc", # 3-Clause BSD
"modernc.org/mathutil", # 3-Clause BSD
"modernc.org/memory", # 3-Clause BSD
"modernc.org/sqlite", # 3-Clause BSD

# No license
"github.com/couchbase/goprotostellar",
]

[header]
ignorePaths = [".devenv", ".direnv", "vendor", "client", ".gen"]
ignoreFiles = ["*.gen.go"]
template = """// Copyright © :YEAR: Tailfin Cloud 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."""
75 changes: 68 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html

export PATH := $(abspath bin/):${PATH}

.PHONY: up
up: ## Start the dependencies via docker compose. `export COMPOSE_PROFILES=dev,redis,...`
$(call print-target)
Expand Down Expand Up @@ -52,16 +54,16 @@ config.yaml:
cp config.example.yaml config.yaml

.PHONY: server
server: ## Run sink-worker
server: ## Run server
@ if [ config.yaml -ot config.example.yaml ]; then diff -u config.yaml config.example.yaml || (echo "!!! The configuration example changed. Please update your config.yaml file accordingly (or at least touch it). !!!" && false); fi
$(call print-target)
air -c ./cmd/server/.air.toml
$(AIR_BIN) -c ./cmd/server/.air.toml

.PHONY: sink-worker
sink-worker: ## Run sink-worker
@ if [ config.yaml -ot config.example.yaml ]; then diff -u config.yaml config.example.yaml || (echo "!!! The configuration example changed. Please update your config.yaml file accordingly (or at least touch it). !!!" && false); fi
$(call print-target)
air -c ./cmd/sink-worker/.air.toml
$(AIR_BIN) -c ./cmd/sink-worker/.air.toml

.PHONY: balance-worker
balance-worker: ## Run balance-worker
Expand All @@ -83,17 +85,28 @@ etoe: ## Run e2e tests
.PHONY: test
test: ## Run tests
$(call print-target)
dagger call --source .:default test
$(DAGGER_BIN) call --source .:default test

.PHONY: test-e2e
test-e2e: ## Run end-to-end tests
$(call print-target)
$(DAGGER_BIN) call --source .:default etoe

.PHONY: lint
lint: ## Run linters
$(call print-target)
dagger call --source .:default lint all
$(DAGGER_BIN) call --source .:default lint all

.PHONY: license-check
license-check: ## Run license check
$(call print-target)
$(LICENSEI_BIN) check
$(LICENSEI_BIN) header

.PHONY: fmt
fmt: ## Format code
$(call print-target)
golangci-lint run --fix
$(GOLANGCI_LINT_BIN) run --fix

.PHONY: mod
mod: ## go mod tidy
Expand All @@ -103,7 +116,55 @@ mod: ## go mod tidy
.PHONY: seed
seed: ## Seed OpenMeter with test data
$(call print-target)
benthos -c etc/seed/seed.yaml
$(BENTHOS_BIN) -c etc/seed/seed.yaml

.PHONY: deps
deps: ## Install dependencies
$(call print-target)
$(MAKE) bin/air bin/dagger bin/golangci-lint bin/licensei bin/benthos

# Dependency versions
AIR_VERSION = 1.52.0
DAGGER_VERSION = 0.11.0
GOLANGCI_VERSION = 1.59.1
LICENSEI_VERSION = 0.9.0
BENTHOS_VERSION = 4.24.0

# Dependency binaries
AIR_BIN := air
DAGGER_BIN := dagger
GOLANGCI_LINT_BIN := golangci-lint
LICENSEI_BIN := licensei
BENTHOS_BIN := benthos

# If we have a "bin" dir, use those binaries instead
ifneq ($(wildcard ./bin/.),)
AIR_BIN := bin/$(AIR_BIN)
DAGGER_BIN := bin/$(DAGGER_BIN)
GOLANGCI_LINT_BIN := bin/$(GOLANGCI_LINT_BIN)
LICENSEI_BIN := bin/$(LICENSEI_BIN)
BENTHOS_BIN := bin/$(BENTHOS_BIN)
endif

bin/air:
@mkdir -p bin
curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | bash -s -- v${AIR_VERSION}

bin/dagger:
@mkdir -p bin
curl -sfL https://raw.githubusercontent.com/dagger/dagger/main/install.sh | bash -s -- v${DAGGER_VERSION}

bin/golangci-lint:
@mkdir -p bin
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- v${GOLANGCI_VERSION}

bin/licensei:
@mkdir -p bin
curl -sfL https://raw.githubusercontent.com/goph/licensei/master/install.sh | bash -s -- v${LICENSEI_VERSION}

bin/benthos:
@mkdir -p bin
curl -Lsf https://sh.benthos.dev | bash -s -- ${BENTHOS_VERSION} ${PWD}/bin

.PHONY: help
.DEFAULT_GOAL := help
Expand Down
37 changes: 34 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,24 +126,37 @@ For other shells, see [https://direnv.net/docs/hook.html](https://direnv.net/doc
Nix may stop working after a MacOS upgrade. If it does, follow [these instructions](https://github.com/NixOS/nix/issues/3616#issuecomment-662858874).

<hr>
</details>
</details><br>

_Alternatively, install [Go](https://go.dev/dl/) on your computer then run `make deps` to install the rest of the dependencies._

Make sure Docker is installed with Compose and Buildx.

Run the dependencies:

```sh
make up
```

Run OpenMeter:
Run project components:

```sh
make run
make sink-worker
make server
```

Build binary:

```shell
make build-sink-worker # Builds sink-worker binary
make build-server # Builds server binary
```

Run tests:

```sh
make test
make test-e2e
```

Run linters:
Expand All @@ -152,6 +165,24 @@ Run linters:
make lint
```

Some linter violations can automatically be fixed:

```shell
make fmt
```

Generate go code:

```shell
make generate
```

Once you are done, you can tear down project dependencies:

```shell
make down
```

## Roadmap

Visit our website at [https://openmeter.io](https://openmeter.io#roadmap) for our public roadmap.
Expand Down

0 comments on commit 928249b

Please sign in to comment.