Skip to content

Commit e3e66ff

Browse files
committed
feat build: bake in the correct stable version of devcontainer in userver-create-service
commit_hash:fa45a4c0930c501101d91f4486712b29f99be8ac
1 parent 0feffed commit e3e66ff

File tree

9 files changed

+62
-5
lines changed

9 files changed

+62
-5
lines changed

.cmake-format.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
'PROGRAMS': '*',
3939
'FILES': '*',
4040
'DESTINATION': '*',
41+
'RENAME': '*',
4142
},
4243
},
4344
'userver_target_generate_openapi_client': {

.mapping.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4420,6 +4420,7 @@
44204420
"scripts/docs/en/userver/tutorial/websocket_service.md":"taxi/uservices/userver/scripts/docs/en/userver/tutorial/websocket_service.md",
44214421
"scripts/docs/en/userver/ydb.md":"taxi/uservices/userver/scripts/docs/en/userver/ydb.md",
44224422
"scripts/docs/examples/service-template/CMakeUserPresets.json.example":"taxi/uservices/userver/scripts/docs/examples/service-template/CMakeUserPresets.json.example",
4423+
"scripts/docs/examples/service-template/userver-create-service.bat":"taxi/uservices/userver/scripts/docs/examples/service-template/userver-create-service.bat",
44234424
"scripts/docs/examples/service-template/userver-create-service.sh":"taxi/uservices/userver/scripts/docs/examples/service-template/userver-create-service.sh",
44244425
"scripts/docs/fontello/README.txt":"taxi/uservices/userver/scripts/docs/fontello/README.txt",
44254426
"scripts/docs/fontello/config.json":"taxi/uservices/userver/scripts/docs/fontello/config.json",

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ if(USERVER_FEATURE_CORE)
336336
COMPONENT core
337337
PROGRAMS "${USERVER_ROOT_DIR}/scripts/userver-create-service"
338338
DESTINATION ${CMAKE_INSTALL_BINDIR}/
339+
RENAME userver-create-service
339340
)
340341
_userver_directory_install(
341342
COMPONENT core

cmake/PrepareInstall.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function(_userver_directory_install)
7777
return()
7878
endif()
7979
set(option)
80-
set(oneValueArgs COMPONENT DESTINATION PATTERN)
80+
set(oneValueArgs COMPONENT DESTINATION PATTERN RENAME)
8181
set(multiValueArgs FILES DIRECTORY PROGRAMS)
8282
cmake_parse_arguments(ARG "${option}" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}")
8383
if(NOT ARG_COMPONENT)
@@ -97,13 +97,15 @@ function(_userver_directory_install)
9797
PROGRAMS ${ARG_PROGRAMS}
9898
DESTINATION ${ARG_DESTINATION}
9999
COMPONENT ${ARG_COMPONENT}
100+
RENAME ${ARG_RENAME}
100101
)
101102
endif()
102103
if(ARG_FILES)
103104
install(
104105
FILES ${ARG_FILES}
105106
DESTINATION ${ARG_DESTINATION}
106107
COMPONENT ${ARG_COMPONENT}
108+
RENAME ${ARG_RENAME}
107109
)
108110
endif()
109111
if(ARG_DIRECTORY)

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,13 @@ userver-create-service [--grpc] [--mongo] [--postgresql] myservice
104104
* without feature flags, the service only has some stubs for HTTP handlers.
105105

106106
If you use @ref devcontainers "Dev Containers", or if you use CPM to download userver,
107-
run this script to get `userver-create-service` command:
107+
run this script as the `userver-create-service` command:
108108

109-
@ref service-template/userver-create-service.sh
109+
* Linux, macOS, BSD: @ref service-template/userver-create-service.sh
110+
* Windows: @ref service-template/userver-create-service.bat
111+
112+
In the command, replace `vMAJOR.MINOR` with the actual userver version, or use `develop` to get bleeding-edge features
113+
at your own risk.
110114

111115
If instead of installing userver you are planning to build userver as a subdirectory,
112116
call the script from userver directory:
@@ -523,3 +527,4 @@ The resulting binary should be 2-15% faster than without PGO, depending on the c
523527
524528
@example service-template/CMakeUserPresets.json.example
525529
@example service-template/userver-create-service.sh
530+
@example service-template/userver-create-service.bat
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@echo off
2+
setlocal
3+
4+
set "REPO_URL=https://github.com/userver-framework/userver.git"
5+
set "BRANCH=vMAJOR.MINOR"
6+
set "WORKDIR=%TEMP%\userver-create-service\%BRANCH%"
7+
8+
if not exist "%WORKDIR%\" (
9+
mkdir "%WORKDIR%"
10+
git clone -q --depth 1 --branch "%BRANCH%" "%REPO_URL%" "%WORKDIR%"
11+
)
12+
13+
py -3 "%WORKDIR%\scripts\userver-create-service" %*

scripts/docs/examples/service-template/userver-create-service.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
REPO_URL="https://github.com/userver-framework/userver.git"
2-
BRANCH="develop"
3-
WORKDIR="/tmp/userver-create-service"
2+
BRANCH="vMAJOR.MINOR"
3+
WORKDIR="/tmp/userver-create-service/$BRANCH"
44
if [ ! -d "$WORKDIR" ]; then
55
mkdir -p "$WORKDIR"
66
git clone -q --depth 1 --branch "$BRANCH" "$REPO_URL" "$WORKDIR"

scripts/userver-create-service

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,34 @@ def template_path() -> pathlib.Path:
2828
return BINDIR / '..' / 'service_template'
2929

3030

31+
def version_file_path() -> pathlib.Path:
32+
if is_system_installed():
33+
return BINDIR / '..' / 'share' / 'userver' / 'version.txt'
34+
return BINDIR / '..' / 'version.txt'
35+
36+
37+
def get_userver_version() -> str:
38+
version_path = version_file_path()
39+
return version_path.read_text().strip()
40+
41+
42+
def get_devcontainer_version(userver_version: str) -> str:
43+
if userver_version.endswith('-rc'):
44+
return 'latest'
45+
return f'v{userver_version}'
46+
47+
48+
def patch_devcontainer_version(service_path: pathlib.Path) -> None:
49+
devcontainer_path = service_path / '.devcontainer' / 'devcontainer.json'
50+
51+
userver_version = get_userver_version()
52+
devcontainer_version = get_devcontainer_version(userver_version)
53+
54+
content = devcontainer_path.read_text()
55+
content = re.sub(r'"(ghcr\.io/[^"]+)"', rf'"\1:{devcontainer_version}"', content)
56+
devcontainer_path.write_text(content)
57+
58+
3159
def parse_args():
3260
parser = argparse.ArgumentParser(
3361
description='Create new C++ userver-based service')
@@ -103,6 +131,7 @@ def main() -> None:
103131
args = parse_args()
104132
check_dst_non_existing(args.service_path)
105133
copy_tree(template_path(), args.service_path, args)
134+
patch_devcontainer_version(args.service_path)
106135
run_ruff(args.service_path)
107136

108137

universal/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,11 @@ _userver_directory_install(
436436
"${USERVER_ROOT_DIR}/cmake/modules/FindUserverGBench.cmake"
437437
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver/modules
438438
)
439+
_userver_directory_install(
440+
COMPONENT universal
441+
FILES "${USERVER_ROOT_DIR}/version.txt"
442+
DESTINATION ${CMAKE_INSTALL_DATADIR}/userver
443+
)
439444

440445
_userver_install_component(MODULE universal)
441446

0 commit comments

Comments
 (0)