Skip to content

Commit b6a6b37

Browse files
committed
intial commit
0 parents  commit b6a6b37

30 files changed

+1130
-0
lines changed

.copier-answers.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Changes here will be overwritten by Copier
2+
_commit: 2.0.2
3+
_src_path: gh:DiamondLightSource/python-copier-template
4+
author_email: giles.knap@diamond.ac.uk
5+
author_name: Giles Knap
6+
component_owner: group:default/sscc
7+
description: Support for a K8S proxy container in controlling and monitoring RTEMS
8+
EPICS IOCs
9+
distribution_name: rtems-proxy
10+
docker: true
11+
docs_type: README
12+
git_platform: github.com
13+
github_org: epics-containers
14+
package_name: rtems_proxy
15+
pypi: true
16+
repo_name: rtems-proxy
17+
type_checker: pyright

.devcontainer/devcontainer.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// For format details, see https://containers.dev/implementors/json_reference/
2+
{
3+
"name": "Python 3 Developer Container",
4+
"build": {
5+
"dockerfile": "../Dockerfile",
6+
"target": "developer"
7+
},
8+
"remoteEnv": {
9+
// Allow X11 apps to run inside the container
10+
"DISPLAY": "${localEnv:DISPLAY}"
11+
},
12+
"customizations": {
13+
"vscode": {
14+
// Set *default* container specific settings.json values on container create.
15+
"settings": {
16+
"python.defaultInterpreterPath": "/venv/bin/python"
17+
},
18+
// Add the IDs of extensions you want installed when the container is created.
19+
"extensions": [
20+
"ms-python.python",
21+
"github.vscode-github-actions",
22+
"tamasfe.even-better-toml",
23+
"redhat.vscode-yaml",
24+
"ryanluker.vscode-coverage-gutters",
25+
"charliermarsh.ruff",
26+
"ms-azuretools.vscode-docker"
27+
]
28+
}
29+
},
30+
"features": {
31+
// Some default things like git config
32+
"ghcr.io/devcontainers/features/common-utils:2": {
33+
"upgradePackages": false
34+
}
35+
},
36+
"runArgs": [
37+
// Allow the container to access the host X11 display and EPICS CA
38+
"--net=host",
39+
// Make sure SELinux does not disable with access to host filesystems like tmp
40+
"--security-opt=label=disable"
41+
],
42+
// Mount the parent as /workspaces so we can pip install peers as editable
43+
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind",
44+
// After the container is created, install the python project in editable form
45+
"postCreateCommand": "pip install $([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e '.[dev]' && pre-commit install"
46+
}

