From c41086654e9f2456c7e7d1a790d0505eb7cf620c Mon Sep 17 00:00:00 2001 From: Giles Knap Date: Wed, 27 Sep 2023 08:41:45 +0000 Subject: [PATCH] fix Dockerfile --- .devcontainer/.bashrc | 68 +++++++++++++++++++ .devcontainer/devcontainer.json | 47 +++++++++++++ .devcontainer/initializeCommand | 10 +++ Dockerfile | 4 +- ctools/README.md | 15 ----- ctools/telnet3.py | 114 -------------------------------- 6 files changed, 127 insertions(+), 131 deletions(-) create mode 100644 .devcontainer/.bashrc create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/initializeCommand delete mode 100644 ctools/README.md delete mode 100644 ctools/telnet3.py diff --git a/.devcontainer/.bashrc b/.devcontainer/.bashrc new file mode 100644 index 0000000..3e7f40c --- /dev/null +++ b/.devcontainer/.bashrc @@ -0,0 +1,68 @@ +################################################################################ +# epics-containers developer shell configuration. +# This is a standard ubuntu .bashrc plus a call to .bashrc_dev_container +# in the user's home directory on the host machine. +################################################################################ + +# ~/.bashrc: executed by bash(1) for non-login shells. +# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) +# for examples + +# If not running interactively, don't do anything +[ -z "$PS1" ] && return + +# don't put duplicate lines in the history. See bash(1) for more options +# ... or force ignoredups and ignorespace +HISTCONTROL=ignoredups:ignorespace + +# append to the history file, don't overwrite it +shopt -s histappend + +# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) +HISTSIZE=1000 +HISTFILESIZE=2000 + +# check the window size after each command and, if necessary, +# update the values of LINES and COLUMNS. +shopt -s checkwinsize + +# make less more friendly for non-text input files, see lesspipe(1) +[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" + +# set variable identifying the chroot you work in (used in the prompt below) +if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then + debian_chroot=$(cat /etc/debian_chroot) +fi + +PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' + +# enable color support of ls and also add handy aliases +if [ -x /usr/bin/dircolors ]; then + test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" + alias ls='ls --color=auto' + #alias dir='dir --color=auto' + #alias vdir='vdir --color=auto' + + alias grep='grep --color=auto' + alias fgrep='fgrep --color=auto' + alias egrep='egrep --color=auto' +fi + +# some more ls aliases +alias ll='ls -alF' +alias la='ls -A' +alias l='ls -CF' + +# Alias definitions. +# You may want to put all your additions into a separate file like +# ~/.bash_aliases, instead of adding them here directly. +# See /usr/share/doc/bash-doc/examples in the bash-doc package. + +if [ -f ~/.bash_aliases ]; then + . ~/.bash_aliases +fi + +# add user's custom .bashrc_dev_container +if [ -f ~/.bashrc_dev_container ]; then + . ~/.bashrc_dev_container +fi diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..fcacb38 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,47 @@ +// For format details, see https://containers.dev/implementors/json_reference/ +{ + "name": "epics-containers IOC devcontainer", + "build": { + "dockerfile": "../Dockerfile", + "target": "developer", + "args": { + "TARGET_ARCHITECTURE": "linux" + } + }, + "remoteEnv": { + "DISPLAY": "${localEnv:DISPLAY}", + "PROJECT_NAME": "${localWorkspaceFolderBasename}" + }, + "customizations": { + "vscode": { + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-python.vscode-pylance", + "tamasfe.even-better-toml", + "redhat.vscode-yaml", + "ryanluker.vscode-coverage-gutters", + "epicsdeb.vscode-epics", + "ms-python.black-formatter" + ] + }, + "settings": { + // global python venv created in epics-base + "python.defaultInterpreterPath": "/venv/bin/python" + } + }, + // Make sure the files we are mapping into the container exist on the host + "initializeCommand": "bash .devcontainer/initializeCommand ${devcontainerId}", + "runArgs": [ + "--net=host", + "--security-opt=label=disable" + ], + "mounts": [ + // Mount some useful local files from the user's home directory + "source=${localEnv:HOME}/.bash_eternal_history,target=/root/.bash_eternal_history,type=bind", + "source=${localWorkspaceFolder}/.devcontainer/.bashrc,target=/root/.bashrc,type=bind", + "source=${localEnv:HOME}/.bashrc_dev_container,target=/root/.bashrc_dev_container,type=bind", + "source=${localEnv:HOME}/.gitconfig,target=/root/.gitconfig,type=bind", + "source=${localEnv:HOME}/.inputrc,target=/root/.inputrc,type=bind", + "source=${localEnv:HOME}/.ssh,target=/root/.ssh,type=bind" + ] +} \ No newline at end of file diff --git a/.devcontainer/initializeCommand b/.devcontainer/initializeCommand new file mode 100644 index 0000000..9282972 --- /dev/null +++ b/.devcontainer/initializeCommand @@ -0,0 +1,10 @@ +#!/bin/bash + +# make sure all the files we mount into the container exist +for i in .bash_eternal_history .bashrc_dev_container .inputrc .gitconfig; do + if [ ! -f $HOME/$i ] ; then + touch $HOME/$i; + fi +done + +echo "devcontainerID ${1}" diff --git a/Dockerfile b/Dockerfile index 1a64bbc..1a94d60 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,8 +27,8 @@ RUN busy/install.sh R1-7-3 COPY ibek-support/ADCore/ ADCore/ RUN ADCore/install.sh R3-12-1 -COPY ibek-support/ADAravis/ ADAravis/ -RUN ADAravis/install.sh R2-3 +# COPY ibek-support/ADAravis/ ADAravis/ +# RUN ADAravis/install.sh R2-3 # Make the IOC RUN ibek ioc generate-makefile diff --git a/ctools/README.md b/ctools/README.md deleted file mode 100644 index 8185a06..0000000 --- a/ctools/README.md +++ /dev/null @@ -1,15 +0,0 @@ -The Ctools directory contains scripts that support epics-containers IOCs, -the contents of this folder is usually inherited from the epics-base -container image. - -Here we allow overriding or adding to the ctools files supplied by epics-base. - -This allows us to update these files for IOC builds without -rebuilding the entire stack of containers. - -Where practical, files in this folder should get pushed back into -epics-base/ctools each time a new release of epics-base is -happening. - -Placing files in here runs the risk that this module will not pick up -updates from epics-base and should be used sparingly. diff --git a/ctools/telnet3.py b/ctools/telnet3.py deleted file mode 100644 index ceb1a20..0000000 --- a/ctools/telnet3.py +++ /dev/null @@ -1,114 +0,0 @@ -import asyncio -import signal -from time import sleep - -import click -import telnetlib3 - - -@click.group() -def cli(): - pass - - -class TelnetRTEMS: - def __init__(self, hostname: str, port: int, reboot: bool, pause: bool): - self.hostname = hostname - self.port = port - self.reboot = reboot - self.pause = pause - self.running = True - self.terminated = False - signal.signal(signal.SIGINT, self.terminate) - signal.signal(signal.SIGTERM, self.terminate) - - def terminate(self, *args): - self.running = False - self.terminated = True - - async def user_input(self, writer): - loop = asyncio.events._get_running_loop() - - while self.running: - # run the wait for input in a separate thread - cmd = await loop.run_in_executor(None, input) - writer.write(cmd) - writer.write("\r") - writer.close() - - async def server_output(self, reader): - while self.running: - out_p = await reader.read(1024) - if not out_p: - raise EOFError("Connection closed by server") - print(out_p, flush=True, end="") - reader.close() - - async def shell(self, reader, writer): - # user input and server output in separate tasks - tasks = [ - self.server_output(reader), - self.user_input(writer), - ] - - await asyncio.gather(*tasks) - - async def send_command(self, cmd): - reader, writer = await telnetlib3.open_connection(self.hostname, self.port) - - writer.write("\r") - await asyncio.sleep(0.1) - prompt = await reader.read(1024) - print(f"prompt is {prompt.strip()}") - - print(f"Sending command: {cmd}") - writer.write(f"{cmd}\r") - await asyncio.sleep(0.1) - result = await reader.read(1024) - print(f"Result is: {result.strip()}") - - reader.close() - writer.close() - - async def connect(self): - while True: # retry loop - try: - if self.reboot: - print("REBOOTING IOC ...") - await self.send_command("exit") - self.reboot = False # only reboot once - elif self.pause: - print("Un-stopping IOC") - await self.send_command("iocRun") - - # start interactive session - reader, writer = await telnetlib3.open_connection( - self.hostname, self.port, shell=self.shell - ) - await writer.protocol.waiter_closed - - if self.terminated and self.pause: - print("Stopping IOC") - await self.send_command("iocPause") - - break # interactive session done so exit retry loop - - except ConnectionResetError: - # probably the previous pod is terminating and is still connected - print("Waiting for Telnet Port (connection reset), RETRYING ...") - sleep(3) - - -@cli.command() -@click.argument("hostname", type=str) -@click.argument("port", type=int) -@click.option("--reboot", type=bool, default=False) -@click.option("--pause", type=bool, default=False) -def connect(hostname: str, port: int, reboot: bool, pause: bool): - telnet = TelnetRTEMS(hostname, port, reboot, pause) - asyncio.run(telnet.connect()) - - -cli.add_command(connect) -if __name__ == "__main__": - cli()