Skip to content

Commit b53c140

Browse files
Merge pull request #38 from spolti/sync
Sync
2 parents 79592e2 + 9633f2d commit b53c140

27 files changed

+635
-201
lines changed

.github/workflows/codeql.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: ["main"]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: ["main"]
20+
schedule:
21+
- cron: "30 8 * * *"
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
# Runner size impacts CodeQL analysis time. To learn more, please see:
27+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
28+
# - https://gh.io/supported-runners-and-hardware-resources
29+
# - https://gh.io/using-larger-runners
30+
# Consider using larger runners for possible analysis time improvements.
31+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
32+
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
33+
permissions:
34+
actions: read
35+
contents: read
36+
security-events: write
37+
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
language: ["go", "python"]
42+
# CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ]
43+
# Use only 'java-kotlin' to analyze code written in Java, Kotlin or both
44+
# Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
45+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
46+
47+
steps:
48+
- name: Checkout repository
49+
uses: actions/checkout@v3
50+
51+
# Initializes the CodeQL tools for scanning.
52+
- name: Initialize CodeQL
53+
uses: github/codeql-action/init@v2
54+
with:
55+
languages: ${{ matrix.language }}
56+
# If you wish to specify custom queries, you can do so here or in a config file.
57+
# By default, queries listed here will override any specified in a config file.
58+
# Prefix the list here with "+" to use these queries and those in the config file.
59+
60+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
61+
# queries: security-extended,security-and-quality
62+
63+
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
64+
# If this step fails, then you should remove it and run the build manually (see below)
65+
- name: Autobuild
66+
uses: github/codeql-action/autobuild@v2
67+
68+
# ℹ️ Command-line programs to run using the OS shell.
69+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
70+
71+
# If the Autobuild fails above, remove it and uncomment the following three lines.
72+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
73+
74+
# - run: |
75+
# echo "Run, Build Application using script"
76+
# ./location_of_script_within_repo/buildscript.sh
77+
78+
- name: Perform CodeQL Analysis
79+
uses: github/codeql-action/analyze@v2
80+
with:
81+
category: "/language:${{matrix.language}}"

Dockerfile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@ USER root
2424
ENV HOME=/root
2525

2626
# Install build and dev tools
27+
# NOTE: Require python38 to install pre-commit
2728
RUN --mount=type=cache,target=/root/.cache/dnf:rw \
2829
dnf install --setopt=cachedir=/root/.cache/dnf -y --nodocs \
29-
python3 \
30-
python3-pip \
3130
nodejs \
31+
python38 \
32+
&& ln -sf /usr/bin/python3 /usr/bin/python \
33+
&& ln -sf /usr/bin/pip3 /usr/bin/pip \
3234
&& true
3335

3436
# Install pre-commit
3537
ENV PIP_CACHE_DIR=/root/.cache/pip
3638
RUN --mount=type=cache,target=/root/.cache/pip \
37-
pip3 install pre-commit
39+
pip install pre-commit
3840

3941
# When using the BuildKit backend, Docker predefines a set of ARG variables with
4042
# information on the platform of the node performing the build (build platform)
@@ -77,9 +79,13 @@ WORKDIR /opt/app
7779
COPY go.mod go.sum ./
7880

7981
# Install go protoc plugins
82+
# no required module provides package google.golang.org/grpc/cmd/protoc-gen-go-grpc
83+
# to add it run `go get google.golang.org/grpc/cmd/protoc-gen-go-grpc`
8084
ENV PATH $HOME/go/bin:$PATH
81-
RUN go get google.golang.org/protobuf/cmd/protoc-gen-go \
82-
google.golang.org/grpc/cmd/protoc-gen-go-grpc \
85+
RUN true \
86+
&& go get google.golang.org/grpc/cmd/protoc-gen-go-grpc \
87+
&& go install google.golang.org/protobuf/cmd/protoc-gen-go \
88+
google.golang.org/grpc/cmd/protoc-gen-go-grpc \
8389
&& protoc-gen-go --version \
8490
&& true
8591

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,19 @@ build:
3434
build.develop:
3535
./scripts/build_docker.sh --target develop
3636

37+
.PHONY: use.develop
38+
## Check if developer image exists, build it if it doesn't
39+
use.develop:
40+
./scripts/build_docker.sh --target develop --use-existing
41+
3742
.PHONY: develop
3843
## Run interactive shell inside developer container
39-
develop: build.develop
44+
develop: use.develop
4045
./scripts/develop.sh
4146

