diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4211054 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.postgres-data +bin +.github + +docker-compose.dev.yml +docker-compose.yml +Dockerfile + +README.md +LICENSE \ No newline at end of file diff --git a/.gitignore b/.gitignore index a5e68ab..836e825 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ # Test binary, built with `go test -c` *.test bin/ +.postgres-data/ # Output of the go coverage tool, specifically when used with LiteIDE *.out diff --git a/Dockerfile b/Dockerfile index 8c97f43..1c3b7d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,7 @@ FROM golang:1.21 as builder WORKDIR /app COPY . . +RUN CGO_ENABLED=0 GOOS=linux go build -o ./pbuf-migrations ./. RUN CGO_ENABLED=0 GOOS=linux go build -o ./pbuf-registry ./cmd/... # 2. run stage @@ -12,6 +13,7 @@ FROM bash:alpine3.18 WORKDIR /app +COPY --from=builder /app/pbuf-migrations /app/pbuf-migrations COPY --from=builder /app/pbuf-registry /app/pbuf-registry CMD ["/app/pbuf-registry"] \ No newline at end of file diff --git a/Dockerfile.migrations b/Dockerfile.migrations deleted file mode 100644 index 187e95a..0000000 --- a/Dockerfile.migrations +++ /dev/null @@ -1,17 +0,0 @@ -# multi-stage build for go lang application -# 1. build stage -FROM golang:1.21 as builder - -WORKDIR /app -COPY . . - -RUN CGO_ENABLED=0 GOOS=linux go build -o ./pbuf-migrations ./. - -# 2. run stage -FROM bash:alpine3.18 - -WORKDIR /app - -COPY --from=builder /app/pbuf-migrations /app/pbuf-migrations - -CMD ["/app/pbuf-migrations"] \ No newline at end of file diff --git a/Makefile b/Makefile index dc523d2..54ff71b 100644 --- a/Makefile +++ b/Makefile @@ -65,12 +65,12 @@ docker: .PHONY: run # run run: - docker-compose build --no-cache && docker-compose up --force-recreate -d + docker-compose -f docker-compose.dev.yml build --no-cache && docker-compose -f docker-compose.dev.yml up --force-recreate -d .PHONY: stop # stop stop: - docker-compose down + docker-compose -f docker-compose.dev.yml down # show help help: diff --git a/README.md b/README.md index 527a42c..3ce5ffe 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,57 @@ The registry solves this problem by providing a central place to store and manag ## Installation -TBD +### Docker Compose + +#### Prerequisites + +- [Docker](https://docs.docker.com/get-docker/) +- [Docker Compose](https://docs.docker.com/compose/install/) + +#### Steps + +1. Clone the repository +2. Run `docker-compose up -d` + +### Helm Chart + +Coming soon... ## Usage -TBD +### CLI + +We recommend to use the [CLI](https://github.com/pbufio/pbuf-cli) to interact with the registry. + +### API + +#### HTTP + +The registry provides a REST API (`:8080` port by default). You can find the swagger documentation [here](https://github.com/pbufio/pbuf-registry/blob/main/gen/v1/registry.swagger.json). + +#### gRPC + +The registry provides a gRPC API (`:8081` port by default). You can find the protobuf definition [here](https://github.com/pbufio/pbuf-registry/blob/main/api/v1/registry.proto) ## Development and Contributing -TBD \ No newline at end of file +### Prerequisites + +- [Go](https://golang.org/doc/install) +- [Docker](https://docs.docker.com/get-docker/) +- [Docker Compose](https://docs.docker.com/compose/install/) +- [Make](https://www.gnu.org/software/make/) + +### Build + +- Run `make build` to build the registry +- Run `make build-in-docker` to build linux binaries in docker + +### Test + +- Run `make test` to run the tests. + +### Test the Registry + +- Run `make run` to start the registry and test it. +- Run `make stop` to stop the running registry. \ No newline at end of file diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..dec1643 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,24 @@ +version: '3.1' +services: + db: + image: postgres:14.7 + restart: always + ports: + - "5432:5432" + environment: + POSTGRES_USER: pbuf + POSTGRES_PASSWORD: pbuf + POSTGRES_DB: pbuf_registry + pbuf-registry: + build: + context: . + restart: always + depends_on: + - db + ports: + - "8080:8080" + - "8081:8081" + environment: + DATA_DATABASE_DSN: "postgres://pbuf:pbuf@db:5432/pbuf_registry?sslmode=disable" + command: > + sh -c "/app/pbuf-migrations && /app/pbuf-registry" \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 28a34a0..434df84 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,31 +5,21 @@ services: restart: always ports: - "5432:5432" + volumes: + - ./.postgres-data:/var/lib/postgresql/data environment: POSTGRES_USER: pbuf POSTGRES_PASSWORD: pbuf POSTGRES_DB: pbuf_registry - pbuf-migrations: - build: - context: . - dockerfile: Dockerfile.migrations - restart: always - depends_on: - - db - environment: - DATA_DATABASE_DSN: "postgres://pbuf:pbuf@db:5432/pbuf_registry?sslmode=disable" - command: - - "/app/pbuf-migrations" pbuf-registry: - build: - context: . + image: ghcr.io/pbufio/registry:v0.1.1 restart: always depends_on: - - pbuf-migrations + - db ports: - "8080:8080" - "8081:8081" environment: DATA_DATABASE_DSN: "postgres://pbuf:pbuf@db:5432/pbuf_registry?sslmode=disable" - command: - - "/app/pbuf-registry" \ No newline at end of file + command: > + sh -c "/app/pbuf-migrations && /app/pbuf-registry" \ No newline at end of file