Skip to content

Commit b5878c8

Browse files
doosuuMP91dennismeister93
authored
feature: Add project creation script and tests (#107)
* script to copy files * Fix path to copy from and let copy example overwrite existing dir Signed-off-by: Dennis Meister <[email protected]> * extract method * Add integration tests for create command * Distinguish between different matrix logs * Add minimal mock config * Disable local runtime * Fix pre-commit in created projects * Exclude examples from linting * Fix execution order in workflow * Update examples/seat-adjuster/src/vapp.py Co-authored-by: Markus Petke <[email protected]> * Fix review findings * Exclude wrong tests * WIP file check Signed-off-by: Dennis Meister <[email protected]> * Get rid of vscode settings file check Signed-off-by: Dennis Meister <[email protected]> * Add runtime stopping in tests again Signed-off-by: Dennis Meister <[email protected]> * Remove code path for pre-existing git repository * Add CLI tag for checkout * Revert "Remove code path for pre-existing git repository" This reverts commit 968dda7. * Fix dependency conflicts * Remove git initialization * Fix pip-compile * Fix pre-commit run * Run pip-compile as module * make pip-compile silent + remove tox * Print to stdout/stderr for error finding in CI * remove root requirements.txt since it is generated * Revert "Print to stdout/stderr for error finding in CI" This reverts commit d41921e. * remove unnecessary pip compile * bump sdk version * fix creation logs * fix * remove appManifest from skeleton * fix script * another fix * Upgrade grpcio(-tools) and fix header * Debugging * change CLI ref * Fix workflow * Fix CLI version for CI workflow * remove requirements.txt as it is generated during creation * fix license --------- Signed-off-by: Dennis Meister <[email protected]> Co-authored-by: Markus Petke <[email protected]> Co-authored-by: Dennis Meister <[email protected]>
1 parent f35fb79 commit b5878c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1296
-140
lines changed

.devcontainer/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#
1313
# SPDX-License-Identifier: Apache-2.0
1414

15-
FROM ghcr.io/eclipse-velocitas/devcontainer-base-images/python:v0.1
15+
FROM ghcr.io/eclipse-velocitas/devcontainer-base-images/python:v0.2
1616

1717
# Force dapr to use localhost traffic
1818
ENV DAPR_HOST_IP="127.0.0.1"

.devcontainer/devcontainer.json

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"python.formatting.provider": "black",
2121
"python.linting.banditEnabled": true,
2222
"python.linting.flake8Enabled": true,
23+
"editor.defaultFormatter": "ms-python.black-formatter",
2324
"terminal.integrated.defaultProfile.linux": "zsh",
2425
"terminal.integrated.profiles.linux": {
2526
"zsh": {
@@ -38,6 +39,7 @@
3839
"ms-kubernetes-tools.vscode-kubernetes-tools",
3940
"matangover.mypy",
4041
"anweber.vscode-httpyac",
42+
"ms-python.black-formatter",
4143
"ms-python.isort",
4244
"ms-python.flake8"
4345
]
+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Copyright (c) 2023 Robert Bosch GmbH
2+
#
3+
# This program and the accompanying materials are made available under the
4+
# terms of the Apache License, Version 2.0 which is available at
5+
# https://www.apache.org/licenses/LICENSE-2.0.
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
#
13+
# SPDX-License-Identifier: Apache-2.0
14+
15+
name: Project creation
16+
17+
concurrency:
18+
group: ${{ github.ref }}-project-creation
19+
cancel-in-progress: true
20+
21+
on:
22+
workflow_dispatch:
23+
push:
24+
# Run only on branches/commits and not tags
25+
branches:
26+
- main
27+
pull_request:
28+
branches:
29+
- main
30+
31+
jobs:
32+
check-project-creation:
33+
name: Check project creation
34+
runs-on: ubuntu-22.04
35+
strategy:
36+
matrix:
37+
example: ["no-example", "seat-adjuster"]
38+
fail-fast: false
39+
40+
steps:
41+
- uses: actions/setup-node@v3
42+
with:
43+
node-version: latest
44+
45+
- name: Checkout CLI
46+
uses: actions/checkout@v4
47+
with:
48+
repository: eclipse-velocitas/cli
49+
path: cli
50+
ref: v0.6.3
51+
52+
- name: Checkout SDK repo
53+
uses: actions/checkout@v4
54+
with:
55+
path: sdk
56+
57+
- name: Install CLI
58+
shell: bash
59+
run: |
60+
cd cli
61+
npm i && npm run build && npx oclif manifest && npm i -g .
62+
63+
- name: Create project
64+
shell: bash
65+
run: |
66+
git config --global user.name "Git User"
67+
git config --global user.email "[email protected]"
68+
69+
# overwrite SDK path in order to use scripts from this branch (rather than sdk/main)
70+
export VELOCITAS_SDK_PATH_OVERRIDE=$(pwd)/sdk
71+
72+
mkdir app
73+
cd app
74+
75+
# show available commands and version of CLI
76+
velocitas
77+
78+
# copy "full" package-index.json from CLI repo
79+
cp ../cli/testbench/test-create/vehicle-app-template/package-index.json ./package-index.json
80+
CREATE_ARGS="-n MyApp"
81+
if [ "${{ matrix.example }}" != "no-example" ]; then
82+
CREATE_ARGS="-e ${{ matrix.example }}"
83+
fi
84+
velocitas create -l python $CREATE_ARGS
85+
86+
- name: Install dependencies
87+
shell: bash
88+
run: |
89+
pip install -r ./sdk/.project-creation/test/requirements.txt
90+
91+
- name: Run verification on generated project
92+
shell: bash
93+
run: |
94+
export VELOCITAS_SDK_ROOT=./sdk
95+
export VELOCITAS_APP_ROOT=./app
96+
97+
# debug print contents
98+
ls -al $VELOCITAS_APP_ROOT
99+
100+
pytest --ignore-glob=**/.devcontainer/* --ignore-glob=**/.skeleton/* ./sdk/.project-creation
101+
102+
- name: Check if devContainer starts up properly and app is usable
103+
uses: devcontainers/[email protected]
104+
with:
105+
subFolder: ./app
106+
runCmd: |
107+
git init && \
108+
pre-commit run --all-files && \
109+
pip3 install -r .devcontainer/tests/automated_tests/requirements.txt && \
110+
cat app/AppManifest.json && \
111+
velocitas exec grpc-interface-support generate-sdk && \
112+
pytest -sx .devcontainer/tests/automated_tests
113+
114+
- name: Upload logs
115+
uses: actions/upload-artifact@v3
116+
if: always()
117+
with:
118+
name: logs_${{ matrix.example }}
119+
path: ./app/logs
120+
retention-days: 1

.pre-commit-config.yaml

+10-7
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,25 @@ repos:
5353
(?x)^(
5454
.*_pb2.py|
5555
.*_pb2.pyi|
56-
.*_pb2_grpc.py
56+
.*_pb2_grpc.py|
57+
examples/.*|
58+
.project-creation/.skeleton/.*
5759
)$
5860
5961
- repo: https://github.com/psf/black
60-
rev: 23.1.0
62+
rev: 23.9.1
6163
hooks:
6264
- id: black
6365
exclude: >
6466
(?x)^(
6567
.*_pb2.py|
6668
.*_pb2.pyi|
67-
.*_pb2_grpc.py
69+
.*_pb2_grpc.py|
70+
examples/.*
6871
)$
6972
7073
- repo: https://github.com/PyCQA/flake8
71-
rev: 6.0.0
74+
rev: 6.1.0
7275
hooks:
7376
- id: flake8
7477
exclude: >
@@ -82,14 +85,14 @@ repos:
8285
- flake8-unused-arguments
8386

8487
- repo: https://github.com/PyCQA/bandit
85-
rev: 1.7.4
88+
rev: 1.7.5
8689
hooks:
8790
- id: bandit
8891
args: ["--skip=B101"]
8992
types_or: [python]
9093

9194
- repo: https://github.com/pre-commit/mirrors-mypy
92-
rev: "v0.991"
95+
rev: v1.5.1
9396
hooks:
9497
- id: mypy
9598
exclude: >
@@ -98,7 +101,7 @@ repos:
98101
.*_pb2.pyi|
99102
.*_pb2_grpc.py
100103
)$
101-
args: [velocitas_sdk]
104+
args: [.]
102105
language: system
103106
pass_filenames: false
104107

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copyright (c) 2023 Contributors to the Eclipse Foundation
2+
#
3+
# This program and the accompanying materials are made available under the
4+
# terms of the Apache License, Version 2.0 which is available at
5+
# https://www.apache.org/licenses/LICENSE-2.0.
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
#
13+
# SPDX-License-Identifier: Apache-2.0
14+
15+
# syntax=docker/dockerfile:1.2
16+
17+
# Build stage, to create the executable
18+
FROM --platform=$TARGETPLATFORM ghcr.io/eclipse-velocitas/devcontainer-base-images/python:v0.2 as builder
19+
ARG TARGETARCH
20+
21+
RUN apt-get update && apt-get install -y python3-dev
22+
23+
COPY ./.velocitas.json /workspace/.velocitas_org.json
24+
COPY ./app /workspace/app
25+
26+
# FIXME: For build tooling we only need "devenv-devcontainer-setup", we should be able to
27+
# filter this without manual jq intervention...
28+
RUN cat ./workspace/.velocitas_org.json | jq 'del(.packages[] | select(.name|test(".*devenv-devcontainer-setup.*")|not))' > ./workspace/.velocitas.json
29+
30+
# Remove this installation for Arm64 once staticx has a prebuilt wheel for Arm64
31+
RUN /bin/bash -c 'set -ex && \
32+
ARCH=`uname -m` && \
33+
if [ "$ARCH" == "aarch64" ]; then \
34+
echo "ARM64" && \
35+
apt-get install -y gcc && \
36+
pip3 install --no-cache-dir scons; \
37+
fi'
38+
39+
RUN pip3 install --no-cache-dir pyinstaller==5.9.0 \
40+
&& pip3 install --no-cache-dir patchelf==0.17.0.0 \
41+
&& pip3 install --no-cache-dir staticx \
42+
&& pip3 install --no-cache-dir -r ./workspace/app/requirements.txt \
43+
&& pip3 install --no-cache-dir -r ./workspace/app/requirements-links.txt
44+
45+
WORKDIR /workspace
46+
47+
RUN velocitas init
48+
49+
WORKDIR /workspace/app
50+
51+
RUN pyinstaller --clean -F -s -p src src/main.py
52+
53+
WORKDIR /workspace/app/dist
54+
55+
RUN staticx main run-exe
56+
57+
# Runner stage, to copy the executable
58+
FROM scratch
59+
60+
COPY --from=builder ./workspace/app/dist/run-exe /dist/
61+
62+
WORKDIR /tmp
63+
WORKDIR /dist
64+
65+
ENV PATH="/dist:$PATH"
66+
67+
LABEL org.opencontainers.image.source="https://github.com/eclipse-velocitas/vehicle-app-python-template"
68+
69+
CMD ["./run-exe"]

.project-creation/.skeleton/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# AppName Readme
2+
3+
A simple skeleton app for getting you up and running with Velocitas app development.

.project-creation/.skeleton/requirements-links.txt

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
velocitas-sdk==0.13.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
grpcio==1.59.0
2+
protobuf==4.24.4
3+
dapr==1.11.0
4+
cloudevents==1.10.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.10
3+
# by the following command:
4+
#
5+
# pip-compile requirements.in
6+
#
7+
aiohttp==3.8.6
8+
# via dapr
9+
aiosignal==1.3.1
10+
# via aiohttp
11+
async-timeout==4.0.3
12+
# via aiohttp
13+
attrs==23.1.0
14+
# via aiohttp
15+
charset-normalizer==3.3.0
16+
# via aiohttp
17+
cloudevents==1.10.0
18+
# via -r requirements.in
19+
dapr==1.11.0
20+
# via -r requirements.in
21+
deprecation==2.1.0
22+
# via cloudevents
23+
frozenlist==1.4.0
24+
# via
25+
# aiohttp
26+
# aiosignal
27+
grpcio==1.59.0
28+
# via
29+
# -r requirements.in
30+
# dapr
31+
idna==3.4
32+
# via yarl
33+
multidict==6.0.4
34+
# via
35+
# aiohttp
36+
# yarl
37+
packaging==23.2
38+
# via deprecation
39+
protobuf==4.24.4
40+
# via
41+
# -r requirements.in
42+
# dapr
43+
python-dateutil==2.8.2
44+
# via dapr
45+
six==1.16.0
46+
# via python-dateutil
47+
typing-extensions==4.8.0
48+
# via dapr
49+
yarl==1.9.2
50+
# via aiohttp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2023 Contributors to the Eclipse Foundation
2+
#
3+
# This program and the accompanying materials are made available under the
4+
# terms of the Apache License, Version 2.0 which is available at
5+
# https://www.apache.org/licenses/LICENSE-2.0.
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
#
13+
# SPDX-License-Identifier: Apache-2.0
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright (c) 2022-2023 Contributors to the Eclipse Foundation
2+
#
3+
# This program and the accompanying materials are made available under the
4+
# terms of the Apache License, Version 2.0 which is available at
5+
# https://www.apache.org/licenses/LICENSE-2.0.
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
#
13+
# SPDX-License-Identifier: Apache-2.0
14+
15+
"""The launcher for starting a Vehicle App."""
16+
17+
import asyncio
18+
import logging
19+
import signal
20+
21+
from vapp import AppName # type: ignore # noqa: E402
22+
from velocitas_sdk.util.log import ( # type: ignore
23+
get_opentelemetry_log_factory,
24+
get_opentelemetry_log_format,
25+
)
26+
27+
logging.setLogRecordFactory(get_opentelemetry_log_factory())
28+
logging.basicConfig(format=get_opentelemetry_log_format())
29+
logging.getLogger().setLevel("DEBUG")
30+
logger = logging.getLogger(__name__)
31+
32+
33+
async def main():
34+
"""Main function"""
35+
logger.info("Starting AppName app...")
36+
app = AppName()
37+
await app.run()
38+
39+
40+
LOOP = asyncio.get_event_loop()
41+
LOOP.add_signal_handler(signal.SIGTERM, LOOP.stop)
42+
LOOP.run_until_complete(main())
43+
LOOP.close()

0 commit comments

Comments
 (0)