Skip to content

Commit

Permalink
Continuous Development with Docker Compose Watch (#1115)
Browse files Browse the repository at this point in the history
* Adds Docker Compose Watch feature
* Updates components to be restarted with source code changes
* Adds comment to explain startup script switch
  • Loading branch information
daschwanden authored Aug 20, 2024
1 parent a6f1b31 commit c2a212f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ FROM ubuntu:22.04

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

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

RUN apt-get update && \
apt-get install -y \
Expand All @@ -63,8 +63,8 @@ RUN apt-get update && \
# building as part of Github Actions.
COPY ./_installers* /client_templates

ENV VIRTUAL_ENV /usr/share/grr-server
ENV GRR_SOURCE /usr/src/grr
ENV VIRTUAL_ENV=/usr/share/grr-server
ENV GRR_SOURCE=/usr/src/grr

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

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

RUN mkdir ${GRR_SOURCE}
RUN mkdir -p ${GRR_SOURCE}
ADD . ${GRR_SOURCE}

WORKDIR ${GRR_SOURCE}
Expand Down
32 changes: 32 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ services:
retries: 10

grr-admin-ui:
build: .
image: ghcr.io/google/grr:latest
container_name: grr-admin-ui
hostname: admin-ui
Expand Down Expand Up @@ -57,8 +58,16 @@ services:
test: "/configs/healthchecks/grr-admin-ui.sh"
timeout: 10s
retries: 10
develop:
watch:
- action: sync+restart
path: ./grr
target: /usr/src/grr/grr
ignore:
- client/

grr-fleetspeak-frontend:
build: .
image: ghcr.io/google/grr:latest
container_name: grr-fleetspeak-frontend
hostname: grr-fleetspeak-frontend
Expand All @@ -78,6 +87,13 @@ services:
- -config
- /configs/server/grr.server.yaml
- --verbose
develop:
watch:
- action: sync+restart
path: ./grr
target: /usr/src/grr/grr
ignore:
- client/

fleetspeak-admin:
image: ghcr.io/google/fleetspeak:latest
Expand Down Expand Up @@ -129,6 +145,7 @@ services:
]

grr-worker:
build: .
image: ghcr.io/google/grr:latest
container_name: grr-worker
volumes:
Expand All @@ -146,8 +163,16 @@ services:
- -config
- /configs/server/grr.server.yaml
- --verbose
develop:
watch:
- action: sync+restart
path: ./grr
target: /usr/src/grr/grr
ignore:
- client/

grr-client:
build: .
image: ubuntu:22.04
container_name: grr-client
depends_on:
Expand Down Expand Up @@ -177,6 +202,13 @@ services:
test: "/configs/healthchecks/grr-client.sh"
timeout: 10s
retries: 10
develop:
watch:
- action: sync+restart
path: ./grr
target: /usr/src/grr/grr
ignore:
- server/

volumes:
db_data:
Expand Down
12 changes: 12 additions & 0 deletions docker_config_files/client/grr_fleetspeak_client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
#
# This script is run when Fleetspeak runs the GRR client.
# It first checks whether we run Docker Compose Watch (i.e. in dev mode).
# If so we run the grr_fleetspeak_client python script so Docker Compose can
# swap in the source code updates on a continuous basis.
# If not we run grrd as we would do so in production.
if [ -f /usr/share/grr-server/bin/grr_fleetspeak_client ]; then
/usr/share/grr-server/bin/python /usr/share/grr-server/bin/grr_fleetspeak_client "$@"
else
/usr/sbin/grrd "$@"
fi
2 changes: 1 addition & 1 deletion docker_config_files/client/textservices/grr_client.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: "GRR"
factory: "Daemon"
config: {
[type.googleapis.com/fleetspeak.daemonservice.Config]: {
argv: "grrd"
argv: "/configs/client/grr_fleetspeak_client.sh"
argv: "--config"
argv: "/configs/client/grr.client.yaml"
}
Expand Down
5 changes: 3 additions & 2 deletions docker_config_files/healthchecks/grr-client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

set -ex

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

0 comments on commit c2a212f

Please sign in to comment.