Skip to content

Commit c2a212f

Browse files
authored
Continuous Development with Docker Compose Watch (#1115)
* Adds Docker Compose Watch feature * Updates components to be restarted with source code changes * Adds comment to explain startup script switch
1 parent a6f1b31 commit c2a212f

File tree

5 files changed

+53
-8
lines changed

5 files changed

+53
-8
lines changed

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ FROM ubuntu:22.04
4040

4141
LABEL maintainer="grr-dev@googlegroups.com"
4242

43-
ENV DEBIAN_FRONTEND noninteractive
43+
ENV DEBIAN_FRONTEND=noninteractive
4444
# Buffering output (sometimes indefinitely if a thread is stuck in
4545
# a loop) makes for a non-optimal user experience when containers
4646
# are run in the foreground, so we disable that.
47-
ENV PYTHONUNBUFFERED 0
47+
ENV PYTHONUNBUFFERED=0
4848

4949
RUN apt-get update && \
5050
apt-get install -y \
@@ -63,8 +63,8 @@ RUN apt-get update && \
6363
# building as part of Github Actions.
6464
COPY ./_installers* /client_templates
6565

66-
ENV VIRTUAL_ENV /usr/share/grr-server
67-
ENV GRR_SOURCE /usr/src/grr
66+
ENV VIRTUAL_ENV=/usr/share/grr-server
67+
ENV GRR_SOURCE=/usr/src/grr
6868

6969
RUN python -m venv --system-site-packages $VIRTUAL_ENV
7070
ENV PATH=${VIRTUAL_ENV}/bin:${PATH}
@@ -73,7 +73,7 @@ RUN ${VIRTUAL_ENV}/bin/python -m pip install wheel nodeenv grpcio-tools==1.60
7373

7474
RUN ${VIRTUAL_ENV}/bin/nodeenv -p --prebuilt --node=16.13.0
7575

76-
RUN mkdir ${GRR_SOURCE}
76+
RUN mkdir -p ${GRR_SOURCE}
7777
ADD . ${GRR_SOURCE}
7878

7979
WORKDIR ${GRR_SOURCE}

compose.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ services:
2727
retries: 10
2828

2929
grr-admin-ui:
30+
build: .
3031
image: ghcr.io/google/grr:latest
3132
container_name: grr-admin-ui
3233
hostname: admin-ui
@@ -57,8 +58,16 @@ services:
5758
test: "/configs/healthchecks/grr-admin-ui.sh"
5859
timeout: 10s
5960
retries: 10
61+
develop:
62+
watch:
63+
- action: sync+restart
64+
path: ./grr
65+
target: /usr/src/grr/grr
66+
ignore:
67+
- client/
6068

6169
grr-fleetspeak-frontend:
70+
build: .
6271
image: ghcr.io/google/grr:latest
6372
container_name: grr-fleetspeak-frontend
6473
hostname: grr-fleetspeak-frontend
@@ -78,6 +87,13 @@ services:
7887
- -config
7988
- /configs/server/grr.server.yaml
8089
- --verbose
90+
develop:
91+
watch:
92+
- action: sync+restart
93+
path: ./grr
94+
target: /usr/src/grr/grr
95+
ignore:
96+
- client/
8197

8298
fleetspeak-admin:
8399
image: ghcr.io/google/fleetspeak:latest
@@ -129,6 +145,7 @@ services:
129145
]
130146

131147
grr-worker:
148+
build: .
132149
image: ghcr.io/google/grr:latest
133150
container_name: grr-worker
134151
volumes:
@@ -146,8 +163,16 @@ services:
146163
- -config
147164
- /configs/server/grr.server.yaml
148165
- --verbose
166+
develop:
167+
watch:
168+
- action: sync+restart
169+
path: ./grr
170+
target: /usr/src/grr/grr
171+
ignore:
172+
- client/
149173

150174
grr-client:
175+
build: .
151176
image: ubuntu:22.04
152177
container_name: grr-client
153178
depends_on:
@@ -177,6 +202,13 @@ services:
177202
test: "/configs/healthchecks/grr-client.sh"
178203
timeout: 10s
179204
retries: 10
205+
develop:
206+
watch:
207+
- action: sync+restart
208+
path: ./grr
209+
target: /usr/src/grr/grr
210+
ignore:
211+
- server/
180212

181213
volumes:
182214
db_data:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
#
3+
# This script is run when Fleetspeak runs the GRR client.
4+
# It first checks whether we run Docker Compose Watch (i.e. in dev mode).
5+
# If so we run the grr_fleetspeak_client python script so Docker Compose can
6+
# swap in the source code updates on a continuous basis.
7+
# If not we run grrd as we would do so in production.
8+
if [ -f /usr/share/grr-server/bin/grr_fleetspeak_client ]; then
9+
/usr/share/grr-server/bin/python /usr/share/grr-server/bin/grr_fleetspeak_client "$@"
10+
else
11+
/usr/sbin/grrd "$@"
12+
fi

docker_config_files/client/textservices/grr_client.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: "GRR"
22
factory: "Daemon"
33
config: {
44
[type.googleapis.com/fleetspeak.daemonservice.Config]: {
5-
argv: "grrd"
5+
argv: "/configs/client/grr_fleetspeak_client.sh"
66
argv: "--config"
77
argv: "/configs/client/grr.client.yaml"
88
}

docker_config_files/healthchecks/grr-client.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
set -ex
88

9-
if [[ "$(ps aux | grep grrd | grep -v grep | wc -l)" == "0" ]]
9+
if [[ "$(ps aux | grep grrd | grep -v grep | wc -l)" == "0" ]] &&
10+
[[ "$(ps aux | grep '/usr/share/grr-server/bin/grr_fleetspeak_client' | grep -v grep | wc -l)" == "0" ]]
1011
then
1112
echo "Healthckeck: GRR client process not running"
1213
exit 1
13-
fi
14+
fi

0 commit comments

Comments
 (0)