Skip to content

Commit

Permalink
Test devcontainer action
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Czyz <[email protected]>
  • Loading branch information
mczyz-antmicro committed Mar 26, 2024
1 parent 16a7194 commit 0d2b2a0
Show file tree
Hide file tree
Showing 14 changed files with 314 additions and 6 deletions.
10 changes: 10 additions & 0 deletions .devcontainer/prebuilt/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"image": "ghcr.io/antmicro/openroad-codespace:lxqt",
"forwardPorts": [6080],
"portsAttributes": {
"6080": {
"label": "desktop"
}
}//,
// "onCreateCommand": "bash /workspaces/openroad-codespace/update-config.sh"
}
2 changes: 1 addition & 1 deletion .devcontainer/ubuntu-gui/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"image": "ghcr.io/antmicro/openroad-flow-scripts/ubuntu22.04:latest",
"image": "ghcr.io/antmicro/openroad-codespace:orfs",
"features": {
"ghcr.io/devcontainers/features/desktop-lite:1": {}
},
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Prebuild docker image
on:
push:
pull_request:
branches:
- main
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
build:
name: BUILD
runs-on: ubuntu-22.04
timeout-minutes: 600
steps:
- uses: actions/checkout@v4
with:
ref: "mczyz/dev"

- name: Login to GitHub Container Registry (GHCR)
if: github.event_name != 'pull_request' && github.repository == 'antmicro/openroad-codespace'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: gha
password: ${{ github.token }}

- name: Docker build
run: |
docker build -t ghcr.io/antmicro/openroad-codespace:orfs -f Dockerfile-orfs .
- name: Push container image to GitHub Container Registry (GHCR)
if: github.event_name != 'pull_request' && github.repository == 'antmicro/openroad-codespace'
run: docker push ghcr.io/antmicro/openroad-codespace:orfs

- name: Devcontainer build
run: |
npm install -g @devcontainers/cli
devcontainer build --config .devcontainer/ubuntu-gui/devcontainer.json --workspace-folder . --push false --image-name ghcr.io/antmicro/openroad-codespace:desktop
# docker image tag test:latest ghcr.io/antmicro/openroad-codespace:test
- name: Push container image to GitHub Container Registry (GHCR)
if: github.event_name != 'pull_request' && github.repository == 'antmicro/openroad-codespace'
run: docker push ghcr.io/antmicro/openroad-codespace:desktop

- name: Docker build
run: |
docker build -t ghcr.io/antmicro/openroad-codespace:lxqt -f Dockerfile-lxqt .
- name: Push container image to GitHub Container Registry (GHCR)
if: github.event_name != 'pull_request' && github.repository == 'antmicro/openroad-codespace'
run: docker push ghcr.io/antmicro/openroad-codespace:lxqt
4 changes: 4 additions & 0 deletions Dockerfile-lxqt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM ghcr.io/antmicro/openroad-codespace:desktop

COPY ./scripts/install-lxqt.sh /usr/local/bin/install-lxqt.sh
RUN bash /usr/local/bin/install-lxqt.sh
6 changes: 6 additions & 0 deletions Dockerfile-orfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM ubuntu:22.04

COPY ./scripts/install.sh /usr/local/bin/install.sh
RUN bash /usr/local/bin/install.sh

ENV PATH="$PATH:/opt/oss-cad-suite/bin"
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@

The goal is to provide a web browser experience of the OpenROAD GUI. Solution works with Firefox and Chrome.

