Skip to content

Commit

Permalink
Update the test server container to use the new ghcr image
Browse files Browse the repository at this point in the history
Some updated to make this easier to use and maintain.
  • Loading branch information
JacobCallahan committed Nov 23, 2024
1 parent 2e1eeb8 commit 3b427c2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/update_test_server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Update Hussh Test Server GHCR Image

on:
push:
paths:
- 'tests/setup/**'
pull_request:
paths:
- 'tests/setup/**'

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# Login to GitHub Container Registry only on push events
- name: Login to GitHub Container Registry
if: github.event_name == 'push'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: jacobcallahan
password: ${{ secrets.GHCR_TOKEN }}

# Build and push Docker image
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
# Conditionally push based on the event type
push: ${{ github.event_name == 'push' }}
tags: ghcr.io/jacobcallahan/hussh/hussh-test-server:latest
3 changes: 2 additions & 1 deletion benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ It is also a good idea to run benchmarks a few times and run an average.

## Install benchmarking requirements
First, you will either need to have your own test target, putting that information in the `target.json` file in this directory.
Alternatively, you can install Docker or Podman, then build the hussh-test-server image in the `tests/setup/` directory of this repo.
If you want to use the test server container, pull it from `ghcr.io/jacobcallahan/hussh/hussh-test-server:latest`
Alternatively, you can build the hussh-test-server image in the `tests/setup/` directory of this repo.
Then you can start the test server with this command
```bash
docker run --rm -d -p 8022:22 hussh-test-server
Expand Down
12 changes: 5 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@
import pytest

TESTDIR = PurePath(__file__).parent
TEST_SERVER_IMAGE = "ghcr.io/jacobcallahan/hussh/hussh-test-server:latest"


@pytest.fixture(scope="session")
def ensure_test_server_image():
"""Ensure that the test server Docker image is available."""
client = docker.from_env()
try:
client.images.get("hussh-test-server")
client.images.get(TEST_SERVER_IMAGE)
except docker.errors.ImageNotFound:
client.images.build(
path=str(TESTDIR / "setup"),
tag="hussh-test-server",
)
client.images.pull(TEST_SERVER_IMAGE)
client.close()


Expand All @@ -34,7 +32,7 @@ def run_test_server(ensure_test_server_image):
container = client.containers.get("hussh-test-server")
except docker.errors.NotFound: # if not, start it
container = client.containers.run(
"hussh-test-server",
TEST_SERVER_IMAGE,
detach=True,
ports={"22/tcp": 8022},
name="hussh-test-server",
Expand All @@ -54,7 +52,7 @@ def run_second_server(ensure_test_server_image):
container = client.containers.get("hussh-test-server2")
except docker.errors.NotFound: # if not, start it
container = client.containers.run(
"hussh-test-server",
TEST_SERVER_IMAGE,
detach=True,
ports={"22/tcp": 8023},
name="hussh-test-server2",
Expand Down

0 comments on commit 3b427c2

Please sign in to comment.