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

Merge docker compose files #146

Merged
merged 3 commits into from
Sep 30, 2021
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
6 changes: 1 addition & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,14 @@ jobs:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
# --- Tidy up ---
- name: "Remove existing containers"
run: "docker ps -aq | xargs docker stop | xargs docker rm"
continue-on-error: true
# --- Code update ---
- name: "Check out code"
uses: actions/checkout@v2
# --- Build and test ---
- name: "Build distributed tests"
run: ./dist-test/build.sh
- name: "Run the distributed tests"
run: ./dist-test/run.sh ci
run: ./dist-test/run.sh

examples:
if: github.event.pull_request.draft == false
Expand Down
10 changes: 0 additions & 10 deletions bin/cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ PROJ_ROOT=${THIS_DIR}/..

pushd ${PROJ_ROOT} > /dev/null

# See if someone has specified a CLI image through an environment variable
if [[ -z "${FAABRIC_CLI_IMAGE}" ]]; then
# Prepare the default version
VERSION=$(cat VERSION)
DEFAULT_IMAGE=faasm/faabric:${VERSION}

# Take the script argument if provided, else use the default
export FAABRIC_CLI_IMAGE=${1:-${DEFAULT_IMAGE}}
fi

echo "Running Faabric CLI (${FAABRIC_CLI_IMAGE})"

INNER_SHELL=${SHELL:-"/bin/bash"}
Expand Down
11 changes: 3 additions & 8 deletions dist-test/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
set -e

export PROJ_ROOT=$(dirname $(dirname $(readlink -f $0)))
pushd ${PROJ_ROOT}/dist-test >> /dev/null

# Set up image name
if [[ -z "${FAABRIC_CLI_IMAGE}" ]]; then
VERSION=$(cat ../VERSION)
export FAABRIC_CLI_IMAGE=faasm/faabric:${VERSION}
fi
pushd ${PROJ_ROOT} >> /dev/null

# Run the build
docker-compose \
run \
builder \
--rm \
cli \
/code/faabric/dist-test/build_internal.sh

popd >> /dev/null
5 changes: 1 addition & 4 deletions dist-test/build_internal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
set -e

export PROJ_ROOT=$(dirname $(dirname $(readlink -f $0)))
pushd ${PROJ_ROOT}/dist-test >> /dev/null
pushd ${PROJ_ROOT} >> /dev/null

# Run the debug build
inv dev.cmake --build=Debug
inv dev.cc faabric_dist_tests
inv dev.cc faabric_dist_test_server