4247
.PHONY: run
4348
## Run make target inside developer container (e.g. `make run fmt`)
44-
run: build.develop
49+
run: use.develop
4550
./scripts/develop.sh make $(RUN_ARGS)
4651

4752
.PHONY: test

README.md

Lines changed: 181 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
[![Build](https://github.com/kserve/modelmesh-runtime-adapter/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/kserve/modelmesh-runtime-adapter/actions/workflows/build.yml)
22

3-
# Modelmesh Runtime Adapter
3+
# ModelMesh Runtime Adapter
44

5-
This repo contains the unified puller/runtime-adapter image of the sidecar containers which run in the modelmesh-serving model server Pods. See the main [modelmesh-serving](https://github.com/kserve/modelmesh-serving) repo for more details.
5+
This repo contains the unified puller/runtime-adapter image of the sidecar containers
6+
which run in the ModelMesh Serving model server Pods. Take a look at the main
7+
[ModelMesh Serving](https://github.com/kserve/modelmesh-serving) repo for more details.
68

79
Logical subcomponents within the image:
810

@@ -12,8 +14,183 @@ Logical subcomponents within the image:
1214
- [model-mesh-ovms-adapter](model-mesh-ovms-adapter)
1315
- [model-mesh-torchserve-adapter](model-mesh-torchserve-adapter)
1416

15-
### Build Image
17+
## Generate sources
1618

17-
```bash
19+
The gRPC code stubs, interfaces and data access classes have to be generated by the
20+
[`protoc` compiler](https://protobuf.dev/getting-started/gotutorial/#compiling-protocol-buffers)
21+
from the `.proto` source files under `internal/proto/*`.
22+
23+
If any of the `.proto` files were modified, run the `protoc` compiler to regenerate
24+
the respective Go source code. It's recommended to use the developer image, which
25+
has all the required libraries pre-installed, by running `make run proto.compile`
26+
instead of `make proto.compile`.
27+
28+
```shell
29+
make run proto.compile
30+
```
31+
32+
## Test the code changes
33+
34+
After making code changes, ensure all existing and new functionality still works
35+
properly by running the unit tests.
36+
37+
```shell
38+
make test
39+
```
40+
41+
## Format code
42+
43+
Run the linter to make sure all code style rules are adhered to. The code will
44+
automatically be formatted if any code style violations are found.
45+
46+
It's recommended to use the developer image, which has all the required libraries
47+
pre-installed, by running `make run fmt` instead of `make fmt`.
48+
49+
```shell
50+
make run fmt
51+
```
52+
53+
## Build the Docker image
54+
55+
Once the code changes have been tested and linted, build a new `modelmesh-runtime-adapter`
56+
Docker image.
57+
58+
```shell
1859
make build
1960
```
61+
62+
## Push the image to a container registry
63+
64+
Push the newly built `modelmesh-runtime-adapter` image to a container registry.
65+
Replace the value of the `DOCKER_USER` environment variable to your docker user ID
66+
and change the `IMAGE_TAG` to something meaningful.
67+
68+
```bash
69+
export DOCKER_USER="<your-docker-userid>"
70+
export IMAGE_TAG="dev"
71+
72+
docker tag kserve/modelmesh-runtime-adapter:latest \
73+
${DOCKER_USER}/modelmesh-runtime-adapter:${IMAGE_TAG}
74+
75+
docker push ${DOCKER_USER}/modelmesh-runtime-adapter:${IMAGE_TAG}
76+
```
77+
78+
## Update the ModelMesh Serving deployment
79+
80+
In order to test the code changes in an existing [ModelMesh Serving](https://github.com/kserve/modelmesh-serving)
81+
deployment, the newly built container image needs to be added to the
82+
`model-serving-config` ConfigMap.
83+
84+
### Check existing model serving configuration
85+
86+
First, check if your ModelMesh Serving deployment already has an existing
87+
`model-serving-config` ConfigMap:
88+
89+
```Shell
90+
kubectl get configmap
91+
92+
NAME DATA AGE
93+
kube-root-ca.crt 1 12d
94+
model-serving-config 1 12d
95+
model-serving-config-defaults 1 12d
96+
tc-config 2 12d
97+
```
98+
99+
### Create a new model serving config
100+
101+
If you did not already have a `model-serving-config` ConfigMap on your cluster,
102+
you can create one. Replace the `<your-docker-userid>` placeholder with your
103+
Docker username. Make sure the value of the `IMAGE_TAG` variable matches
104+
the one that was pushed to the container registry.
105+
106+
```shell
107+
export DOCKER_USER="<your-docker-userid>"
108+
export IMAGE_NAME="${DOCKER_USER}/modelmesh-runtime-adapter"
109+
export IMAGE_TAG="dev"
110+
111+
kubectl apply -f - <<EOF
112+
---
113+
apiVersion: v1
114+
kind: ConfigMap
115+
metadata:
116+
name: model-serving-config
117+
data:
118+
config.yaml: |
119+
storageHelperImage:
120+
name: ${IMAGE_NAME}
121+
tag: ${IMAGE_TAG}
122+
EOF
123+
```
124+
125+
### Update an existing model serving config
126+
127+
If the ConfigMap list contains `model-serving-config`, save the contents of your
128+
existing configuration in a local temp file:
129+
130+
```Bash
131+
mkdir -p temp
132+
kubectl get configmap model-serving-config -o yaml > temp/model-serving-config.yaml
133+
```
134+
135+
Add the `storageHelperImage` property to the `config.yaml` string property.
136+
137+
```YAML
138+
storageHelperImage:
139+
name: your-docker-userid/modelmesh-runtime-adapter
140+
tag: latest
141+
```
142+
143+
Replace the `your-docker-userid` placeholder with _your_ Docker username and make
144+
sure the `tag` matches the one that was pushed to the container registry earlier.
145+
146+
The complete ConfigMap YAML file _may_ look like this:
147+
148+
```YAML
149+
apiVersion: v1
150+
kind: ConfigMap
151+
metadata:
152+
name: model-serving-config
153+
namespace: modelmesh-serving
154+
data:
155+
config.yaml: |
156+
podsPerRuntime: 1
157+
restProxy:
158+
enabled: true
159+
scaleToZero:
160+
enabled: false
161+
gracePeriodSeconds: 5
162+
storageHelperImage:
163+
name: your-docker-userid/modelmesh-runtime-adapter
164+
tag: dev
165+
```
166+
167+
Apply the ConfigMap to your cluster:
168+
169+
```Bash
170+
kubectl apply -f temp/model-serving-config.yaml
171+
```
172+
173+
If you are comfortable using `vi`, you can forgo creating a temp file and edit
174+
the ConfigMap directly in the terminal:
175+
176+
```Shell
177+
kubectl edit configmap model-serving-config
178+
```
179+
180+
### Verify the container images used by the model serving runtime
181+
182+
The `modelmesh-controller` watches the ConfigMap and responds to updates by
183+
automatically restarting the serving runtime pods using the newly built
184+
runtime adapter image.
185+
186+
You can check which container images are used by running the following command:
187+
188+
```Shell
189+
kubectl get pods -o jsonpath='{range .items[*]}{"\n"}{.metadata.name}{"\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}' | sort | column -ts $'\t' | sed 's/, *$//g'
190+
191+
etcd-78ff7867d5-45svw quay.io/coreos/etcd:v3.5.4
192+
minio-6ddbfc9665-gtf7x kserve/modelmesh-minio-examples:latest
193+
modelmesh-controller-64f5c8d6d6-k6rzc kserve/modelmesh-controller:latest
194+
modelmesh-serving-mlserver-1.x-84884c6849-s8dw6 kserve/rest-proxy:latest, seldonio/mlserver:1.3.2, your-docker-userid/modelmesh-runtime-adapter:dev, kserve/modelmesh:latest
195+
modelmesh-serving-mlserver-1.x-84884c6849-xpdw4 kserve/rest-proxy:latest, seldonio/mlserver:1.3.2, your-docker-userid/modelmesh-runtime-adapter:dev, kserve/modelmesh:latest
196+
```

go.mod

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ require (
5151
go.uber.org/atomic v1.7.0 // indirect
5252
go.uber.org/multierr v1.6.0 // indirect
5353
golang.org/x/crypto v0.14.0 // indirect
54-
golang.org/x/net v0.17.0 // indirect
54+
golang.org/x/net v0.10.0 // indirect
5555
golang.org/x/oauth2 v0.7.0 // indirect
5656
golang.org/x/sys v0.13.0 // indirect
5757
golang.org/x/text v0.13.0 // indirect
@@ -67,3 +67,9 @@ require (
6767
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
6868
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
6969
)
70+
71+
// Update to avoid CVE-2022-27191, CVE-2021-43565, CVE-2020-29652
72+
replace golang.org/x/crypto => golang.org/x/crypto v0.14.0
73+
74+
// Update to avoid CVE-2023-3978, CVE-2023-39325, CVE-2023-44487
75+
replace golang.org/x/net => golang.org/x/net v0.17.0

0 commit comments

Comments
 (0)