Skip to content

Commit

Permalink
Alicanto, workflow, and modelHooks updates (#14)
Browse files Browse the repository at this point in the history
* workflow, alicanto, and bennu-simulink-provider updates

* Fixed error in setup.py and commented out gobennu install
  • Loading branch information
rfasano authored Nov 8, 2023
1 parent 5252036 commit ba5a43c
Show file tree
Hide file tree
Showing 15 changed files with 1,436 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Docker Image CI

on:
push:
branches: [ "main", "**" ]

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: docker build . --file Dockerfile --tag sceptre-bennu:$(date +%s)
48 changes: 48 additions & 0 deletions .github/workflows/publish-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Create and publish a Docker image

# Configures this workflow to run every time a change is pushed to the branch called `release`.
on:
push:
branches: ['**']

# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
build-and-push-image:
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
#
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

107 changes: 107 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# create python build image
FROM ubuntu:20.04 AS pybuilder

ENV DEBIAN_FRONTEND noninteractive

RUN apt update \
&& apt install -y \
build-essential cmake git wget python3-dev python3-pip \
libfreetype6-dev liblapack-dev libboost-dev \
&& rm -rf /var/lib/apt/lists/*

# setup ZMQ
ENV ZMQ_VERSION 4.3.4
RUN wget -O zmq.tgz https://github.com/zeromq/libzmq/releases/download/v4.3.4/zeromq-4.3.4.tar.gz \
&& mkdir -p /tmp/zmq \
&& tar -C /tmp/zmq -xvzf zmq.tgz \
&& rm zmq.tgz \
&& cd /tmp/zmq/zeromq-${ZMQ_VERSION} \
&& ./configure --enable-drafts \
&& make -j$(nproc) install

# setup Helics (needed for pybennu)
ENV HELICS_VERSION 2.7.1
RUN wget -O helics.tgz https://github.com/GMLC-TDC/HELICS/releases/download/v${HELICS_VERSION}/Helics-v${HELICS_VERSION}-source.tar.gz \
&& mkdir -p /tmp/helics \
&& tar -C /tmp/helics -xzf helics.tgz \
&& rm helics.tgz \
&& mkdir -p /tmp/helics/build && cd /tmp/helics/build \
&& cmake -D HELICS_USE_SYSTEM_ZEROMQ_ONLY=ON .. \
&& make -j$(nproc) install

RUN python3 -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org pyzmq~=20.0.0 --install-option=--enable-drafts

RUN wget -O pyhelics.tgz https://github.com/GMLC-TDC/pyhelics/releases/download/v${HELICS_VERSION}/helics-${HELICS_VERSION}.tar.gz \
&& mkdir -p /tmp/pyhelics \
&& tar -C /tmp/pyhelics -xzf pyhelics.tgz \
&& rm pyhelics.tgz \
&& cd /tmp/pyhelics/helics-${HELICS_VERSION} \
&& sed -i 's/helics-apps/helics-apps~=2.7.1/' setup.py \
&& python3 -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org .

#DEBUG build
#ADD docker/vendor /tmp/bennu/vendor
#WORKDIR /tmp/bennu/vendor/helics-helper
#RUN python3 -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org .

# install Python bennu package
ADD src/pybennu /tmp/bennu/src/pybennu
WORKDIR /tmp/bennu/src/pybennu
RUN python3 -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org .

# create final image
FROM ubuntu:20.04

ENV DEBIAN_FRONTEND noninteractive

RUN apt update \
&& apt install -y \
# bennu
build-essential ca-certificates cmake cmake-curses-gui \
git wget pkg-config libasio-dev libsodium-dev \
libboost-system-dev libboost-filesystem-dev \
libboost-thread-dev libboost-serialization-dev \
libboost-date-time-dev libboost-program-options-dev \
libboost-iostreams-dev libsodium23 libfreetype6 \
liblapack3 libzmq5-dev \
# fpm
libffi-dev ruby-dev ruby-ffi \
# python
python3-dev python3-pip python3-setuptools python3-wheel \
&& rm -rf /var/lib/apt/lists/*

# setup Go
#ENV GOLANG_VERSION 1.16.5
#RUN wget -O go.tgz https://golang.org/dl/go${GOLANG_VERSION}.linux-amd64.tar.gz \
# && tar -C /usr/local -xzf go.tgz && rm go.tgz
#ENV GOPATH /go
#ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH

# copy over custom-built libraries
COPY --from=pybuilder /usr/local /usr/local
ENV LD_LIBRARY_PATH /usr/local/lib:/usr/local/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH}

# copy over bennu source code
ADD cmake /tmp/bennu/cmake
ADD CMakeLists.txt /tmp/bennu/CMakeLists.txt
ADD src/bennu /tmp/bennu/src/bennu
ADD src/deps /tmp/bennu/src/deps
#ADD src/gobennu /tmp/bennu/src/gobennu
ADD test /tmp/bennu/test

#set necessary vars
#ENV GOPROXY "http://proxy.golang.org"
#ENV GONOSUMDB "proxy.golang.org/*,github.com,github.com/*,gopkg.in,gopkg.in/*,golang.org/*,golang.org"
#ENV GOPRIVACY "proxy.golang.org/*,github.com,github.com/*,gopkg.in,gopkg.in/*,golang.org/*,golang.org"
#ENV GOINSECURE "proxy.golang.org/*,github.com,github.com/*,gopkg.in,gopkg.in/*,golang.org/*,golang.org"

# install C++ and Golang bennu package
WORKDIR /tmp/bennu/build
RUN cmake -D BUILD_GOBENNU=OFF ../ && make -j$(nproc) install \
&& rm -rf /tmp/*

RUN gem install fpm
RUN pip3 install --trusted-host pypy.org --trusted-host files.pythonhosted.org -U aptly-ctl pip setuptools twine wheel

WORKDIR /root
CMD /bin/bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# TODO: make this script take as input the .slx to build

if [ $# -ne 1 ]; then
echo "Usage: ./bulid processModle.slx"
exit
fi

fullfile=$(basename -- "$1");
echo $fullfile

filename="${fullfile%.*}";
echo $filename;

extension="${fullfile##*.}";
echo $extension;

buildfolder="${filename}_grt_rtw"
echo $buildfolder


if [ $extension != "slx" ]; then
echo "Must supply a .slx file"
exit
fi

# FYI: the model name is case sensitive
modelname=$filename
echo $modelname

apifile="${buildfolder}/${modelname}_capi.c"
echo $apifile

command -v matlab 2>&1 > /dev/null;
if [ $? -eq 0 ]; then
echo "matlab is installed, proceeding to build Simulink process model..."
# TODO: Research if there is the ability to hook the code from the command line
matlab -nojvm -nodisplay -nodesktop -r "warning off; rtwbuild('${modelname}'); quit();"
else
echo "matlab not installed, skipping Simulink process model build..."
fi

# mv inputs.txt inputs.bak
# mv outputs.txt outputs.bak
#
# # TODO: Make sure this still works with other solvers
# cat $apifile \
# | cut -d\" -f2 \
# | cut -d\/ -f3 \
# | cut -d" " -f2 \
# | grep -Ev "^(sim)" \
# | grep -E "(_AI|_DI)" \
# | sort \
# | uniq \
# >> inputs.txt \
# ;
#
# cat $apifile \
# | cut -d\" -f2 \
# | cut -d\/ -f3 \
# | grep -Ev "(sim|Scale)" \
# | grep -E "(_AO|_DO)" \
# | sort \
# | uniq \
# >> outputs.txt \
# ;
#
# cat $apifile \
# | cut -d\" -f2 \
# | cut -d\/ -f3 \
# | cut -d" " -f2 \
# | grep -Ev "^(sim)" \
# | grep -E "(_PANEL)" \
# | sort \
# | uniq \
# >> outputs.txt \
# ;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
for filepath in ./*.slx; do
# set required variables
#echo $filepath;
fullfile=$(basename -- "$filepath");
#echo $fullfile;
filename="${fullfile%.*}";
#echo $filename;
extension="${fullfile##*.}";
#echo $extension;
buildfolder="$filename""_grt_rtw"
#echo $buildfolder

# rm build folders
rm -rf $buildfolder
rm -rf slprj

# rm extra files
if [ -f "${filename}.slxc" ]; then
rm "${filename}.slxc"
fi

if [ -f "${filename}.mat" ]; then
rm "${filename}.mat"
fi

# rm binary file
if [ -f $filename ]; then
rm $filename
fi
done;

Loading

0 comments on commit ba5a43c

Please sign in to comment.