Skip to content

Commit bb95f7a

Browse files
committed
Use existing container if available
1 parent f30442a commit bb95f7a

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed

ci/dev-image/Dockerfile

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ RUN apt-get update && apt-get install -y \
44
curl \
55
iproute2 \
66
vim \
7-
libgpgme-dev \
87
iptables \
98
net-tools \
109
libsecret-1-dev \

ci/dev-image/exec.sh

+26-26
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,14 @@ git submodule update --init
88

99
container_name=code-server-dev
1010

11-
# Docker build is very verbose even when everything is cached.
12-
echo "--- Building $container_name"
13-
cd ../../ && docker build -t $container_name -f ./ci/dev-image/Dockerfile . > /dev/null
14-
15-
set +e
16-
container_id=$(docker container inspect --format="{{.Id}}" $container_name 2>/dev/null)
17-
18-
if [ $? -eq "0" ]; then
19-
echo "--- Killing $container_name"
20-
docker rm -f $container_name 2>/dev/null
21-
fi
22-
set -e
23-
24-
echo "--- Spawning $container_name"
25-
container_id=$(docker run \
11+
enter() {
12+
echo "--- Entering $container_name"
13+
docker exec -it $container_id /bin/bash
14+
}
15+
16+
run() {
17+
echo "--- Spawning $container_name"
18+
container_id=$(docker run \
2619
-it \
2720
--privileged \
2821
--name $container_name \
@@ -32,19 +25,26 @@ container_id=$(docker run \
3225
$([[ -t 0 ]] && echo -it || true) \
3326
-d \
3427
$container_name)
28+
}
3529

36-
set +e
30+
build() {
31+
echo "--- Building $container_name"
32+
cd ../../ && docker build -t $container_name -f ./ci/dev-image/Dockerfile . > /dev/null
33+
}
3734

38-
echo "--- Executing: $@"
35+
set +e
36+
container_id=$(docker container inspect --format="{{.Id}}" $container_name 2> /dev/null)
3937

40-
CMD="$@"
38+
if [ $? -eq "0" ]; then
39+
set -e
40+
echo "-- Starting container"
41+
docker start $container_id > /dev/null
4142

42-
docker exec \
43-
$([[ -t 0 ]] && echo -it || true) \
44-
$container_id \
45-
bash -c "$CMD"
43+
enter
44+
exit 0
45+
fi
4646

47-
docker exec \
48-
$([[ -t 0 ]] && echo -it || true) \
49-
$container_id \
50-
bash
47+
set -e
48+
build
49+
run
50+
enter

doc/CONTRIBUTING.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ yarn watch # Visit http://localhost:8080 once completed.
1313
To develop inside of an isolated docker container:
1414

1515
```shell
16-
./ci/dev-image/exec.sh bash -c 'yarn && yarn vscode && yarn watch' # Visit http://localhost:8080 once completed.
16+
./ci/dev-image/exec.sh
17+
18+
root@12345:/code-server# yarn
19+
root@12345:/code-server# yarn vscode
20+
root@12345:/code-server# yarn watch
1721
```
1822

1923
Any changes made to the source will be live reloaded.

0 commit comments

Comments
 (0)