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

Rename and make naming consistent #28

Merged
merged 7 commits into from
Jun 12, 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
12 changes: 6 additions & 6 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ _src_path: gh:DiamondLightSource/python-copier-template
author_email: [email protected]
author_name: David Perl
component_owner: group:default/sscc
description: an service to put and get your config values from
distribution_name: config-service
docker: true
description: A service to put and get your config values from
distribution_name: daq-config-server
docker: false
docs_type: README
git_platform: github.com
github_org: dperl-dls
package_name: config_service
github_org: DiamondLightSource
package_name: daq_config_server
pypi: true
repo_name: config-service
repo_name: daq-config-server
type_checker: pyright
4 changes: 2 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Contribute to the project

Contributions and issues are most welcome! All issues and pull requests are
handled through [GitHub](https://github.com/dperl-dls/config-service/issues). Also, please check for any existing issues before
handled through [GitHub](https://github.com/DiamondLightSource/daq-config-server/issues). Also, please check for any existing issues before
filing a new one. If you have a great idea but it involves big changes, please
file a ticket before making a pull request! We want to make sure you don't spend
your time coding something that might not fit the scope of the project.

## Issue or Discussion?

Github also offers [discussions](https://github.com/dperl-dls/config-service/discussions) as a place to ask questions and share ideas. If
Github also offers [discussions](https://github.com/DiamondLightSource/daq-config-server/discussions) as a place to ask questions and share ideas. If
your issue is open ended and it is not obvious when it can be "closed", please
raise it as a discussion instead.

Expand Down
110 changes: 55 additions & 55 deletions .github/workflows/_container.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
on:
workflow_call:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Need this to get version number from last tag
fetch-depth: 0

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

- name: Log in to GitHub Docker Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and export to Docker local cache
uses: docker/build-push-action@v5
with:
context: .
# Need load and tags so we can test it below
load: true
tags: tag_for_testing

- name: Test cli works in cached runtime image
run: docker run --rm tag_for_testing config-service --version

- name: Create tags for publishing image
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=tag
type=raw,value=latest

- name: Push cached image to container registry
if: github.ref_type == 'tag'
uses: docker/build-push-action@v5
# This does not build the image again, it will find the image in the
# Docker cache and publish it
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
workflow_call:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Need this to get version number from last tag
fetch-depth: 0
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Docker Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and export to Docker local cache
uses: docker/build-push-action@v5
with:
context: .
# Need load and tags so we can test it below
load: true
tags: tag_for_testing
- name: Test cli works in cached runtime image
run: docker run --rm tag_for_testing config-service --version
- name: Create tags for publishing image
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=tag
type=raw,value=latest
- name: Push cached image to container registry
if: github.ref_type == 'tag'
uses: docker/build-push-action@v5
# This does not build the image again, it will find the image in the
# Docker cache and publish it
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
4 changes: 2 additions & 2 deletions .github/workflows/backend_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: backend CI
on:
push:
paths:
- gui/**
- gui/**
pull_request:
paths:
- gui/**
- gui/**

jobs:
check:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ ARG RUN_APP_IN_DEV_MODE=0
ENV DEV_MODE=${RUN_APP_IN_DEV_MODE}

# change this entrypoint if it is not the same as the repo
CMD config-service
CMD daq-config-server
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
[![CI](https://github.com/dperl-dls/config-service/actions/workflows/ci.yml/badge.svg)](https://github.com/dperl-dls/config-service/actions/workflows/ci.yml)
[![Coverage](https://codecov.io/gh/dperl-dls/config-service/branch/main/graph/badge.svg)](https://codecov.io/gh/dperl-dls/config-service)
[![Frontend CI](https://github.com/dperl-dls/daq-config-server/actions/workflows/gui_ci.yml/badge.svg)](https://github.com/dperl-dls/daq-config-server/actions/workflows/gui_ci.yml)
[![Backend CI](https://github.com/dperl-dls/daq-config-server/actions/workflows/backend_ci.yml/badge.svg)](https://github.com/dperl-dls/daq-config-server/actions/workflows/backend_ci.yml)
[![Coverage](https://codecov.io/gh/dperl-dls/daq-config-server/branch/main/graph/badge.svg)](https://codecov.io/gh/dperl-dls/daq-config-server)
[![PyPI](https://img.shields.io/pypi/v/daq-config-server.svg)](https://pypi.org/project/daq-config-server)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

# config_service
# daq_config_server

A service to put and get your config values from.

| Source | <https://github.com/dperl-dls/config-service> |
| :------: | :----------------------------------------------------: |
| Docker | `docker run ghcr.io/dperl-dls/config-service:latest` |
| Releases | <https://github.com/dperl-dls/config-service/releases> |
| Source | <https://github.com/DiamondLightSource/daq-config-server> |
| :------: | :----------------------------------------------------------------: |
| Docker | `docker run ghcr.io/DiamondLightSource/daq-config-server:latest` |
| Releases | <https://github.com/DiamondLightSource/daq-config-server/releases> |

A simple app for storing and fetching values. Has a Valkey (Redis) instance as well as options for file-backed legacy
values (e.g. `beamlineParameters`...)

Currently the server application always needs to be run with the `--dev` flag, as it cannot yet look at the DLS
filesystem to find the real beamline parameter files.

To use the config values in an experimental application (e.g. Hyperion) you can do:

```python
from config_service.client import ConfigService
from daq_config_server.client import ConfigServer

config_service = ConfigService("<service ip address>", <port>)
config_server = ConfigServer("<service ip address>", <port>)

use_stub_offsets: bool = config_service.best_effort_get_feature_flag("use_stub_offsets")
use_stub_offsets: bool = config_server.best_effort_get_feature_flag("use_stub_offsets")

```

Expand All @@ -45,5 +50,5 @@ To deploy a live version, you can run the above script with no arguments and the
argus, run `kubectl rollout restart deployment`

To test locally, you can build everything with `./deployment/build_and_push_all.sh --dev --no-push` and then
run the containers `daq-config-server-dev` (with the command `config-service --dev`), `daq-config-server-db-dev`,
run the containers `daq-config-server-dev` (with the command `daq-config-server --dev`), `daq-config-server-db-dev`,
and `daq-config-server-gui-dev`, all with the `--net host` option.
6 changes: 3 additions & 3 deletions catalog-info.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: config-service
title: config-service
description: an service to put and get your config values from
name: daq-config-server
title: daq-config-server
description: A service to put and get your config values from
spec:
type: documentation
lifecycle: experimental
Expand Down
5 changes: 4 additions & 1 deletion gui/config-server-gui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ import {
import * as React from "react";
import { ColorModeSwitcher } from "./ColorModeSwitcher";

var BACKEND = process.env.REACT_APP_BACKEND_ADDR;
var BACKEND =
process.env.NODE_ENV === "production"
? process.env.REACT_APP_BACKEND_ADDR
: "http://localhost:8555";
type FeatureFlag = { name: string; value: boolean };

let start_data = fetch(`${BACKEND}/featureflag`).then((response) =>
Expand Down
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools>=64", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[project]
name = "config-service"
name = "daq-config-server"
classifiers = [
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: Apache Software License",
Expand Down Expand Up @@ -33,18 +33,18 @@ dev = [
]

[project.scripts]
config-service = "config_service.__main__:main"
daq-config-server = "daq_config_server.__main__:main"

[project.urls]
GitHub = "https://github.com/dperl-dls/config-service"
GitHub = "https://github.com/DiamondLightSource/daq-config-server"

[[project.authors]] # Further authors may be added by duplicating this section
email = "[email protected]"
name = "David Perl"


[tool.setuptools_scm]
write_to = "src/config_service/_version.py"
write_to = "src/daq_config_server/_version.py"

[tool.pyright]
reportMissingImports = false # Ignore missing stubs in imported modules
Expand All @@ -61,7 +61,7 @@ filterwarnings = "error"
testpaths = "docs src tests"

[tool.coverage.run]
data_file = "/tmp/config_service.coverage"
data_file = "/tmp/daq_config_server.coverage"

[tool.coverage.paths]
# Tests are run from installed location, map back to the src directory
Expand All @@ -85,7 +85,7 @@ allowlist_externals =
commands =
pre-commit: pre-commit run --all-files --show-diff-on-failure {posargs}
type-checking: pyright src tests {posargs}
tests: pytest --cov=config_service --cov-report term --cov-report xml:cov.xml {posargs}
tests: pytest --cov=daq_config_server --cov-report term --cov-report xml:cov.xml {posargs}
"""

[tool.ruff]
Expand Down
4 changes: 0 additions & 4 deletions src/config_service/__init__.py

This file was deleted.

3 changes: 3 additions & 0 deletions src/daq_config_server/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from ._version import __version__

__all__ = ["__version__"]
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ def main():
main(args)


# test with: python -m config_service
# test with: python -m daq_config_server
if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions src/config_service/app.py → src/daq_config_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
ROOT_PATH = ""

app = FastAPI(
title="DAQ config service",
title="DAQ config server",
description="""For storing and fetching beamline parameters, etc. which are needed
by more than one applicatioon or service""",
root_path=ROOT_PATH,
Expand Down Expand Up @@ -136,4 +136,4 @@ def main(args):
else:
BEAMLINE_PARAM_PATH = BEAMLINE_PARAMETER_PATHS["i03"]
BEAMLINE_PARAMS = GDABeamlineParameters.from_file(BEAMLINE_PARAM_PATH)
uvicorn.run(app="config_service.app:app", host="0.0.0.0", port=8555)
uvicorn.run(app="daq_config_server.app:app", host="0.0.0.0", port=8555)
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
T = TypeVar("T")


class ConfigService:
class ConfigServer:
def __init__(self, address: str, port: int, log: Logger | None = None) -> None:
self.address = address
self.port = port
self._log = log if log else getLogger("config_service.client")
self._log = log if log else getLogger("daq_config_server.client")

def _get(self, endpoint: str, param: str | None = None):
conn = HTTPConnection(self.address, self.port)
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from fastapi import status
from fastapi.testclient import TestClient

from config_service.app import app
from config_service.beamline_parameters import GDABeamlineParameters
from config_service.constants import ENDPOINTS
from daq_config_server.app import app
from daq_config_server.beamline_parameters import GDABeamlineParameters
from daq_config_server.constants import ENDPOINTS

mock_bl_params = GDABeamlineParameters()
mock_bl_params.params = {"p1": 0.234, "p2": 0.345, "p3": 678}
Expand All @@ -28,7 +28,7 @@ async def _assert_get_and_response(
assert content == expected_response


@patch("config_service.app.BEAMLINE_PARAMS", mock_bl_params)
@patch("daq_config_server.app.BEAMLINE_PARAMS", mock_bl_params)
class TestApi:
async def test_get_all_beamlineparams(self, mock_app):
await _assert_get_and_response(
Expand All @@ -43,7 +43,7 @@ async def test_get_one_beamlineparam(self, mock_app):
{param: mock_bl_params.params[param]},
)

@patch("config_service.app.valkey")
@patch("daq_config_server.app.valkey")
async def test_get_feature_list(self, mock_valkey: MagicMock, mock_app):
test_param_list = ["param_1", "param_2", "param_3"]
mock_valkey.smembers.return_value = test_param_list
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import subprocess
import sys

from config_service import __version__
from daq_config_server import __version__


def test_cli_version():
cmd = [sys.executable, "-m", "config_service", "--version"]
cmd = [sys.executable, "-m", "daq_config_server", "--version"]
assert subprocess.check_output(cmd).decode().strip() == __version__