Skip to content

Commit cd4e80e

Browse files
authored
Docker build script (#127)
1 parent 0213b0e commit cd4e80e

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

docker-build.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
# Variables
4+
CONTAINER_NAME="spectator-build"
5+
IMAGE_NAME="spectator-cpp-image"
6+
CONTAINER_FILE_PATH="/home/ubuntu/spectator-cpp/cmake-build"
7+
HOST_FILE_PATH="$PWD"
8+
9+
if [[ -z "$BUILD_TYPE" ]]; then
10+
BUILD_TYPE="Debug"
11+
fi
12+
13+
# Build image if it does not exist
14+
if [[ -z "$(docker images -q $IMAGE_NAME 2>/dev/null)" ]]; then
15+
echo "Docker image $IMAGE_NAME not found. Building..."
16+
docker build -t $IMAGE_NAME -f Dockerfiles/Ubuntu.Dockerfile .
17+
fi
18+
19+
## Remove any previous container
20+
docker rm $CONTAINER_NAME 2>/dev/null || true
21+
22+
## Run the container and execute build.sh inside the virtual environment
23+
docker run --name $CONTAINER_NAME \
24+
--entrypoint bash $IMAGE_NAME -lc \
25+
"source /home/ubuntu/spectator-cpp/venv/bin/activate && set -x && BUILD_TYPE=$BUILD_TYPE bash /home/ubuntu/spectator-cpp/build.sh"
26+
27+
## Copy the build output from the container to the host
28+
docker cp $CONTAINER_NAME:$CONTAINER_FILE_PATH $HOST_FILE_PATH
29+
30+
## Remove the container after copying
31+
docker rm $CONTAINER_NAME

0 commit comments

Comments
 (0)