Skip to content

Commit

Permalink
Add docker-compose tests
Browse files Browse the repository at this point in the history
  • Loading branch information
s-westphal committed Jan 16, 2024
1 parent 375473f commit 438afdd
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 44 deletions.
75 changes: 31 additions & 44 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,49 +182,6 @@ jobs:
path: gcs_upload_dir/
retention-days: 1

build-push-docker-image:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
runs-on: ubuntu-22.04
needs:
- build-centos
- build-ubuntu
- build-osx
- build-windows
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Download installers from GitHub artifacts
id: download
uses: actions/download-artifact@v4
with:
path: ./_artifacts
pattern: '*installer*'
- name: Login to GitHub Container registry
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
if: ${{ github.event_name == 'push' }}
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
if: ${{ github.event_name == 'push' }}
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

build-push-docker-base-image:
env:
REGISTRY: ghcr.io
Expand Down Expand Up @@ -276,7 +233,7 @@ jobs:
id-token: 'write'
runs-on: ubuntu-22.04
needs:
- build-push-docker
- docker-compose-test
steps:
- uses: actions/checkout@v3
- name: Download installers from GitHub artifacts
Expand Down Expand Up @@ -319,3 +276,33 @@ jobs:
# Omit `path` (e.g. /home/runner/deploy/) in final GCS path.
parent: false

docker-compose-test:
if: ${{ github.event_name == 'push' }}
permissions:
contents: 'read'
id-token: 'write'
runs-on: ubuntu-22.04
needs:
- build-push-docker-base-image
steps:
- uses: actions/checkout@v3
- name: Start docker-compose stack
shell: /bin/bash
run: |
cd ..
docker-compose -f docker-compose.yaml pull --include-deps
docker-compose -f docker-compose.yaml up -d
- name: Test
shell: /bin/bash
run: |
cd ..
docker-compose -f docker-compose.yaml run \
-v $(pwd):/github_workspace \
-w /github_workspace \
--entrypoint appveyor/e2e_tests/run_docker_compose_e2e_test.sh \
- name: Stop docker-compose stack
if: always()
shell: /bin/bash
run: |
cd ..
docker-compose -f docker-compose.yaml down
44 changes: 44 additions & 0 deletions appveyor/e2e_tests/docker_compose_client_collection_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python3

import time

from grr_api_client import api


grrapi = api.InitHttp(api_endpoint="http://localhost:8000",
auth=("admin", "root"))

search_result = grrapi.SearchClients()

result = {}
for client in search_result:
client_id = client.client_id
client_last_seen_at = client.data.last_seen_at
result[client_id] = client_last_seen_at

assert len(result) == 1


flow_args = grrapi.types.CreateFlowArgs("FileFinder")
flow_args.ClearField("paths")
flow_args.paths.append("/client_templates/*")
flow_args.action.action_type = flow_args.action.DOWNLOAD

hunt_runner_args = grrapi.types.CreateHuntRunnerArgs()

hunt = grrapi.CreateHunt(flow_name="FileFinder", flow_args=flow_args,
hunt_runner_args=hunt_runner_args)
hunt = hunt.Start()

# Wait until results are available.
time.sleep(20)

found_files = set([f.payload.stat_entry.pathspec.path for f in hunt.ListResults()])

assert len(found_files) == 4
assert found_files == {
'/client_templates/windows-installers',
'/client_templates/osx-installers',
'/client_templates/centos-installers',
'/client_templates/ubuntu-installers'
}
15 changes: 15 additions & 0 deletions appveyor/e2e_tests/run_docker_compose_e2e_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
#
# Tests the docker-compose setup

set -ex

docker-compose up

docker exec -it grr-admin-ui \
/bin/bash -c \
"grr_console \
-config /configs/grr.server.yaml \
-command_file e2e_tests/docker_compose_client_collection_test.py"


0 comments on commit 438afdd

Please sign in to comment.