First time Codespace users are encouraged to read the tutorial [creating a codespace for a repository](https://docs.github.com/en/codespaces/developing-in-a-codespace/creating-a-codespace-for-a-repository).

## User

1. First time users are encourage to read the tutorial [creating a codespace for a repository](https://docs.github.com/en/codespaces/developing-in-a-codespace/creating-a-codespace-for-a-repository). Follow this tutorial to create a codespace from the ORFS repository. Select `ubuntu gui` in the `Dev container configuration` field
2. Connect to the generated codespace
3. At the bottom, there should be tab `PORTS`, where you will find the `Forwarded Address`. Follow this link
4. NoVNC tab should open - default password is `vscode`.
5. Right-click on desktop and open Terminal and execute the following commands to run OpenROAD GUI
1. Create a codespace from this repository.

![create](https://github.com/antmicro/openroad-codespace/blob/mczyz/dev/img/create_codespace.gif)

2. Select `ubuntu gui` in the `Dev container configuration` field

![configure](https://github.com/antmicro/openroad-codespace/blob/mczyz/dev/img/configure_codespace.gif)

3. Connect to the generated codespace
4. At the bottom, there should be tab `PORTS`, where you will find the `Forwarded Address`. Follow this link to connect to NoVNC

![open](https://github.com/antmicro/openroad-codespace/blob/mczyz/dev/img/open_vnc.gif)

5. NoVNC tab should open - default password is `vscode`.
6. Right-click on desktop and open Terminal and execute the following commands to run OpenROAD GUI

```
cd /OpenROAD-flow-scripts/flow
Expand Down
72 changes: 72 additions & 0 deletions common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Base file is from devcontainers/features/desktop-lite/install.sh
# Original file is licensed as MIT
# Applied modifications to the script 2024

user_name="root"
group_name="root"
LOG=/tmp/container-init.log

export DBUS_SESSION_BUS_ADDRESS="autolaunch:"
export DISPLAY=":1"
export VNC_RESOLUTION="1920x1080x32"
export LANG="en_US.UTF-8"
export LANGUAGE="en_US.UTF-8"

# Try to kill pid based on name
kill_pid()
{
PIDS_TO_KILL=$(ps axjf | grep $1 | awk '{print $2}')
for PID in ${PIDS_TO_KILL[@]}; do
echo "Attempting to kill $PID"
kill -9 $PID
done
}

# Execute the command it not already running
startInBackgroundIfNotRunning()
{
log "Starting $1."
echo -e "\n** $(date) **" | sudoIf tee -a /tmp/$1.log > /dev/null
if ! pgrep -x $1 > /dev/null; then
keepRunningInBackground "$@"
while ! pgrep -x $1 > /dev/null; do
sleep 1
done
log "$1 started."
else
echo "$1 is already running." | sudoIf tee -a /tmp/$1.log > /dev/null
log "$1 is already running."
fi
}

# Keep command running in background
keepRunningInBackground()
{
($2 bash -c "while :; do echo [\$(date)] Process started.; $3; echo [\$(date)] Process exited!; sleep 5; done 2>&1" | sudoIf tee -a /tmp/$1.log > /dev/null & echo "$!" | sudoIf tee /tmp/$1.pid > /dev/null)
}

# Use sudo to run as root when required
sudoIf()
{
if [ "$(id -u)" -ne 0 ]; then
sudo "$@"
else
"$@"
fi
}

# Use sudo to run as non-root user if not already running
sudoUserIf()
{
if [ "$(id -u)" -eq 0 ] && [ "${user_name}" != "root" ]; then
sudo -u ${user_name} "$@"
else
"$@"
fi
}

# Log messages
log()
{
echo -e "[$(date)] $@" | sudoIf tee -a $LOG > /dev/null
}
38 changes: 38 additions & 0 deletions desktop-update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

. ./common.sh

log "** SCRIPT START **"

# Start dbus.
log 'Running "/etc/init.d/dbus start".'
if [ -f "/var/run/dbus/pid" ] && ! pgrep -x dbus-daemon > /dev/null; then
sudoIf rm -f /var/run/dbus/pid
fi
sudoIf /etc/init.d/dbus start 2>&1 | sudoIf tee -a /tmp/dbus-daemon-system.log > /dev/null
while ! pgrep -x dbus-daemon > /dev/null; do
sleep 1
done

# Startup tigervnc server and fluxbox
sudoIf rm -rf /tmp/.X11-unix /tmp/.X*-lock
mkdir -p /tmp/.X11-unix
sudoIf chmod 1777 /tmp/.X11-unix
sudoIf chown root:${group_name} /tmp/.X11-unix
if [ "$(echo "${VNC_RESOLUTION}" | tr -cd 'x' | wc -c)" = "1" ]; then VNC_RESOLUTION=${VNC_RESOLUTION}x16; fi
screen_geometry="${VNC_RESOLUTION%*x*}"
screen_depth="${VNC_RESOLUTION##*x}"
startInBackgroundIfNotRunning "Xtigervnc" sudoUserIf "tigervncserver ${DISPLAY} -geometry ${screen_geometry} -depth ${screen_depth} -rfbport 5901 -dpi ${VNC_DPI:-96} -localhost -desktop fluxbox -fg" -passwd /usr/local/etc/vscode-dev-containers/vnc-passwd

# Spin up noVNC if installed and not running.
if [ -d "/usr/local/novnc" ] && [ "$(ps -ef | grep /usr/local/novnc/noVNC*/utils/launch.sh | grep -v grep)" = "" ]; then
keepRunningInBackground "noVNC" sudoIf "/usr/local/novnc/noVNC*/utils/launch.sh --listen 6080 --vnc localhost:5901"
log "noVNC started."
else
log "noVNC is already running or not installed."
fi

# Run whatever was passed in
log "Executing \"$@\"."
exec "$@"
log "** SCRIPT EXIT **"
Binary file added img/configure_codespace.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/create_codespace.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/open_vnc.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions scripts/install-lxqt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Create session config file
apt-get update
apt-get -y --no-install-recommends install lxqt

mkdir -p ~/.config/lxqt/
touch ~/.config/lxqt/session.conf

cat << EOF > ~/.config/lxqt/session.conf
[General]
__userfile__=true
window_manager=xfwm4
EOF
28 changes: 28 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

export KLAYOUT_VER=${KLAYOUT_VER:-0.28.17-1}
export DEBIAN_FRONTEND=noninteractive

apt-get -qqy update
apt-get install -qqy --no-install-recommends git wget ca-certificates

update-ca-certificates
wget https://www.klayout.org/downloads/Ubuntu-22/klayout_${KLAYOUT_VER}_amd64.deb
apt-get install -qqy --no-install-recommends ./klayout_${KLAYOUT_VER}_amd64.deb
rm -rf ./klayout_${KLAYOUT_VER}_amd64.deb

wget https://github.com/YosysHQ/oss-cad-suite-build/releases/download/2024-03-26/oss-cad-suite-linux-x64-20240326.tgz
tar -xvf oss-cad-suite-linux-x64-20240326.tgz
rm -rf oss-cad-suite-linux-x64-20240326.tgz
mkdir -p /opt
mv oss-cad-suite /opt/oss-cad-suite

wget https://github.com/Precision-Innovations/OpenROAD/releases/download/2024-03-25/openroad_2.0_amd64-ubuntu22.04-2024-03-25.deb
apt-get install -qqy --no-install-recommends ./openroad_2.0_amd64-ubuntu22.04-2024-03-25.deb
rm -rf ./openroad_2.0_amd64-ubuntu22.04-2024-03-25.deb

cd ~
git clone https://github.com/The-OpenROAD-Project/OpenROAD-flow-scripts.git

apt-get clean
apt-get autoclean
69 changes: 69 additions & 0 deletions update-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

. ./common.sh

# Attempt to change default shell
chsh -s /bin/bash

# Install Konsole

# apt-get update
# sudoIf apt-get -y install gnome-terminal

# # Update fluxbox config

# fluxbox_apps="$(cat \
# << 'EOF'
# [transient] (role=GtkFileChooserDialog)
# [Dimensions] {100% 100%}
# [Position] (CENTER) {0 0}
# [end]
# EOF
# )"

# echo "${fluxbox_apps}" > ~/.fluxbox/apps

# fluxbox_menu="$(cat \
# << 'EOF'
# [begin] ( Application Menu )
# [exec] (File Manager) { nautilus ~ } <>
# [exec] (Text Editor) { mousepad } <>
# [exec] (Terminal) { gnome-terminal /bin/bash } <>
# [exec] (Web Browser) { x-www-browser --disable-dev-shm-usage } <>
# [submenu] (System) {}
# [exec] (Set Resolution) { tilix -t "Set Resolution" -e bash /usr/local/bin/set-resolution } <>
# [exec] (Edit Application Menu) { mousepad ~/.fluxbox/menu } <>
# [exec] (Passwords and Keys) { seahorse } <>
# [exec] (Top Processes) { tilix -t "Top" -e htop } <>
# [exec] (Disk Utilization) { tilix -t "Disk Utilization" -e ncdu / } <>
# [exec] (Editres) {editres} <>
# [exec] (Xfontsel) {xfontsel} <>
# [exec] (Xkill) {xkill} <>
# [exec] (Xrefresh) {xrefresh} <>
# [end]
# [config] (Configuration)
# [workspaces] (Workspaces)
# [end]
# EOF
# )"

# echo "${fluxbox_menu}" > ~/.fluxbox/menu

# kill_pid tigervncserver
# kill_pid novnc

# ps axjf | grep tigervncserver
# ps axjf | grep novnc

# bash desktop-update.sh

# Create session config file
sudoIf apt-get -y --no-install-recommends install lxqt

cat << EOF > ~/.config/lxqt/session.conf
[General]
__userfile__=true
window_manager=xfwm4
EOF
#

0 comments on commit 0d2b2a0

Please sign in to comment.