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

Dockerfile and Documentation Changes #53

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions .github/CONTRIBUTING.md
shihab-dls marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Contribute to the project

Contributions and issues are most welcome! All issues and pull requests are
handled through [GitHub](https://github.com/PandABlocks/PandABlocks-rootfs/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/PandABlocks/PandABlocks-rootfs/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.

## Developer Information

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.

This project was created using the [Diamond Light Source Copier Template](https://github.com/DiamondLightSource/python-copier-template) for Python projects.

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.1.0/how-to.html).
34 changes: 34 additions & 0 deletions .github/actions/install_requirements/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Install requirements
description: Install a version of python then call pip install and report what was installed
inputs:
python-version:
description: Python version to install, default is from Dockerfile
default: "dev"
pip-install:
description: Parameters to pass to pip install
default: "$([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e .[dev]"

runs:
using: composite
steps:
- name: Get version of python
run: |
PYTHON_VERSION="${{ inputs.python-version }}"
if [ $PYTHON_VERSION == "dev" ]; then
PYTHON_VERSION=$(sed -n "s/ARG PYTHON_VERSION=//p" Dockerfile)
fi
echo "PYTHON_VERSION=$PYTHON_VERSION" >> "$GITHUB_ENV"
shell: bash

- name: Setup python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install packages
run: pip install ${{ inputs.pip-install }}
shell: bash

- name: Report what was installed
run: pip freeze
shell: bash
10 changes: 6 additions & 4 deletions .github/pages/index.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Redirecting to master branch</title>

<head>
<title>Redirecting to main branch</title>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0; url=./master/index.html">
<link rel="canonical" href="master/index.html">
</head>
<link rel="canonical" href="main/index.html">
</head>

</html>
95 changes: 95 additions & 0 deletions .github/pages/make_switcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import json
import logging
from argparse import ArgumentParser
from pathlib import Path
from subprocess import CalledProcessError, check_output
from typing import List, Optional


def report_output(stdout: bytes, label: str) -> List[str]:
ret = stdout.decode().strip().split("\n")
print(f"{label}: {ret}")
return ret


def get_branch_contents(ref: str) -> List[str]:
"""Get the list of directories in a branch."""
stdout = check_output(["git", "ls-tree", "-d", "--name-only", ref])
return report_output(stdout, "Branch contents")


def get_sorted_tags_list() -> List[str]:
"""Get a list of sorted tags in descending order from the repository."""
stdout = check_output(["git", "tag", "-l", "--sort=-v:refname"])
return report_output(stdout, "Tags list")


def get_versions(ref: str, add: Optional[str]) -> List[str]:
"""Generate the file containing the list of all GitHub Pages builds."""
# Get the directories (i.e. builds) from the GitHub Pages branch
try:
builds = set(get_branch_contents(ref))
except CalledProcessError:
builds = set()
logging.warning(f"Cannot get {ref} contents")

# Add and remove from the list of builds
if add:
builds.add(add)

# Get a sorted list of tags
tags = get_sorted_tags_list()

# Make the sorted versions list from main branches and tags
versions: List[str] = []
for version in ["master", "main"] + tags:
if version in builds:
versions.append(version)
builds.remove(version)

# Add in anything that is left to the bottom
versions += sorted(builds)
print(f"Sorted versions: {versions}")
return versions


def write_json(path: Path, repository: str, versions: str):
org, repo_name = repository.split("/")
pages_url = f"https://{org}.github.io"
if repo_name != f"{org}.github.io":
# Only add the repo name if it isn't the source for the org pages site
pages_url += f"/{repo_name}"
struct = [
{"version": version, "url": f"{pages_url}/{version}/"} for version in versions
]
text = json.dumps(struct, indent=2)
print(f"JSON switcher:\n{text}")
path.write_text(text, encoding="utf-8")


def main(args=None):
parser = ArgumentParser(
description="Make a versions.json file from gh-pages directories"
)
parser.add_argument(
"--add",
help="Add this directory to the list of existing directories",
)
parser.add_argument(
"repository",
help="The GitHub org and repository name: ORG/REPO",
)
parser.add_argument(
"output",
type=Path,
help="Path of write switcher.json to",
)
args = parser.parse_args(args)

# Write the versions file
versions = get_versions("origin/gh-pages", args.add)
write_json(args.output, args.repository, versions)


if __name__ == "__main__":
main()
68 changes: 68 additions & 0 deletions .github/workflows/_build-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
on:
workflow_call:


jobs:
build-image:
runs-on: ubuntu-latest
steps:

# Git repositories
- name: Checkout Source
uses: actions/checkout@v2
with:
path: PandABlocks-rootfs

- name: Checkout rootfs builder
uses: actions/checkout@v2
with:
repository: dls-controls/rootfs
path: rootfs

- name: Checkout annotypes
uses: actions/checkout@v2
with:
repository: dls-controls/annotypes
path: annotypes

- name: Checkout pymalcolm
uses: actions/checkout@v2
with:
repository: dls-controls/pymalcolm
path: pymalcolm

- name: Checkout malcolmjs
uses: actions/checkout@v2
with:
repository: dls-controls/malcolmjs
path: malcolmjs

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-

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

# Build and push container image to registry
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./PandABlocks-rootfs/Dockerfile
push: false
tags: pandablocks-dev-container:latest
outputs: type=docker, dest=./pandablocks-dev-container.tar
cache-to: type=gha

# Upload container as an artifact
- name: Upload contianer as an artifact
uses: actions/upload-artifact@v4
with:
name: pandablocks-dev-container
path: .
46 changes: 46 additions & 0 deletions .github/workflows/_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
on:
workflow_call:

jobs:
build:
strategy:
fail-fast: false
matrix:
platform: ["zynq", "zynqmp"]

name: build/${{ matrix.platform }}
runs-on: ubuntu-latest

steps:

# Download artifact of image
- uses: actions/download-artifact@v4
with:
name: pandablocks-dev-container
path: .

# Git repositories
- name: Checkout Source
uses: actions/checkout@v2
with:
path: PandABlocks-rootfs
# require history to get back to last tag for version number of branches
fetch-depth: 0

# Run make inside the container
- name: Make zips
run: |
docker load --input pandablocks-dev-container.tar
docker run \
-v "${{ github.workspace }}:/repos" \
-v "${{ github.workspace }}/build:/build" \
pandablocks-dev-container:latest \
/bin/bash -c \
"cd PandABlocks-rootfs && ln -s CONFIG.example CONFIG && make zips PLATFORM=${{ matrix.platform }}"

# Upload zips as artifact
- name: Upload deps and boot build files
uses: actions/upload-artifact@v4
with:
name: zips-${{ matrix.platform }}
path: ./build/PandA-rootfs-${{ matrix.platform }}/*.zip
78 changes: 78 additions & 0 deletions .github/workflows/_container-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
on:
workflow_call:

jobs:
container-release:
runs-on: ubuntu-latest
# if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
steps:

# Git repositories
- name: Checkout Source
uses: actions/checkout@v2
with:
path: PandABlocks-rootfs

- name: Checkout rootfs builder
uses: actions/checkout@v2
with:
repository: dls-controls/rootfs
path: rootfs

- name: Checkout annotypes
uses: actions/checkout@v2
with:
repository: dls-controls/annotypes
path: annotypes

- name: Checkout pymalcolm
uses: actions/checkout@v2
with:
repository: dls-controls/pymalcolm
path: pymalcolm

- name: Checkout malcolmjs
uses: actions/checkout@v2
with:
repository: dls-controls/malcolmjs
path: malcolmjs

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-

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

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/pandablocks/pandablocks-dev-container
tags: |
type=ref,event=branch
type=ref,event=tag
type=raw,value=latest

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

- name: Rebuild and release image
uses: docker/build-push-action@v2
with:
context: .
file: ./PandABlocks-rootfs/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
push: ${{ github.event_name != 'pull_request' }}
Loading
Loading