Skip to content

Commit

Permalink
pbuf registry basic support (#4)
Browse files Browse the repository at this point in the history
* pbuf registry basic support

* fix dockerfile

* fix failed tests

* fix link in README.md

* add export definition
  • Loading branch information
aatarasoff authored Nov 8, 2023
1 parent 204274e commit e4ac841
Show file tree
Hide file tree
Showing 84 changed files with 14,404 additions and 178 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:

- name: Run pbuf vendor in Docker and Verify Files
run: |
docker run --rm -v $(pwd)/vendor:/tmp/vendor -w /tmp/vendor pbuf sh -c "cp /app/pbuf.yaml /tmp/vendor && /app/pbuf vendor"
docker run --rm -v $(pwd)/vendor:/tmp/vendor -w /tmp/vendor pbuf-cli sh -c "cp /app/pbuf.yaml /tmp/vendor && /app/pbuf-cli vendor"
if [ ! -f ./vendor/proto/addressbook.proto ]; then
echo "Address book proto file from main branch is not found"
exit 1
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ FROM bash:alpine3.16
WORKDIR /app

COPY ./e2e/pbuf.yaml /app
COPY ./bin/pbuf /app/pbuf
COPY ./bin/pbuf-cli /app/pbuf-cli

CMD ["/app/pbuf"]
CMD ["/app/pbuf-cli"]
19 changes: 17 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
.PHONY: vendor
# vendor modules
vendor:
pbuf-cli vendor

.PHONY: vendor-gen
# gen modules
vendor-gen:
buf generate --exclude-path third_party/google

.PHONY: vendor-all
vendor-all:
make vendor
make vendor-gen

.PHONY: build
# build
build:
mkdir -p bin/ && go build -o ./bin/pbuf .
mkdir -p bin/ && go build -o ./bin/pbuf-cli .

.PHONY: build-in-docker
# build in docker
Expand All @@ -17,7 +32,7 @@ build-in-docker:
.PHONY: docker
# docker
docker:
docker build -t pbuf:latest .
docker build -t pbuf-cli:latest .

.PHONY: lint
# lint
Expand Down
161 changes: 151 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

The `pbuf-cli` is a Command Line Interface (CLI) tool for PowerBuf, allowing you to easily manage, and vendor modules.

We recommend using `pbuf-cli` with the [PowerBuf Registry](https://github.com/pbufiio/pbuf-registry).

---

### Installation
Expand Down Expand Up @@ -44,15 +46,105 @@ pbuf-cli [command] [arguments...]

#### Available Commands

1. **Vendor**
##### Vendor

The vendor command allows you to vendor modules from provided configuration.

```bash
pbuf-cli vendor
```

By default, this command reads the configuration from `pbuf.yaml`. The configuration provides details like the repository, branch or tag, path, and output directory for each module.

##### Register Module

The register command allows you to register a module to the registry.

```bash
pbuf-cli modules register
```

You can register a module by providing the following details in `pbuf.yaml`:

```yaml
version: v1
name: [module_name]
...
```

Replace `[module_name]` with the name of the module you want to register.

##### Get Module

The vendor command allows you to vendor modules from provided configuration.
The get command allows you to get the information about a module from the registry.

```bash
pbuf-cli modules get [module_name]
```

Response example:
```json
{
"id": "b9f9898a-8510-4017-9618-5244176eb1b8",
"name": "pbufio/pbuf-registry",
"tags": [
"v0.0.0",
"v0.1.0"
]
}
```

```bash
pbuf-cli vendor
```
##### List Modules

The list command allows you to list all modules from the registry.

```bash
pbuf-cli modules list
```

Response example:
```json
[
{
"id": "b9f9898a-8510-4017-9618-5244176eb1b8",
"name": "pbufio/pbuf-registry"
},
{
"id": "b9f9898a-8510-4017-9618-5244176eb1b8",
"name": "pbufio/pbuf-cli"
}
]
```

By default, this command reads the configuration from `pbuf.yaml`. The configuration provides details like the repository, branch or tag, path, and output directory for each module.
##### Push Module

The push command allows you to push `.proto` files to the registry with a specific tag.

```bash
pbuf-cli modules push [tag]
```

Replace `[tag]` with the tag you want to push.

#### Delete Tag

The delete command allows you to delete a tag from the registry.

```bash
pbuf-cli modules delete-tag [tag]
```

The command deletes all the proto files associated with the tag.

#### Delete Module

The delete command allows you to delete a module from the registry.

```bash
pbuf-cli modules delete [module_name]
```

The command deletes all the tags and proto files associated with the module.

---

Expand All @@ -61,33 +153,82 @@ pbuf-cli [command] [arguments...]
A typical `pbuf.yaml` file contains the following:

```yaml
version: "1.0"
version: v1
name: [module_name]
registry:
addr: [registry_url]
insecure: true # no tls support at the moment, but it will be added soon
export:
paths:
- [proto_files_path]
modules:
# use the registry to vendor .proto files
- name: [dependency_module_name]
path: [path_in_registry]
tag: [dependency_module_tag]
out: [output_folder_on_local]
# use a git repository to vendor .proto files
- repository: [repository_url]
path: [path_in_repository]
branch: [branch_name]
tag: [tag_name]
out: [output_folder_on_local]
```
Replace placeholders with appropriate values:
Replace main placeholders with appropriate values:
- `[module_name]`: The module name you want to register.
- `[registry_url]`: The URL of the pbuf-registry.
- `[proto_files_path]: One or several paths that contain `.proto` files.

Replace placeholders in the registry modules with appropriate values:
- `[dependency_module_name]`: The module name you want to vendor.
- `[path_in_registry]`: Path to the folder or file in the registry you want to vendor.
- `[tag_name]`: Specific tag to vendor.
- `[output_folder_on_local]`: Folder where the vendor content should be placed on your local machine.

Replace placeholders in modules placed in git with appropriate values:
- `[repository_url]`: The URL of the Git repository.
- `[path_in_repository]`: Path to the folder or file in the repository you want to vendor.
- `[branch_name]`: Specific branch name to clone (optional if tag is provided).
- `[tag_name]`: Specific tag to clone (optional if branch is provided).
- `[output_folder_on_local]`: Folder where the vendored content should be placed on your local machine.
- `[output_folder_on_local]`: Folder where the vendor content should be placed on your local machine.

#### Examples

#### Push Module
```yaml
version: v1
name: pbufio/pbuf-registry
registry:
addr: pbuf.cloud:8081
insecure: true
# all `.proto` files from `api` and `entities` folders
# will be exported as the module proto files
export:
paths:
- api
- entities
modules: []
```
#### Vendor Modules
```yaml
version: v1
name: pbuf-cli
registry:
addr: pbuf.cloud:8081
insecure: true
modules:
# will copy api/v1/registry.proto file to third_party/api/v1/registry.proto
- name: pbufio/pbuf-registry
tag: v0.0.1
out: third_party
# will copy examples/addressbook.proto file to proto/addressbook.proto
- repository: https://github.com/protocolbuffers/protobuf
path: examples/addressbook.proto
branch: main
out: proto
# will copy examples folder to examples folder
# will copy examples folder to examples folder
- repository: https://github.com/protocolbuffers/protobuf
path: examples
tag: v24.4
Expand Down
8 changes: 8 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: v1
plugins:
- plugin: go
out: gen
opt: paths=source_relative
- plugin: go-grpc
out: gen
opt: paths=source_relative
3 changes: 3 additions & 0 deletions buf.work.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version: v1
directories:
- third_party
7 changes: 7 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: v1
breaking:
use:
- FILE
lint:
use:
- DEFAULT
Loading

0 comments on commit e4ac841

Please sign in to comment.