Skip to content

Commit

Permalink
Update docs and move cli dependencies to a container (#58)
Browse files Browse the repository at this point in the history
* update docs and moved cli deps into a container
* fmt
* fix the ci
  • Loading branch information
firminochangani authored Aug 19, 2024
1 parent c7a9e6b commit d094107
Show file tree
Hide file tree
Showing 8 changed files with 747 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
run: go mod download

- name: Spin up Docker
run: task docker:up
run: task run

- name: Test all
run: task test:all
Expand Down
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

37 changes: 24 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# subscribed.dev
# Subscribed

[![main](https://github.com/subscribeddotdev/subscribed-backend/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/subscribeddotdev/subscribed-backend/actions/workflows/main.yml)

Expand All @@ -12,23 +12,34 @@ Subscribed is a webhook provider that allows software developers to quickly add

> In early-stage development of a Webhooks provider platform... things will change, a lot.
## Local setup
## Getting started

### Pre-requisites (tools)
### Requirements

- Docker
- [Docker](https://docker.com) and [Docker Compose](https://docs.docker.com/compose/)
- [Taskfile](https://taskfile.dev): An alternative to Make used to run custom tasks defined in [./Taskfile.yml](./Taskfile.yml)

### Running the project locally
### Setup

```
docker-compose up -d
```
1. Clone the repository `git clone [email protected]:subscribeddotdev/subscribed-backend.git`
2. Build the container with all the CLI tools that this repo depends on: `task setup`
3. Run the project: `task run`
4. View logs: `task logs`

And then
## Running tests:

```
task logs
```
- Running unit and integration tests `task test`
- Running component tests `task test:component`
- Running all tests `task test:all`

That alone should be enough to boot up the app in development inside a docker container with live-reloading enabled.
### Other operations:

- Running migrations upwards `task mig:up`
- Running migrations downwards `task mig:down`
- Generating handlers from the Open API spec `task openapi`
- Generating ORM models `task orm`
- Generating models from the event specification `task events`

## License

[GNU Affero General Public License v3.0](./LICENSE)
61 changes: 34 additions & 27 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@ dotenv:
- ./.env

tasks:
setup:
dir: ./misc/tools/cli
cmds:
- docker build -t subscribed-cli-tools:latest .

tools:
cmds:
- |
docker run \
--rm \
--env-file ./.env.local \
--network host \
-v $(pwd):/app \
-w /app \
subscribed-cli-tools:latest \
{{.CLI_ARGS}}
run:
cmds:
- docker compose up -d {{.CLI_ARGS}}

run:backend:
cmds:
- task watch -- go run ./cmd/service
Expand All @@ -20,37 +41,37 @@ tasks:

mig:up:
cmds:
- goose -s -dir ./misc/sql/migrations up
- task tools -- goose -s -dir ./misc/sql/migrations up

mig:down:
cmds:
- goose -s -dir ./misc/sql/migrations down
- task tools -- goose -s -dir ./misc/sql/migrations down

mig:reset:
cmds:
- goose -s -dir ./misc/sql/migrations reset
- task tools -- goose -s -dir ./misc/sql/migrations reset

mig:create:
cmds:
- goose -s -dir ./misc/sql/migrations create {{.CLI_ARGS}} sql
- task tools -- goose -s -dir ./misc/sql/migrations create {{.CLI_ARGS}} sql

seed:up:
cmds:
- goose -no-versioning -dir ./misc/sql/seeds up
- task tools -- goose -no-versioning -dir ./misc/sql/seeds up

seed:down:
cmds:
- goose -no-versioning -dir ./misc/sql/seeds down
- task tools -- goose -no-versioning -dir ./misc/sql/seeds down

seed:create:
cmds:
- goose -no-versioning -dir ./misc/sql/seeds create {{.CLI_ARGS}} sql
- task tools -- goose -no-versioning -dir ./misc/sql/seeds create {{.CLI_ARGS}} sql

orm:
cmds:
- task mig:down
- task mig:up
- sqlboiler psql --wipe --no-tests -o ./internal/adapters/models
- task tools -- sqlboiler psql --wipe --no-tests -o ./internal/adapters/models

test:all:
cmds:
Expand All @@ -67,17 +88,13 @@ tasks:
- go clean -testcache
- go test -v -race ./tests/components/...

lint:docker:
cmds:
- docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.59.1 golangci-lint run -v

lint:
cmds:
- golangci-lint run
- task tools -- golangci-lint run

lint:fix:
cmds:
- golangci-lint run --fix
- task tools -- golangci-lint run --fix

fmt:
cmds:
Expand All @@ -87,34 +104,24 @@ tasks:
cmds:
- docker compose logs -f --tail 10

docker:up:
cmds:
- docker compose up -d {{.CLI_ARGS}}

openapi:
cmds:
- |
oapi-codegen \
task tools -- oapi-codegen \
-package http \
-generate server,types,spec \
./api/openapi.yml > ./internal/ports/http/server.gen.go
- |
oapi-codegen \
task tools -- oapi-codegen \
-package client \
-generate client,types,spec \
./api/openapi.yml > ./tests/client/client.gen.go
events:
cmds:
- |
protoc ./events/events.proto \
task tools -- protoc ./events/events.proto \
--go_out=./events/go --go_opt=paths=source_relative \
--go-grpc_out=./events/go --go-grpc_opt=paths=source_relative \
--proto_path=./events
# Proxies the app via NGROK to facilitate testing webhooks
# NGROK_URL must be set in your local .env.secrets
webhook:
cmds:
- ngrok http --domain=$NGROK_URL 8080
10 changes: 5 additions & 5 deletions events/go/events.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/ports/http/server.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions misc/tools/cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM golang:1.22.3

# SQLBoiler (ORM)
RUN go install github.com/volatiletech/sqlboiler/v4@latest
RUN go install github.com/volatiletech/sqlboiler/v4/drivers/sqlboiler-psql@latest

# Goose for SQL Migrations
RUN go install github.com/pressly/goose/v3/cmd/goose@latest

# Open API Code Generator
RUN go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest

# Golang linter
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.22.3

# Protocol Buffers Compiler & plugins
RUN apt update
RUN apt install -y protobuf-compiler
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
2 changes: 1 addition & 1 deletion tests/client/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d094107

Please sign in to comment.