.github/CONTRIBUTING.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Contribute to the project
2+
3+
Contributions and issues are most welcome! All issues and pull requests are
4+
handled through [GitHub](https://github.com/epics-containers/rtems-proxy/issues). Also, please check for any existing issues before
5+
filing a new one. If you have a great idea but it involves big changes, please
6+
file a ticket before making a pull request! We want to make sure you don't spend
7+
your time coding something that might not fit the scope of the project.
8+
9+
## Issue or Discussion?
10+
11+
Github also offers [discussions](https://github.com/epics-containers/rtems-proxy/discussions) as a place to ask questions and share ideas. If
12+
your issue is open ended and it is not obvious when it can be "closed", please
13+
raise it as a discussion instead.
14+
15+
## Code Coverage
16+
17+
While 100% code coverage does not make a library bug-free, it significantly
18+
reduces the number of easily caught bugs! Please make sure coverage remains the
19+
same or is improved by a pull request!
20+
21+
## Developer Information
22+
23+
It is recommended that developers use a [vscode devcontainer](https://code.visualstudio.com/docs/devcontainers/containers). This repository contains configuration to set up a containerized development environment that suits its own needs.
24+
25+
This project was created using the [Diamond Light Source Copier Template](https://github.com/DiamondLightSource/python-copier-template) for Python projects.
26+
27+
For more information on common tasks like setting up a developer environment, running the tests, and setting a pre-commit hook, see the template's [How-to guides](https://diamondlightsource.github.io/python-copier-template/2.0.2/how-to.html).
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Install requirements
2+
description: Install a version of python then call pip install and report what was installed
3+
inputs:
4+
python-version:
5+
description: Python version to install, default is from Dockerfile
6+
default: "dev"
7+
pip-install:
8+
description: Parameters to pass to pip install
9+
default: "$([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e .[dev]"
10+
11+
runs:
12+
using: composite
13+
steps:
14+
- name: Get version of python
15+
run: |
16+
PYTHON_VERSION="${{ inputs.python-version }}"
17+
if [ $PYTHON_VERSION == "dev" ]; then
18+
PYTHON_VERSION=$(sed -n "s/ARG PYTHON_VERSION=//p" Dockerfile)
19+
fi
20+
echo "PYTHON_VERSION=$PYTHON_VERSION" >> "$GITHUB_ENV"
21+
shell: bash
22+
23+
- name: Setup python
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: ${{ env.PYTHON_VERSION }}
27+
28+
- name: Install packages
29+
run: pip install ${{ inputs.pip-install }}
30+
shell: bash
31+
32+
- name: Report what was installed
33+
run: pip freeze
34+
shell: bash

.github/dependabot.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "github-actions"
9+
directory: "/"
10+
schedule:
11+
interval: "weekly"
12+
groups:
13+
actions:
14+
patterns:
15+
- "*"
16+
17+
- package-ecosystem: "pip"
18+
directory: "/"
19+
schedule:
20+
interval: "weekly"
21+
groups:
22+
dev-dependencies:
23+
patterns:
24+
- "*"

.github/pages/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<title>Redirecting to main branch</title>
6+
<meta charset="utf-8">
7+
<meta http-equiv="refresh" content="0; url=./main/index.html">
8+
<link rel="canonical" href="main/index.html">
9+
</head>
10+
11+
</html>

.github/pages/make_switcher.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import json
2+
import logging
3+
from argparse import ArgumentParser
4+
from pathlib import Path
5+
from subprocess import CalledProcessError, check_output
6+
from typing import List, Optional
7+
8+
9+
def report_output(stdout: bytes, label: str) -> List[str]:
10+
ret = stdout.decode().strip().split("\n")
11+
print(f"{label}: {ret}")
12+
return ret
13+
14+
15+
def get_branch_contents(ref: str) -> List[str]:
16+
"""Get the list of directories in a branch."""
17+
stdout = check_output(["git", "ls-tree", "-d", "--name-only", ref])
18+
return report_output(stdout, "Branch contents")
19+
20+
21+
def get_sorted_tags_list() -> List[str]:
22+
"""Get a list of sorted tags in descending order from the repository."""
23+
stdout = check_output(["git", "tag", "-l", "--sort=-v:refname"])
24+
return report_output(stdout, "Tags list")
25+
26+
27+
def get_versions(ref: str, add: Optional[str]) -> List[str]:
28+
"""Generate the file containing the list of all GitHub Pages builds."""
29+
# Get the directories (i.e. builds) from the GitHub Pages branch
30+
try:
31+
builds = set(get_branch_contents(ref))
32+
except CalledProcessError:
33+
builds = set()
34+
logging.warning(f"Cannot get {ref} contents")
35+
36+
# Add and remove from the list of builds
37+
if add:
38+
builds.add(add)
39+
40+
# Get a sorted list of tags
41+
tags = get_sorted_tags_list()
42+
43+
# Make the sorted versions list from main branches and tags
44+
versions: List[str] = []
45+
for version in ["master", "main"] + tags:
46+
if version in builds:
47+
versions.append(version)
48+
builds.remove(version)
49+
50+
# Add in anything that is left to the bottom
51+
versions += sorted(builds)
52+
print(f"Sorted versions: {versions}")
53+
return versions
54+
55+
56+
def write_json(path: Path, repository: str, versions: str):
57+
org, repo_name = repository.split("/")
58+
struct = [
59+
{"version": version, "url": f"https://{org}.github.io/{repo_name}/{version}/"}
60+
for version in versions
61+
]
62+
text = json.dumps(struct, indent=2)
63+
print(f"JSON switcher:\n{text}")
64+
path.write_text(text, encoding="utf-8")
65+
66+
67+
def main(args=None):
68+
parser = ArgumentParser(
69+
description="Make a versions.json file from gh-pages directories"
70+
)
71+
parser.add_argument(
72+
"--add",
73+
help="Add this directory to the list of existing directories",
74+
)
75+
parser.add_argument(
76+
"repository",
77+
help="The GitHub org and repository name: ORG/REPO",
78+
)
79+
parser.add_argument(
80+
"output",
81+
type=Path,
82+
help="Path of write switcher.json to",
83+
)
84+
args = parser.parse_args(args)
85+
86+
# Write the versions file
87+
versions = get_versions("origin/gh-pages", args.add)
88+
write_json(args.output, args.repository, versions)
89+
90+
91+
if __name__ == "__main__":
92+
main()

.github/workflows/_check.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
on:
2+
workflow_call:
3+
outputs:
4+
branch-pr:
5+
description: The PR number if the branch is in one
6+
value: ${{ jobs.pr.outputs.branch-pr }}
7+
8+
jobs:
9+
pr:
10+
runs-on: "ubuntu-latest"
11+
outputs:
12+
branch-pr: ${{ steps.script.outputs.result }}
13+
steps:
14+
- uses: actions/github-script@v7
15+
id: script
16+
if: github.event_name == 'push'
17+
with:
18+
script: |
19+
const prs = await github.rest.pulls.list({
20+
owner: context.repo.owner,
21+
repo: context.repo.repo,
22+
head: context.repo.owner + ':${{ github.ref_name }}'
23+
})
24+
if (prs.data.length) {
25+
console.log(`::notice ::Skipping CI on branch push as it is already run in PR #${prs.data[0]["number"]}`)
26+
return prs.data[0]["number"]
27+
}

.github/workflows/_container.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
on:
2+
workflow_call:
3+
4+
jobs:
5+
build:
6+
runs-on: ubuntu-latest
7+
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v4
11+
with:
12+
# Need this to get version number from last tag
13+
fetch-depth: 0
14+
15+
- name: Set up Docker Buildx
16+
id: buildx
17+
uses: docker/setup-buildx-action@v3
18+
19+
- name: Log in to GitHub Docker Registry
20+
if: github.event_name != 'pull_request'
21+
uses: docker/login-action@v3
22+
with:
23+
registry: ghcr.io
24+
username: ${{ github.actor }}
25+
password: ${{ secrets.GITHUB_TOKEN }}
26+
27+
- name: Build and export to Docker local cache
28+
uses: docker/build-push-action@v5
29+
with:
30+
context: .
31+
# Need load and tags so we can test it below
32+
load: true
33+
tags: tag_for_testing
34+
35+
- name: Test cli works in cached runtime image
36+
run: docker run --rm tag_for_testing --version
37+
38+
- name: Create tags for publishing image
39+
id: meta
40+
uses: docker/metadata-action@v5
41+
with:
42+
images: ghcr.io/${{ github.repository }}
43+
tags: |
44+
type=ref,event=tag
45+
type=raw,value=latest
46+
47+
- name: Push cached image to container registry
48+
if: github.ref_type == 'tag'
49+
uses: docker/build-push-action@v5
50+
# This does not build the image again, it will find the image in the
51+
# Docker cache and publish it
52+
with:
53+
context: .
54+
push: true
55+
tags: ${{ steps.meta.outputs.tags }}
56+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/_dist.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
on:
2+
workflow_call:
3+
4+
jobs:
5+
build:
6+
runs-on: "ubuntu-latest"
7+
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v4
11+
with:
12+
# Need this to get version number from last tag
13+
fetch-depth: 0
14+
15+
- name: Build sdist and wheel
16+
run: >
17+
export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) &&
18+
pipx run build
19+
20+
- name: Upload sdist and wheel as artifacts
21+
uses: actions/upload-artifact@v4
22+
with:
23+
name: dist
24+
path: dist
25+
26+
- name: Check for packaging errors
27+
run: pipx run twine check --strict dist/*
28+
29+
- name: Install produced wheel
30+
uses: ./.github/actions/install_requirements
31+
with:
32+
pip-install: dist/*.whl
33+
34+
- name: Test module --version works using the installed wheel
35+
# If more than one module in src/ replace with module name to test
36+
run: python -m $(ls --hide='*.egg-info' src | head -1) --version

0 commit comments

Comments
 (0)