Skip to content

Commit f800ea7

Browse files
committed
fix docs: clean up userver-create-service docs
commit_hash:692a2992eb562454f4b530618dcee9a41560ba84
1 parent 7f931bf commit f800ea7

8 files changed

Lines changed: 119 additions & 81 deletions

File tree

.mapping.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3742,6 +3742,7 @@
37423742
"scripts/docs/en/userver/tutorial/websocket_service.md":"taxi/uservices/userver/scripts/docs/en/userver/tutorial/websocket_service.md",
37433743
"scripts/docs/en/userver/ydb.md":"taxi/uservices/userver/scripts/docs/en/userver/ydb.md",
37443744
"scripts/docs/examples/service-template/CMakeUserPresets.json.example":"taxi/uservices/userver/scripts/docs/examples/service-template/CMakeUserPresets.json.example",
3745+
"scripts/docs/examples/service-template/userver-create-service.sh":"taxi/uservices/userver/scripts/docs/examples/service-template/userver-create-service.sh",
37453746
"scripts/docs/fontello/README.txt":"taxi/uservices/userver/scripts/docs/fontello/README.txt",
37463747
"scripts/docs/fontello/config.json":"taxi/uservices/userver/scripts/docs/fontello/config.json",
37473748
"scripts/docs/fontello/css/animation.css":"taxi/uservices/userver/scripts/docs/fontello/css/animation.css",
@@ -3878,6 +3879,7 @@
38783879
"service_template/.gitignore":"taxi/uservices/userver/service_template/.gitignore",
38793880
"service_template/.vscode/README.md":"taxi/uservices/userver/service_template/.vscode/README.md",
38803881
"service_template/.vscode/c_cpp_properties.json":"taxi/uservices/userver/service_template/.vscode/c_cpp_properties.json",
3882+
"service_template/.vscode/settings.json":"taxi/uservices/userver/service_template/.vscode/settings.json",
38813883
"service_template/CMakeLists.txt":"taxi/uservices/userver/service_template/CMakeLists.txt",
38823884
"service_template/CMakePresets.json":"taxi/uservices/userver/service_template/CMakePresets.json",
38833885
"service_template/Makefile":"taxi/uservices/userver/service_template/Makefile",

scripts/docs/en/userver/build/build.md

Lines changed: 65 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,105 +5,108 @@
55

66
1\. @ref ways_to_get_userver "Get userver".
77

8-
2\. Create new service with the following command (if you installed userver system-wide):
8+
2\. Create a new service project with the following command:
99

1010
```shell
11-
userver-create-service myservice
11+
userver-create-service [--grpc] [--mongo] [--postgresql] myservice
1212
```
1313

14-
If you installed userver via CPM or as a git repository, call script from userver directory:
15-
```shell
16-
userver/scripts/userver-create-service myservice
17-
```
14+
This will create `myservice` dir, relative to the current working directory.
15+
16+
If you did not install userver system-wide and the command above is not found, see @ref service_templates.
17+
18+
To use additional userver libraries later, see @ref service_templates_libraries.
1819

19-
If you want to enable gRPC, postgresql, or mongo in your service, use the following flags:
20+
3\. Build and test your service. Run in the service project root:
2021

2122
```shell
22-
userver-create-service --grpc --mongo --postgresql myservice
23+
make build-debug && \
24+
make test-debug
2325
```
2426

25-
3\. Build and test your service. Run in the service repo root:
27+
4\. To get a feel for how the service runs without needing to set up full production environment, run:
2628

2729
```shell
28-
make build-release && \
29-
make test-release
30+
myservice$ make start-debug
3031
```
3132

32-
Now you are ready for fast and comfortable creation of C++ microservices, services and utilities!
33-
33+
Wait until the service starts, then try to send a request.
3434

35-
## Quick start for beginners (old way)
35+
```shell
36+
curl http://127.0.0.1:8080/hello?name=userver
37+
```
3638

