forked from redhat-ai-dev/ai-lab-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import-ai-lab-samples
executable file
·88 lines (67 loc) · 3.14 KB
/
import-ai-lab-samples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
ROOT_DIR=$(realpath $SCRIPTDIR/..)
SKELETON_DIR=$ROOT_DIR/skeleton
TEMPLATE_DIR=$ROOT_DIR/templates
REPO="${SAMPLE_REPO:-https://github.com/redhat-ai-dev/ai-lab-samples}"
BRANCH="${SAMPLE_BRANCH:-main}"
DIRNAME=$(basename $REPO)
mkdir -p $SCRIPTDIR/samples
SAMPLE_DIR=$SCRIPTDIR/samples/$DIRNAME
if [ -d $SAMPLE_DIR ]; then
(cd $SAMPLE_DIR; git pull 2>&1 > /dev/null)
else
(cd $SCRIPTDIR/samples; git clone $REPO 2>&1 > /dev/null)
fi
(cd $SAMPLE_DIR; git checkout $BRANCH; git pull)
cd $SAMPLE_DIR
for f in */; do
if [ -d "$f" ]; then
# $f is a directory
SAMPLENAME=$(basename $f)
DEST=$ROOT_DIR/templates/$SAMPLENAME
rm -rf $DEST
mkdir -p $DEST
cp -r $SAMPLE_DIR/$SAMPLENAME $DEST/content
# add template card docs
cp -r $ROOT_DIR/skeleton/template-card-techdocs/base/docs $DEST/docs
cp -r $ROOT_DIR/skeleton/template-card-techdocs/base/mkdocs.yml $DEST/mkdocs.yml
cp $ROOT_DIR/skeleton/template.yaml $DEST/template.yaml
cp -r $ROOT_DIR/skeleton/techdoc/docs $DEST/content/docs
cp -r $ROOT_DIR/skeleton/techdoc/mkdocs.yml $DEST/content/mkdocs.yml
# get readme to source component doc
cp -r $SAMPLE_DIR/README.md $DEST/content/docs/source-component.md
cp -r $ROOT_DIR/skeleton/source-repo/.tekton/README.md $DEST/content/docs/pipelines.md
# get default env variables
source $SCRIPTDIR/envs/base
# get sample env variables
source $SCRIPTDIR/envs/$SAMPLENAME
if [ -f $f/Containerfile ]; then
sed -i "s!sed.edit.DOCKERFILE!Containerfile!g" $DEST/template.yaml
sed -i "s!sed.edit.BUILDCONTEXT!.!g" $DEST/template.yaml
fi
sed -i "s!sed.edit.APP_NAME!$APP_NAME!g" $DEST/template.yaml
sed -i "s!sed.edit.APP_DISPLAY_NAME!$APP_DISPLAY_NAME!g" $DEST/template.yaml
sed -i "s!sed.edit.DESCRIPTION!$APP_DESC!g" $DEST/template.yaml
sed -i "s!sed.edit.APPTAGS!$APP_TAGS!g" $DEST/template.yaml
sed -i "s!sed.edit.CATALOG_DESCRIPTION!Secure Supply Chain Example for $APP_DISPLAY_NAME!g" $DEST/template.yaml
sed -i "s!sed.edit.APP_DISPLAY_NAME!$APP_DISPLAY_NAME!g" $DEST/docs/index.md
sed -i "s!sed.edit.TEMPLATE_SOURCE_URL!$TEMPLATE_SOURCE_URL!g" $DEST/docs/index.md
if [ $SUPPORT_LLM == false ]; then
sed -i '/# SED_LLM_SERVER_START/,/# SED_LLM_SERVER_END/d' $DEST/template.yaml
fi
if [ $SUPPORT_ASR == false ]; then
sed -i '/# SED_ASR_MODEL_SERVER_START/,/# SED_ASR_MODEL_SERVER_END/d' $DEST/template.yaml
fi
if [ $SUPPORT_DETR == false ]; then
sed -i '/# SED_DETR_MODEL_SERVER_START/,/# SED_DETR_MODEL_SERVER_END/d' $DEST/template.yaml
fi
if [ $SUPPORT_DB == false ]; then
sed -i '/# SED_DB_START/,/# SED_DB_END/d' $DEST/template.yaml
fi
source $ROOT_DIR/properties
cat $DEST/template.yaml | envsubst > $DEST/new-template.yaml
mv $DEST/new-template.yaml $DEST/template.yaml
fi
done
rm -rf $SCRIPTDIR/samples