Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous Development with Docker Compose Watch #1115

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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="[email protected]"

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
Loading