Skip to content

Commit a24523c

Browse files
authored
Fix github build workflow and startup scripts. (#123)
* Fix github flow * Add image pulling from docker/start.sh * Fix start.sh * Fix start.sh * fix images fetching. * Fix image checking * Setting LeetHome automatically. * Create empty .env by default. * Fix permission for docker/stop.sh * Move shared config check to docker_util.sh * Add default leet_home to start_docker.sh
1 parent a10a385 commit a24523c

File tree

6 files changed

+112
-231
lines changed

6 files changed

+112
-231
lines changed

.github/workflows/build_llmeds_app.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ jobs:
7070
platforms: linux/amd64,linux/arm64
7171

7272
- name: Build successful
73-
run: echo "Docker image name is ${{ env.DOCKER_USERNAME }}/${{ env.APP_NAME }}:${{ steps.meta.outputs.tags }}
73+
run: echo "Docker image name is ${{ env.DOCKER_USERNAME }}/${{ env.APP_NAME }}:${{ steps.meta.outputs.tags }}"

docker/docker_util.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
# check if the .env file exists in the docker directory
3+
env_file="$DIR/.env"
4+
template_file="$DIR/env.template"
5+
if [ ! -f "$env_file" ]; then
6+
# copy the .env.template file to .env if it doesn't exist
7+
cp "$template_file" "$env_file"
8+
echo ".env file not found in $DIR for docker-compose.yml. Copied from $template_file."
9+
fi
10+
11+
# load the .env file into the environment by exporting the variables
12+
while IFS='=' read -r name value; do
13+
if [[ ! $name =~ ^\# ]] && [[ -n $name ]]; then
14+
# we only export the variables that are not set in the environment
15+
current_env_value="${!name:-}"
16+
if [ -z "${current_env_value}" ]; then
17+
export "$name=$value";
18+
else
19+
# print a warning message if the two values are different
20+
if [ "${current_env_value}" != "${value}" ]; then
21+
echo "[start.sh warning] $name is set to $current_env_value in the current environment, but the $env_file file has a different value: $value"
22+
fi;
23+
fi;
24+
fi;
25+
done < "${env_file}"
26+
27+
if [ -z "${LEET_HOME:-}" ]; then
28+
case "$(uname -s)" in
29+
Darwin|Linux)
30+
LEET_HOME=~/leettools
31+
;;
32+
CYGWIN*|MINGW*|MSYS*)
33+
LEET_HOME="$USERPROFILE/leettools"
34+
;;
35+
*)
36+
echo "Unsupported operating system, using the value from .env file"
37+
;;
38+
esac
39+
echo "LEET_HOME is not set, using the default value: $LEET_HOME"
40+
export LEET_HOME="$LEET_HOME"
41+
fi
42+
43+
# set DOCUMENETS_HOME to the Documents directory on different OS
44+
# windows: C:\Users\<username>\Documents
45+
# mac: ~/Documents
46+
# linux: ~/Documents
47+
48+
# if no DOCUMENETS_HOME is set in the .env file, set it to the Documents directory on different OS
49+
if [ -z "${DOCUMENETS_HOME:-}" ]; then
50+
case "$(uname -s)" in
51+
Darwin|Linux)
52+
DOCUMENETS_HOME=~/Documents
53+
;;
54+
CYGWIN*|MINGW*|MSYS*)
55+
DOCUMENETS_HOME="$USERPROFILE/Documents"
56+
;;
57+
*)
58+
echo "Unsupported operating system, using the value from .env file"
59+
;;
60+
esac
61+
echo "DOCUMENETS_HOME is not set, using the default value: $DOCUMENETS_HOME"
62+
export DOCUMENETS_HOME="$DOCUMENETS_HOME"
63+
fi

docker/start.sh

Lines changed: 31 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,43 @@
33
set -e -u
44

55
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6+
BASE_DIR="$(cd "$DIR"/.. && pwd)"
67

