Skip to content

Commit

Permalink
BDW & GUI support inside the docker image.
Browse files Browse the repository at this point in the history
  • Loading branch information
benycze committed Apr 11, 2021
1 parent 0bc65e8 commit 046be66
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 120 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
bsc
bsc-contrib
doc
scripts/reps
5 changes: 2 additions & 3 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ blocks:
- sudo swapon /swapfile
#Translate the project
- checkout
- bash bootstrap.sh
- docker build -t localhost/bsc-compiler .
- cd scripts && bash bootstrap.sh && cd ..
- docker build --build-arg USER=$USER --build-arg UID=`id -u` --build-arg `id -g` -t localhost/bsc-compiler .
- docker run -w /bluespec/bsc localhost/bsc-compiler /bin/bash -c "cd examples/smoke_test && make smoke_test"

33 changes: 26 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,33 @@
#
# Author(s): Pavel Benacek <[email protected]>

FROM ubuntu:18.04
FROM ubuntu:20.04

# Defeault argument values
ARG BJOBS=1
COPY bsc /bluespec/bsc
COPY build-new-package.sh /bluespec
COPY bsc-contrib /bluespec/bsc-contrib
COPY doc /bluespec/doc
ARG USER=user
ARG UID=1000
ARG GID=1000
ARG PASS=password

RUN apt update && apt upgrade -y && DEBIAN_FRONTEND=noninteractive apt install -y tzdata sudo vim software-properties-common
# Copy downloaded repos
COPY scripts/reps/bsc /bluespec/bsc
COPY scripts/reps/bsc-contrib /bluespec/bsc-contrib
COPY scripts/reps/doc /bluespec/doc
COPY scripts/reps/bdw /bluespec/bdw
COPY scripts/build-new-package.sh /bluespec

# Install tooling a
RUN apt update && apt upgrade -y && \
DEBIAN_FRONTEND=noninteractive apt install -y tzdata sudo vim software-properties-common \
sudo xauth vim-gtk graphviz
RUN add-apt-repository universe && apt update && apt upgrade -y
RUN cd /bluespec && bash ./build-new-package.sh 1.0.0 1.0.0 $BJOBS

# Add user into the system
RUN groupadd --gid $GID $USER && \
useradd --uid $UID --gid $GID --groups sudo --shell /bin/bash -m $USER && \
echo "$USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/admins && \
echo "$USER:$PASS" | chpasswd

# Build Bluespec tools
RUN cd /bluespec && bash ./build-new-package.sh 1.0.0 1.0.0 1.0.0 $BJOBS
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ This repository contains a prepared build script of Bluespec compiler for the Do