37-
1\. Press the "Use this template" button at the top right of the
38-
[GitHub template page](https://github.com/userver-framework/service_template).
39+
The answer should be something like this:
3940

40-
@warning [service_template](https://github.com/userver-framework/service_template) has no databases and uses HTTP.
41-
If you need gRPC or a database, please use other @ref service_templates "templates".
41+
```shell
42+
> curl http://127.0.0.1:8080/hello?name=userver
43+
Hello, userver!
44+
```
4245

43-
2\. Clone the service:
46+
5\. (Optional) Add the service project to Git:
4447

4548
```shell
46-
git clone https://github.com/your-username/your-service.git && cd your-service
49+
myservice$ git init && git add . && git commit -m "Initial commit"
4750
```
4851

49-
3\. @ref ways_to_get_userver "Get userver".
52+
Push it to GitHub
53+
(see [its documentation](https://docs.github.com/en/migrations/importing-source-code/using-the-command-line-to-import-source-code/adding-locally-hosted-code-to-github#adding-a-local-repository-to-github-using-git)).
5054

51-
4\. Build and start your service. Run in the service repo root:
55+
There are preconfigured GitHub CI checks that run ctest tests.
5256

53-
```shell
54-
make build-release && \
55-
make start-release
56-
```
57+
Now you are ready for fast and comfortable creation of C++ microservices, services and utilities!
5758

58-
During the build, you can make a coffee break until approximately the following output appears:
59+
## Quick start for beginners (old way, pre userver 2.8)
5960

60-
```shell
61-
====================================================================================================
62-
Started service at http://localhost:8080/, configured monitor URL is http://localhost:-1/
63-
====================================================================================================
61+
@warning Service template repositories are deprecated, because possible sets of userver libraries to include cause
62+
an exponential growth in the number of wanted repositories. For userver 2.9 and later, use
63+
the @ref quick_start_for_beginners "service project generator script" instead.
6464

65-
PASSED
66-
[service-runner] Service started, use C-c to terminate
67-
INFO <userver> Server is started
68-
...
69-
DEBUG <userver> Accepted connection #2/32768
70-
DEBUG <userver> Incoming connection from ::ffff:127.0.0.1, fd 43
65+
1\. Press the "Use this template" button at the top right of the appropriate service template repo page:
7166

72-
```
67+
| Link | Contains |
68+
|------------------------------------------------------------------|------------------------|
69+
| https://github.com/userver-framework/service_template | HTTP |
70+
| https://github.com/userver-framework/pg_service_template | HTTP, PostgreSQL |
71+
| https://github.com/userver-framework/pg_grpc_service_template | HTTP, PostgreSQL, gRPC |
72+
| https://github.com/userver-framework/mongo_grpc_service_template | HTTP, MongoDB, gRPC |
7373

74-
5\. Try to send a request.
74+
2\. Clone the service:
7575

7676
```shell
77-
curl http://127.0.0.1:8080/hello?name=userver
77+
git clone https://github.com/your-username/your-service.git && cd your-service
7878
```
7979

80-
The answer should be something like this:
80+
3\. Give a proper name to your service and replace all the occurrences of "*service_template" string with that name:
8181

8282
```shell
83-
> curl http://127.0.0.1:8080/hello?name=userver
84-
Hello, userver!
83+
find . -not -path "./third_party/*" -not -path ".git/*" -not -path './build-*' -type f | xargs sed -i 's/service_template/YOUR_SERVICE_NAME/g'
8584
```
8685

87-
Now you are ready for fast and comfortable creation of C++ microservices, services and utilities!
86+
4\. @ref ways_to_get_userver "Get userver".
87+
88+
5\. Build and test the service, see steps 3-4 from the @ref quick_start_for_beginners "updated instruction above".
8889

8990
@anchor service_templates
9091
## Service templates for userver based services
9192

92-
There are ready to use service templates at GitHub:
93+
To create a new service project, run:
9394

94-
| Link | Contains |
95-
|------------------------------------------------------------------|------------------------|
96-
| https://github.com/userver-framework/service_template | HTTP |
97-
| https://github.com/userver-framework/pg_service_template | HTTP, PostgreSQL |
98-
| https://github.com/userver-framework/pg_grpc_service_template | HTTP, PostgreSQL, gRPC |
99-
| https://github.com/userver-framework/mongo_grpc_service_template | HTTP, MongoDB, gRPC |
95+
```shell
96+
userver-create-service [--grpc] [--mongo] [--postgresql] myservice
97+
```
10098

101-
To create a service:
99+
* Project directory will be `myservice`, relative to the current working directory;
100+
* service name will be the last segment of the path;
101+
* even without feature flags, the service only has some stubs for HTTP handlers.
102102

103-
1. Press the "Use this template" button at the top right of the GitHub template page
104-
2. Clone the service `git clone your-service-repo && cd your-service-repo`
105-
3. Give a proper name to your service and replace all the occurrences of "*service_template" string with that name.
106-
4. Feel free to tweak, adjust or fully rewrite the source code of your service.
103+
If instead of installing userver you are planning to build userver as a subdirectory, call the script from userver directory:
104+
105+
```shell
106+
path/to/userver/scripts/userver-create-service myservice
107+
```
108+
109+
If you use CPM to download userver, see @ref userver_cpm "CPM section".
107110

108111
You'll need to @ref ways_to_get_userver "get userver" before proceeding with local development.
109112

@@ -246,9 +249,7 @@ Some advice:
246249
### Downloading userver using CPM
247250

248251
userver itself can be downloaded and built using CPM.
249-
In fact, this is what
250-
[download_userver()](https://github.com/userver-framework/service_template/blob/develop/cmake/DownloadUserver.cmake)
251-
function does in @ref service_templates "service templates" by default.
252+
In fact, this is what `download_userver()` function does in @ref service_templates "service templates" by default.
252253
253254
`download_userver()` just calls `CPMAddPackage` with some defaults, so you can pin userver `VERSION` or `GIT_TAG`
254255
for reproducible builds.
@@ -258,6 +259,10 @@ When acquiring userver via CPM, you first need to install build dependencies. Th
258259
* install @ref scripts/docs/en/userver/build/dependencies.md "build dependencies"
259260
* or use base image of @ref docker_with_ubuntu_22_04
260261
262+
To use a @ref service_templates "service template" with CPM, run this script to get `userver-create-service` command:
263+
264+
@ref service-template/userver-create-service.sh
265+
261266
Make sure to @ref service_templates_presets "enable" the CMake options to build userver libraries you need,
262267
then link to those libraries.
263268
@@ -480,3 +485,4 @@ The resulting binary should be 2-15% faster than without PGO, depending on the c
480485
@htmlonly </div> @endhtmlonly
481486
482487
@example service-template/CMakeUserPresets.json.example
488+
@example service-template/userver-create-service.sh

scripts/docs/en/userver/supported_platforms.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,21 @@ organization page contains multiple repositories, including:
3030
* [uservice-dynconf](https://github.com/userver-framework/uservice-dynconf) -
3131
the service to control dynamic configs of the other userver-based services.
3232

33-
Also there are several legacy template services (use userver-create-service script instead):
33+
Also, there are several legacy template services
34+
(use @ref quick_start_for_beginners "userver-create-service" script instead):
3435

3536
* [service_template](https://github.com/userver-framework/service_template) -
36-
template of a C++ service that uses userver framework with ready-to-user
37-
build, test and CI scripts.
37+
template of a C++ service that uses userver framework with ready-to-use
38+
build, test and CI scripts.
3839
* [pg_service_template](https://github.com/userver-framework/pg_service_template) -
39-
template of a C++ service that uses userver framework with ready-to-user PostgreSQL database,
40-
build, test and CI scripts.
40+
template of a C++ service that uses userver framework with ready-to-use PostgreSQL database,
41+
build, test and CI scripts.
4142
* [pg_grpc_service_template](https://github.com/userver-framework/pg_grpc_service_template) -
42-
template of a C++ service that uses userver framework with ready-to-user PostgreSQL database, gRPC server,
43-
build, test and CI scripts.
43+
template of a C++ service that uses userver framework with ready-to-use PostgreSQL database, gRPC server,
44+
build, test and CI scripts.
45+
* [mongo_grpc_service_template](https://github.com/userver-framework/mongo_grpc_service_template) -
46+
template of a C++ service that uses userver framework with ready-to-use Mongo database, gRPC server,
47+
build, test and CI scripts.
4448

4549
All the repositories are part of the userver framework,
4650
thus they support the same set of architectures, compilers, operating systems
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
userver-create-service() {
2+
REPO_URL="https://github.com/userver-framework/userver.git"
3+
BRANCH="develop"
4+
WORKDIR="/tmp/userver-create-service"
5+
if [ ! -d "$WORKDIR" ]; then
6+
mkdir -p "$WORKDIR"
7+
git clone -q --depth 1 --branch "$REPO_URL" "$BRANCH" "$WORKDIR"
8+
fi
9+
"$WORKDIR/scripts/userver-create-service" "$@"
10+
}

scripts/userver-create-service

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,20 @@ def parse_args():
3333
description='Create new C++ userver-based service')
3434
for feature in FEATURES:
3535
parser.add_argument(f'--{feature}', action='store_true')
36-
parser.add_argument('service_path')
36+
parser.add_argument('service_path', type=pathlib.Path)
3737
return parser.parse_args()
3838

3939

40-
def service_name(service_path: str) -> str:
41-
return os.path.basename(os.path.normpath(service_path)).replace('-', '_')
40+
def service_name(service_path: pathlib.Path) -> str:
41+
return service_path.resolve().name.replace('-', '_')
4242

4343

4444
def handle_file(src: pathlib.Path, dst: pathlib.Path, args) -> bool:
4545
orig_text = src.read_text()
4646
text = []
4747
skip = False
4848
for line in orig_text.splitlines():
49-
line = line.replace('service_template',
50-
service_name(args.service_path))
49+
line = line.replace('service_template', service_name(args.service_path))
5150
match_on = TEMPLATE_ON_REGEX.match(line)
5251
match_current = TEMPLATE_CURRENT_REGEX.match(line)
5352
if match_on:
@@ -74,7 +73,7 @@ def handle_file(src: pathlib.Path, dst: pathlib.Path, args) -> bool:
7473
def copy_tree(src: pathlib.Path, dst: pathlib.Path, args) -> None:
7574
for root, _, files in os.walk(src):
7675
dst_root = dst / pathlib.Path(root).relative_to(src)
77-
os.makedirs(dst_root, exist_ok=True)
76+
dst_root.mkdir(parents=True, exist_ok=True)
7877
dst_root_is_empty = True
7978

8079
for file in files:
@@ -91,21 +90,20 @@ def run_ruff(src: pathlib.Path) -> None:
9190
try:
9291
subprocess.check_call(['ruff', 'format', str(src)])
9392
except BaseException as exc:
94-
print(f'Failed to run ruff ({exc}), skipping.')
93+
print(f'Warning: Failed to run ruff ({exc}), skipping.', file=sys.stderr)
9594

9695

97-
def check_dst_non_existing(service_path: str):
98-
if pathlib.Path(service_path).exists():
99-
print(f'Error: {service_path} directory already exists.',
100-
file=sys.stderr)
96+
def check_dst_non_existing(service_path: pathlib.Path):
97+
if service_path.exists():
98+
print(f'Error: {service_path} directory already exists.', file=sys.stderr)
10199
sys.exit(1)
102100

103101

104102
def main() -> None:
105103
args = parse_args()
106104
check_dst_non_existing(args.service_path)
107105
copy_tree(template_path(), args.service_path, args)
108-
run_ruff(pathlib.Path(args.service_path))
106+
run_ruff(args.service_path)
109107

110108

111109
if __name__ == '__main__':

service_template/.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# NOTE: if this CI check breaks, just remove it, docker checks are enough anyway.
2+
13
name: CI
24

35
'on':

service_template/.github/workflows/docker.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ name: Docker build
1010
- develop
1111
- feature/**
1212

13+
env:
14+
UBSAN_OPTIONS: print_stacktrace=1
15+
1316
jobs:
1417
tests:
1518
runs-on: ubuntu-latest
@@ -28,10 +31,10 @@ jobs:
2831
ccache-
2932
3033
- name: Cmake
31-
run: make docker-cmake-release
34+
run: make docker-cmake-debug
3235

3336
- name: Build
34-
run: make docker-build-release
37+
run: make docker-build-debug
3538

3639
- name: Test
37-
run: make docker-test-release
40+
run: make docker-test-debug
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"cmake.automaticReconfigure": false,
3+
"cmake.configureOnEdit": false,
4+
"cmake.configureOnOpen": false,
5+
"cmake.copyCompileCommands": "${workspaceFolder}/.vscode/compile_commands.json",
6+
"clangd.arguments": [
7+
"--background-index",
8+
"--compile-commands-dir=.vscode",
9+
"--clang-tidy",
10+
"--completion-style=detailed",
11+
"--header-insertion=never"
12+
]
13+
}

0 commit comments

Comments
 (0)