7-
# check if the .env file exists in the docker directory
8-
env_file="$DIR/.env"
9-
if [ ! -f "$env_file" ]; then
10-
# copy the .env.template file to .env if it doesn't exist
11-
cp "$env_file.template" "$env_file"
12-
echo ".env file not found in $DIR for docker-compose.yml. Copied from $DIR/.env.template."
13-
fi
14-
15-
# load the .env file into the environment by exporting the variables
16-
while IFS='=' read -r name value; do
17-
if [[ ! $name =~ ^\# ]] && [[ -n $name ]]; then
18-
# we only export the variables that are not set in the environment
19-
current_env_value="${!name:-}"
20-
if [ -z "${current_env_value}" ]; then
21-
export "$name=$value";
22-
else
23-
# print a warning message if the two values are different
24-
if [ "${current_env_value}" != "${value}" ]; then
25-
echo "[start.sh warning] $name is set to $current_env_value in the current environment, but the $env_file file has a different value: $value"
26-
fi;
27-
fi;
28-
fi;
29-
done < "${env_file}"
30-
31-
# set DOCUMENETS_HOME to the Documents directory on different OS
32-
# windows: C:\Users\<username>\Documents
33-
# mac: ~/Documents
34-
# linux: ~/Documents
35-
36-
# if no DOCUMENETS_HOME is set in the .env file, set it to the Documents directory on different OS
37-
if [ -z "${DOCUMENETS_HOME:-}" ]; then
38-
case "$(uname -s)" in
39-
Darwin|Linux)
40-
export DOCUMENETS_HOME=~/Documents
41-
;;
42-
CYGWIN*|MINGW*|MSYS*)
43-
export DOCUMENETS_HOME="$USERPROFILE/Documents"
44-
;;
45-
*)
46-
echo "Unsupported operating system, using the value from .env file"
47-
;;
48-
esac
8+
# check if the .env file exists in the base directory
9+
if [ ! -f "$BASE_DIR/.env" ]; then
10+
echo ".env file not found in $BASE_DIR. Using all default values."
11+
echo "" >> "$BASE_DIR/.env"
4912
fi
5013

5114
pushd . > /dev/null
5215

5316
cd "$DIR"
54-
55-
docker compose --profile full down
56-
docker compose --profile full up -d
17+
# shellcheck disable=SC1091
18+
source docker_util.sh
19+
20+
# check if the docker image exists
21+
# read the images from the docker-compose.yml file
22+
# replace ${LEETTOOLS_VERSION} and ${LEETTOOLS_WEB_VERSION} with the actual env vars
23+
images=$(grep 'image:' docker-compose.yml | sed 's/image: //')
24+
25+
# check if the docker image exists
26+
for image in $images; do
27+
# replace ${LEETTOOLS_VERSION} and ${LEETTOOLS_DEV_VERSION} with the actual env vars
28+
# shellcheck disable=SC2001
29+
image=$(echo "$image" | sed "s/\${LEETTOOLS_VERSION}/${LEETTOOLS_VERSION}/")
30+
# shellcheck disable=SC2001
31+
image=$(echo "$image" | sed "s/\${LEETTOOLS_WEB_VERSION}/${LEETTOOLS_WEB_VERSION}/")
32+
# Split image name and tag
33+
image_name=$(echo "$image" | cut -d: -f1)
34+
image_tag=$(echo "$image" | cut -d: -f2)
35+
if ! docker images "$image_name" | grep -q "$image_tag"; then
36+
echo "Docker image $image does not exist. Pulling the image..."
37+
docker pull "$image"
38+
fi
39+
done
40+
41+
docker compose down || true
42+
docker compose up -d
5743

5844
popd > /dev/null
5945

docker/start_docker.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,19 @@ fi
116116

117117
# check if the LEET_HOME, EDS_DATA_DIR, and EDS_LOG_DIR environment variables are set
118118
if [ -z "${LEET_HOME:-}" ]; then
119-
echo "LEET_HOME is not set"
120-
exit 1
119+
case "$(uname -s)" in
120+
Darwin|Linux)
121+
LEET_HOME=~/leettools
122+
;;
123+
CYGWIN*|MINGW*|MSYS*)
124+
LEET_HOME="$USERPROFILE/leettools"
125+
;;
126+
*)
127+
echo "Unsupported operating system, using the value from .env file"
128+
;;
129+
esac
130+
echo "LEET_HOME is not set, using the default value: $LEET_HOME"
131+
export LEET_HOME="$LEET_HOME"
121132
fi
122133

123134
if [ -z "${EDS_DATA_DIR:-}" ]; then
@@ -135,7 +146,6 @@ fi
135146
# run the docker container as a service with port 8000:8000
136147
# mount the data directory at $LEET_HOME, $EDS_DATA_DIR, $EDS_LOG_DIR
137148
# run the docker container with the .env.docker file
138-
139149
leet_home_in_docker="/leettools"
140150

141151
# print the docker run command

docker/stop.sh

100644100755
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ set -e -u
44

55
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
66

7-
pushd . > /dev/null
7+
pushd . > /dev/null
8+
89
cd "$DIR"
10+
# shellcheck disable=SC1091
11+
source docker_util.sh
912

1013
docker compose --profile full down
1114

0 commit comments

Comments
 (0)