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

Add offline docker example for air gapped networks #160

Merged
merged 16 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from 9 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
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
ENTRYPOINT ["/tini", "--", "/usr/local/bin/docker-entrypoint"]

ENV SUITES_DIR=/usr/share/heartbeat/suites

# or docker run your-image /your/program ...
RUN echo /usr/share/heartbeat/.node \\
/usr/share/heartbeat/.npm \\
/usr/share/heartbeat/.cache \\
/usr/share/heartbeat/.config \\
/opt/elastic-synthetics | xargs -IDIR sh -c "mkdir DIR && chown -R heartbeat DIR"
$SUITES_DIR \\
/opt/elastic-synthetics | xargs -IDIR sh -c "mkdir DIR && chown -R heartbeat:heartbeat DIR"
ENV NODE_PATH=/usr/share/heartbeat/.node
USER heartbeat
RUN cd /usr/share/heartbeat/.node \\
Expand Down
4 changes: 3 additions & 1 deletion examples/docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ else
IMAGE=$VERSION
fi

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

echo "Using image '$IMAGE' with extra args: $HEARTBEAT_ARGS"
docker run \
--rm \
--name=heartbeat \
--user=heartbeat \
--net=host \
--security-opt seccomp=seccomp_profile.json \
--security-opt seccomp=$SCRIPT_DIR/seccomp_profile.json \
--volume="$(pwd)/heartbeat.docker.yml:/usr/share/heartbeat/heartbeat.yml:ro" \
--volume="$(pwd)/../../:/opt/elastic-synthetics:rw" \
$IMAGE \
Expand Down
30 changes: 30 additions & 0 deletions examples/todos/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This Dockerfile illustrates the usage of synthetics in an air gapped environment, where
# public internet access is not available. In this situation you'll want to create
# a custom image using our official docker image as a base.

# Use our synthetics image as a base.
ARG STACK_VERSION=latest
FROM docker.elastic.co/experimental/synthetics:${STACK_VERSION}-synthetics
# Use the line below if you're using a custom base image, usually only for
# developers
#FROM heartbeat-synthetics-local

# This flag variable will prevent heartbeat from running `npm i` or
# similar commands that depend on an internet connection.
# We'll have to do that work now, when we bake the image.
ENV ELASTIC_SYNTHETICS_OFFLINE=true

# Copy our heartbeat config directly to the image.
# This could be done as a shared mount instead, but if we're
# baking an image anyway, this may be something that may be easier
# to do in this manner.
COPY heartbeat.docker.yml /usr/share/heartbeat/heartbeat.yml

RUN mkdir -p $SUITES_DIR/todos
# Copy your custom synthetics tests into a folder on the image
COPY ./* $SUITES_DIR/todos/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
COPY ./* $SUITES_DIR/todos/
COPY . $SUITES_DIR/todos/


# Install NPM deps locally on this image
# Please note that it's important to run both `npm install` AND `npm install playwright`
# for more see this issue: https://github.com/microsoft/playwright/issues/3712
RUN cd $SUITES_DIR/todos && npm install && npm install playwright-chromium
andrewvc marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions examples/todos/build-offline-dockerfile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
# This demonstrates building and tagging a custom offline docker heartbeat image with synthetics
# with all dependencies pre-bundled.

# You'll want to run this in an environment with internet access so that NPM deps cap be installed,
andrewvc marked this conversation as resolved.
Show resolved Hide resolved
# then, take the resultant image and transfer that to your air gapped network.
docker build --build-arg STACK_VERSION=7.10.0 -t my-custom-heartbeat .
12 changes: 12 additions & 0 deletions examples/todos/heartbeat.docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
seccomp.enabled: false
heartbeat.config.monitors:
path: "${path.config}/monitors.d/*.yml"
reload.enabled: false
reload.period: 5s

heartbeat.synthetic_suites:
- name: Todos
# SUITES_DIR is an environment var provided by the docker container
path: "${SUITES_DIR}/todos"
schedule: "@every 1m"
1 change: 1 addition & 0 deletions examples/todos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"license": "MIT",
"dependencies": {
"@elastic/synthetics": "*",
"playwright-chromium": "^1.6.2",
andrewvc marked this conversation as resolved.
Show resolved Hide resolved
"playwright-core": "^1.5.2"
}
}
2 changes: 2 additions & 0 deletions examples/todos/run-offline-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
../docker/run.sh my-custom-heartbeat
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: It seems to me that this could be move to docs or to the readme

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ I'll remove this