# Copy the results
cp -r /build/faabric/static/* /build/faabric/dist-test/

popd >> /dev/null
19 changes: 19 additions & 0 deletions dist-test/dev_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -e

THIS_DIR=$(dirname $(readlink -f $0))
PROJ_ROOT=${THIS_DIR}/..
pushd ${PROJ_ROOT} > /dev/null

if [[ -z "$1" ]]; then
docker-compose \
up \
-d \
dist-test-server
else
docker-compose \
restart \
dist-test-server
fi

popd > /dev/null
58 changes: 0 additions & 58 deletions dist-test/docker-compose.yml

This file was deleted.

13 changes: 0 additions & 13 deletions dist-test/restart_server.sh

This file was deleted.

60 changes: 23 additions & 37 deletions dist-test/run.sh
Original file line number Diff line number Diff line change
@@ -1,46 +1,32 @@
#!/bin/bash

export PROJ_ROOT=$(dirname $(dirname $(readlink -f $0)))
pushd ${PROJ_ROOT}/dist-test >> /dev/null

# Set up image name
if [[ -z "${FAABRIC_CLI_IMAGE}" ]]; then
VERSION=$(cat ../VERSION)
export FAABRIC_CLI_IMAGE=faasm/faabric:${VERSION}
fi
pushd ${PROJ_ROOT} >> /dev/null

RETURN_VAL=0

if [ "$1" == "local" ]; then
INNER_SHELL=${SHELL:-"/bin/bash"}

# Start everything in the background
docker-compose \
up \
--no-recreate \
-d \
master

# Run the CLI
docker-compose \
exec \
master \
${INNER_SHELL}
else
# Run the tests directly
docker-compose \
run \
master \
/build/faabric/static/bin/faabric_dist_tests
RETURN_VAL=$?

echo "-------------------------------------------"
echo " WORKER LOGS "
echo "-------------------------------------------"
docker-compose logs worker

docker-compose stop
fi
# Run the test server in the background
docker-compose \
up \
-d \
dist-test-server

# Run the tests directly
docker-compose \
run \
--rm \
cli \
/build/faabric/static/bin/faabric_dist_tests

RETURN_VAL=$?

echo "-------------------------------------------"
echo " SERVER LOGS "
echo "-------------------------------------------"
docker-compose logs dist-test-server

# Stop everything
docker-compose stop

popd >> /dev/null

Expand Down
16 changes: 15 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker
- .:/code/faabric
- ./:/code/faabric
- ./build:/build/faabric
working_dir: /code/faabric
stdin_open: true
Expand All @@ -21,3 +21,17 @@ services:
- REDIS_QUEUE_HOST=redis
depends_on:
- redis

dist-test-server:
image: ${FAABRIC_CLI_IMAGE}
volumes:
- ./:/code/faabric
- ./build:/build/faabric
working_dir: /build/faabric/static
environment:
- LOG_LEVEL=debug
- REDIS_STATE_HOST=redis
- REDIS_QUEUE_HOST=redis
command: ./bin/faabric_dist_test_server
depends_on:
- redis
47 changes: 22 additions & 25 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,51 +73,48 @@ inv dev.cc faabric
We have some standard tests using [Catch2](https://github.com/catchorg/Catch2)
under the `faabric_tests` target.

### Distributed tests
## Distributed tests

The distributed tests are aimed at testing a more "realistic" distributed
environment and use multiple containers.
The distributed tests are aimed at testing distributed features across more than
one host.

To set up the initial build:
### Running locally

```bash
# Build the relevant binaries
./dist-test/build.sh
```

Then to run and develop locally:
To set up the distributed tests locally:

```bash
# Start up the CLI container
./dist-test/run.sh local
# Start the CLI
./bin/cli.sh

# Rebuild and run inside CLI container as usual
# Build both the tests and the server
inv dev.cc faabric_dist_tests
/build/static/bin/faabric_dist_tests

# To rebuild the server, you'll need to rebuild and restart
inv dev.cc faabric_dist_test_server
```

In another terminal, start the server:

# Outside the container
./dist-test/restart_server.sh
```bash
./dist-tests/dev_server.sh
```

To see logs locally:
Back in the CLI, you can then run the tests:

```bash
cd dist-test
docker-compose logs -f
faabric_dist_tests
```

To run as if in CI:
You can repeat this process of rebuilding, restarting the server, and running.

### Running as if in CI

To run the distributed tests as if in CI:

```bash
# Clean up
cd dist-test
docker-compose stop
docker-compose rm

# Run once through
# Build and run
./dist-test/build.sh
./dist-test/run.sh
```

Expand Down
15 changes: 15 additions & 0 deletions tests/dist/fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,20 @@ class DistTestsFixture
std::make_shared<tests::DistTestExecutorFactory>();
faabric::scheduler::setExecutorFactory(fac);
}

std::string getWorkerIP()
{
if (workerIP.empty()) {
workerIP = faabric::util::getIPFromHostname("dist-test-server");
}

return workerIP;
}

std::string getMasterIP() { return conf.endpointHost; }

private:
std::string workerIP;
std::string masterIP;
};
}
4 changes: 0 additions & 4 deletions tests/dist/init.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#pragma once

// Note - these must match the container config
#define MASTER_IP "172.50.0.4"
#define WORKER_IP "172.50.0.5"

namespace tests {

void initDistTests();
Expand Down
4 changes: 2 additions & 2 deletions tests/dist/scheduler/test_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TEST_CASE_METHOD(DistTestsFixture,

sch.getFunctionResult(m.id(), 1000);
std::string expected =
fmt::format("Function {} executed on host {}", m.id(), MASTER_IP);
fmt::format("Function {} executed on host {}", m.id(), getMasterIP());

REQUIRE(m.outputdata() == expected);
}
Expand All @@ -47,7 +47,7 @@ TEST_CASE_METHOD(DistTestsFixture,
faabric::Message result = sch.getFunctionResult(m.id(), 1000);

std::string expected =
fmt::format("Function {} executed on host {}", m.id(), WORKER_IP);
fmt::format("Function {} executed on host {}", m.id(), getWorkerIP());

REQUIRE(result.outputdata() == expected);
}
Expand Down
Loading