Skip to content

Commit 2b151f5

Browse files
committed
Only one docker run script to run them all
1 parent 05c8305 commit 2b151f5

File tree

2 files changed

+51
-25
lines changed

2 files changed

+51
-25
lines changed

Makefile

+11-11
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,28 @@ build-image:
2929
@bash -x src/scripts/docker_image_build.sh
3030

3131
build-all: build-image
32-
@bash -x src/scripts/build.sh scripts/bazel_build.sh
32+
@bash -x src/scripts/run.sh scripts/bazel_build.sh
3333

3434
run-query-agent:
35-
@bash -x src/scripts/run.sh query_broker 31700
35+
@bash -x src/scripts/run.sh bin/query_broker 31700
3636

3737
run-attention-broker:
38-
@bash -x src/scripts/run.sh attention_broker_service 37007
38+
@bash -x src/scripts/run.sh bin/attention_broker_service 37007
3939

4040
run-link-creation-agent:
41-
@bash -x src/scripts/run.sh link_creation_server $(OPTIONS)
41+
@bash -x src/scripts/run.sh bin/link_creation_server $(OPTIONS)
4242

4343
run-link-creation-client:
44-
@bash -x src/scripts/run.sh link_creation_agent_client $(OPTIONS)
44+
@bash -x src/scripts/run.sh bin/link_creation_agent_client $(OPTIONS)
4545

4646
run-inference-agent:
47-
@bash -x src/scripts/run.sh inference_agent_server $(OPTIONS)
47+
@bash -x src/scripts/run.sh bin/inference_agent_server $(OPTIONS)
4848

4949
run-inference-agent-client:
50-
@bash -x src/scripts/run.sh inference_agent_client $(OPTIONS)
50+
@bash -x src/scripts/run.sh bin/inference_agent_client $(OPTIONS)
5151

5252
run-evolution:
53-
@bash ./src/scripts/bazel.sh ./scripts/bazel_cmd.sh run //evolution:main -- $(OPTIONS)
53+
@bash src/scripts/run.sh scripts/bazel_cmd.sh run //evolution:main -- $(OPTIONS)
5454

5555
run-das-agent:
5656
@bash ./src/scripts/bazel.sh run //das_agent:main -- $(OPTIONS)
@@ -64,14 +64,14 @@ setup-nunet-dms:
6464
reset-nunet-dms:
6565
@bash -x src/scripts/reset-nunet-dms.sh
6666

67-
bazel: build-image
68-
@bash ./src/scripts/bazel.sh $(filter-out $@, $(MAKECMDGOALS))
67+
bazel:
68+
@bash -x src/scripts/run.sh scripts/bazel_cmd.sh $(filter-out $@, $(MAKECMDGOALS))
6969

7070
test-all-no-cache:
7171
@$(MAKE) bazel 'test --cache_test_results=no //tests/...'
7272

7373
test-all: build-image
74-
@$(MAKE) bazel test //tests/...
74+
@$(MAKE) bazel 'test //tests/...'
7575

7676
lint-all:
7777
@$(MAKE) bazel lint \

src/scripts/run.sh

+40-14
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,50 @@
11
#!/bin/bash
22

3-
CONTAINER_NAME="$1"
4-
shift
3+
set -exou pipefail
4+
5+
IMAGE_NAME="das-builder"
56

67
ENV_VARS=$(test -f .env && echo "--env-file=.env" || echo "")
78

9+
# Ensure an entrypoint is provided
10+
if [ -z "$1" ]; then
11+
echo "Usage: $0 <entrypoint>"
12+
exit 1
13+
fi
14+
15+
ENTRYPOINT="$1"
16+
shift
17+
18+
# local paths
19+
LOCAL_WORKDIR=$(pwd)
20+
LOCAL_BIN_DIR=$LOCAL_WORKDIR/src/bin
21+
LOCAL_CACHE="$HOME/.cache/das"
22+
23+
mkdir -p "$LOCAL_BIN_DIR" "$LOCAL_CACHE"
24+
25+
# container paths
26+
CONTAINER_WORKDIR=/opt/das
27+
CONTAINER_WORKSPACE_DIR=/opt/das/src
28+
CONTAINER_BIN_DIR=$CONTAINER_WORKSPACE_DIR/bin
29+
CONTAINER_CACHE=/home/"${USER}"/.cache
30+
31+
CONTAINER_NAME=$(echo "$ENTRYPOINT" | sed 's/[\/.]/_/g' | sed 's/_sh$//')
32+
833
if docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
934
echo "Removing existing container: ${CONTAINER_NAME}"
1035
docker rm -f "${CONTAINER_NAME}"
1136
fi
1237

13-
mkdir -p bin
14-
docker run \
15-
--name="$CONTAINER_NAME" \
16-
--network host \
17-
--volume .:/opt/das \
18-
--workdir /opt/das \
19-
$ENV_VARS \
20-
das-builder \
21-
"src/bin/$CONTAINER_NAME" "$@"
22-
23-
sleep 1
24-
docker rm -f "$CONTAINER_NAME"
38+
docker run --rm \
39+
--user="$(id -u)":"$(id -g)" \
40+
--name=$CONTAINER_NAME \
41+
-e BIN_DIR=$CONTAINER_BIN_DIR \
42+
$ENV_VARS \
43+
--network=host \
44+
--volume /etc/passwd:/etc/passwd:ro \
45+
--volume "$LOCAL_CACHE":"$CONTAINER_CACHE" \
46+
--volume "$LOCAL_WORKDIR":"$CONTAINER_WORKDIR" \
47+
--workdir "$CONTAINER_WORKSPACE_DIR" \
48+
--entrypoint "${ENTRYPOINT}" \
49+
"${IMAGE_NAME}" \
50+
"${@}"

0 commit comments

Comments
 (0)