The only thing you need is to install the [Docker](https://www.docker.com/) or [Podman](https://podman.io/) (use the Podman tool because it is much better ;)).

The image contains elementary development tools, [Bluespec compiler](https://github.com/B-Lang-org/bsc), [Bluespec documentation and examples](https://github.com/BSVLang/Main.git) and [Bluespec contribution library](https://github.com/B-Lang-org/bsc-contrib).
The image contains elementary development tools, [Bluespec compiler](https://github.com/B-Lang-org/bsc), [Bluespec documentation and examples](https://github.com/BSVLang/Main.git), [Bluespec contribution library](https://github.com/B-Lang-org/bsc-contrib) and [BSC Development Workstation](https://github.com/B-Lang-org/bdw).

## How to download and build the image

Clone the repository using this command (gets all dependencies):

```bash
git clone https://github.com/benycze/bsc-docker-container
bash bootstrap.sh
cd scripts
bootstrap.sh
```

If you need a specific version or update to fresh master you can do it on your own. Update everything to fresh master branches (in the case that you used the `boostrap.sh` file earlier):
Expand All @@ -35,12 +36,13 @@ git checkout devel
The image is then built quite easily (the following example is for docker but you can use the same command using the [podman](https://podman.io/) tool):

```bash
docker build -t localhost/bsc-compiler --build-arg BJOBS=4 .
docker build -t localhost/bsc-compiler --build-arg BJOBS=4 --build-arg USER=$USER --build-arg UID=`id -u` --build-arg `id -g` .
```

This command builds the image named localhost/bsc-compiler and it also uses 4 jobs to build the tool. You can also adjust the BJOBS if you need to use less or more CPU cores to build the image. Image for docker is built using the `build-image.sh`.
Variables UID, USER and GID are used for the creation of local account with admin rights via the `sudo` tool.

## How to run the image
## How to run the image (just a console)

The following command can be used to runt the image and mount the local working directory.

Expand All @@ -53,3 +55,28 @@ This command will do the following:
* Starts the container from the localhost/bsc-compiler image
* Mounts the local /home/user/bsc-work directory into /bsc-work directory inside the image
* Starts the container and attach the console

In a case that you want to run the image using a normal account:

```bash
docker run --user=$USER --rm -t -i --mount=type=bind,source=/home/user/bsc-work,destination=/bsc-work localhost/bsc-compiler bash
```

## How to run the X11 App

The image also contains the Bluespec Development Workstation together with possibility to run X11 apps
on your X window system. Basically you need export your local XAuthority variable and X11 socket from
your system into the container (detailed explemention [here](https://blog.artis3nal.com/2020-09-13-container-gui-app-pgmodeler/))

Check your environment for these variables:
* XAUTHORITY (if not defined run the `export XAUTHORITY=$(xauth info | grep "Authority file" | awk '{ print $3 }')` command)
* DISPLAY (this should be defined :-))

After that, run the following command with docker:

```bash
docker run --rm -t -i -e DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix:ro -v $XAUTHORITY:$XAUTHORITY:ro --user=$USER --mount=type=bind,source=/home/user/bsc-work,destination=/bsc-work localhost/bsc-compiler /bin/bash
```

You should be fine to run the graphic app from the container image (you can check it using the `gvim`).
The example of image start script is inside the `run-example` folder.
5 changes: 3 additions & 2 deletions build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ echo "Cleaning the folder ..."
git clean -d -f -f -x .

echo "Downloading all folders ..."
bash bootstrap.sh
cd scripts && bash bootstrap.sh && cd ..

echo "Building the Bluespec docker image ..."
docker build -t localhost/bsc-compiler --build-arg BJOBS=4 .
docker build -t localhost/bsc-compiler --build-arg BJOBS=4 --build-arg USER=$USER \
--build-arg UID=`id -u` --build-arg `id -g` .

echo "Done!"
100 changes: 0 additions & 100 deletions build-new-package.sh

This file was deleted.

14 changes: 14 additions & 0 deletions run-example/start-bsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
# Copyright 2019 by the bsc docker image contributors
# SPDX-License-Identifier: GPL-3.0-only
#
# Author(s): Pavel Benacek <[email protected]>

#
# This file can be used as the initial template for your own start-up file.
# Fill the mount folder using the:
# --mount=type=bind,source=/home/user/bsc-work,destination=/bsc-work

docker run --rm -t -i -e DISPLAY \
-v /tmp/.X11-unix/:/tmp/.X11-unix:ro -v $XAUTHORITY:$XAUTHORITY:ro \
--user=$USER localhost/bsc-compiler /bin/bash
6 changes: 5 additions & 1 deletion bootstrap.sh → scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
#
# Author(s): Pavel Benacek <[email protected]>

DOWNLOAD_PATH=`pwd`/reps

echo "Preparing all directories ..."

mkdir -p $DOWNLOAD_PATH && cd $DOWNLOAD_PATH

git clone --recursive https://github.com/B-Lang-org/bsc.git bsc
git clone --recursive https://github.com/B-Lang-org/bsc-contrib bsc-contrib
git clone --recursive https://github.com/BSVLang/Main.git doc
git clone --recursive https://github.com/B-Lang-org/bdw

echo "Done!"
echo "Reps downloaded"
Loading

0 comments on commit 046be66

Please sign in to comment.