Skip to content

Commit 489e93b

Browse files
Cross platform tool env support
Signed-off-by: Weber (US), Matthew L <matthew.l.weber3@boeing.com>
1 parent 3e570f9 commit 489e93b

5 files changed

Lines changed: 97 additions & 76 deletions

File tree

demos/copilot/src/monitors/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# License: SPDX-License-Identifier: MIT
22

3-
CONTAINER_IMG = registry.gitlab.com/elisa-tech/aero-wg-ci/copilot:latest
3+
CONTAINER_IMG = registry.gitlab.com/elisa-tech/aero-wg-ci/copilot:2249410795
44
CONTAINER_ARGS = -e HOST_UID="$(shell id -u)" -e HOST_GID="$(shell id -g)" -v $(PWD)/../:/demo
55
CONTAINER_TEST_ARGS = -e HOST_UID="$(shell id -u)" -e HOST_GID="$(shell id -g)" -v $(PWD)/../../../:/demo
66

@@ -11,8 +11,8 @@ RUN_IT_PREFIX := $(if $(shell mount | grep -q 'xfs' && echo 1),,docker run --rm
1111
DEMO_CHDIR := $(if $(shell mount | grep -q 'xfs' && echo 1),,cd /demo/monitors &&)
1212
DEMO_CHDIR_TEST := $(if $(shell mount | grep -q 'xfs' && echo 1),,cd /demo/copilot/src/monitors &&)
1313

14-
CMD_PREFIX := $(if $(shell mount | grep -q 'xfs' && echo 1),,$(DEMO_CHDIR) export "PATH=$$PATH:/opt/ghc/8.6.5/bin/" &&)
15-
CMD_PREFIX_TEST := $(if $(shell mount | grep -q 'xfs' && echo 1),,$(DEMO_CHDIR_TEST) export "PATH=$$PATH:/opt/ghc/8.6.5/bin/" &&)
14+
CMD_PREFIX := $(if $(shell mount | grep -q 'xfs' && echo 1),,$(DEMO_CHDIR) export "PATH=$$PATH:/home/user/.local/bin/:/home/user/.cabal/bin:/opt/.ghcup/bin" &&)
15+
CMD_PREFIX_TEST := $(if $(shell mount | grep -q 'xfs' && echo 1),,$(DEMO_CHDIR_TEST) export "PATH=$$PATH:/home/user/.local/bin/:/home/user/.cabal/bin:/opt/.ghcup/bin" &&)
1616

1717
# TODO add CICD adjustments to prefix and when detecting that we're running inside a container (for the `make dev` case)
1818

Lines changed: 71 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
#
33
# Dockerfile to install Copilot and make it available to the user
44
#
5-
#
6-
# This file is specific to versions of Ubuntu strictly before 23.04. After that
7-
# version, Copilot became included in Ubuntu as a package.
5+
# This file is designed to support a Docker Build on both AMD64 and ARM64
6+
# systems. As a result, some items are built from source instead of prebuilts.
87
#
98
FROM ubuntu:focal
109

@@ -14,7 +13,7 @@ ENV DEBIAN_FRONTEND=noninteractive
1413
# Install dependencies
1514
RUN apt-get update && \
1615
apt-get upgrade -y && \
17-
apt-get install -y \
16+
apt-get install -y --no-install-recommends \
1817
build-essential \
1918
cpio \
2019
git \
@@ -33,37 +32,52 @@ RUN apt-get update && \
3332
&& \
3433
apt-get -y autoremove && \
3534
apt-get -y clean && \
36-
rm -rf /var/lib/apt/lists/*
35+
rm -rf /var/lib/apt/lists/* /usr/share/{icons,alsa,AAVMF,ovmf,fonts,vim,mime,X11,i18n,man,doc}
3736

38-
# Install Copilot dependencies
37+
# Build Haskell env from source
38+
ENV BOOTSTRAP_HASKELL_NONINTERACTIVE=1
39+
ENV BOOTSTRAP_HASKELL_VERBOSE=1
40+
ENV BOOTSTRAP_HASKELL_GHC_VERSION=8.6.5
41+
ENV GHCUP_INSTALL_BASE_PREFIX=/opt
3942
RUN apt-get update && \
4043
apt-get install -y \
4144
alex \
45+
curl \
4246
happy \
4347
libbz2-dev \
4448
libexpat-dev \
49+
libncurses-dev \
50+
libtinfo5 \
4551
libz-dev \
4652
pkg-config \
4753
software-properties-common \
4854
&& \
49-
apt-get -y autoremove && \
50-
apt-get -y clean && \
51-
rm -rf /var/lib/apt/lists/*
52-
RUN add-apt-repository ppa:hvr/ghc && \
53-
apt-get update && \
54-
apt-get install -y \
55-
ghc-8.6.5 \
56-
cabal-install-2.4 \
55+
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh && \
56+
ls /opt/.ghcup/bin && /opt/.ghcup/bin/ghcup gc --cache && \
57+
rm -rf /root/.cabal/packages/* /opt/.ghcup/cache/ghc-8.6.5-a /opt/.ghcup/cache/stack* && \
58+
. /opt/.ghcup/env && \
59+
cabal clean && \
60+
echo 'source /opt/.ghcup/env' >> /root/.bashrc && \
61+
apt-get remove -y \
62+
alex \
63+
curl \
64+
happy \
65+
libbz2-dev \
66+
libexpat-dev \
67+
libncurses-dev \
68+
libz-dev \
69+
pkg-config \
70+
software-properties-common \
5771
&& \
5872
apt-get -y autoremove && \
5973
apt-get -y clean && \
6074
rm -rf /var/lib/apt/lists/*
61-
75+
6276
# To be able to generate a toolchain with locales, enable one UTF-8 locale
6377
RUN sed -i 's/# \(en_US.UTF-8\)/\1/' /etc/locale.gen && \
6478
/usr/sbin/locale-gen
6579

66-
# Pass environment variables during build
80+
# Pass environment variables during a build to represent a version
6781
ARG CI_COMMIT_SHA="Local"
6882
ARG CI_PIPELINE_URL="Local"
6983
ARG DOCKERFILE_AUTHOR="Local"
@@ -86,34 +100,59 @@ RUN echo "Creation Date: $(date -u +'%Y-%m-%dT%H:%M:%SZ')" > /.VERSION && \
86100
RUN useradd -ms /bin/bash user
87101
RUN echo "user ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/user \
88102
&& chmod 0440 /etc/sudoers.d/user
89-
RUN echo 'export PATH=/opt/ghc/8.6.5/bin:/opt/cabal/2.4/bin:/home/user/.cabal/bin/:$PATH' >> /home/user/.bashrc && \
103+
RUN echo 'source /opt/.ghcup/env' >> /home/user/.bashrc && \
90104
chown -R user:user /home/user
91-
# Transparent uid:gid setup for manual container use
92-
COPY entry.sh /entry.sh
93-
RUN chmod 777 /entry.sh && chown root:root /entry.sh
94105
USER user
95106
WORKDIR /home/user
96107

97-
# Install Copilot
98-
ENV PATH=/opt/ghc/8.6.5/bin:/opt/cabal/2.4/bin:/home/user/.cabal/bin/:$PATH
99-
RUN cabal v2-update
100-
RUN cabal v2-install --lib \
108+
# Install Copilot - cabal was stable on a small ARM machine with extra args setting limits
109+
# e.g., --jobs=1 --ghc-options="+RTS -M200M -RTS"
110+
RUN sudo apt-get update && \
111+
sudo apt-get install -y \
112+
clang \
113+
libbz2-dev \
114+
libgmp-dev \
115+
lld \
116+
lldb \
117+
llvm \
118+
&& \
119+
. /opt/.ghcup/env && \
120+
cabal v2-update && \
121+
cabal v2-install --lib \
101122
copilot-4.5.1 \
102123
copilot-c99-4.5.1 \
103124
copilot-interpreter-4.5.1 \
104125
copilot-language-4.5.1 \
105126
copilot-libraries-4.5.1 \
106-
copilot-theorem-4.5.1
107-
108-
# Install Ogma
109-
RUN cd && \
127+
copilot-theorem-4.5.1 && \
110128
git clone https://github.com/nasa/ogma.git && \
111129
cd ogma && \
112130
cabal v2-install ogma-cli:ogma && \
113-
cd && \
114-
rm -rf ogma
131+
echo 'export PATH=$HOME/.local/bin/:$PATH' >> /home/user/.bashrc && \
132+
cd .. && \
133+
rm -rf ogma && \
134+
cabal clean && \
135+
rm -rf ~/.cache/cabal/packages/* && \
136+
sudo apt-get remove -y \
137+
clang \
138+
lld \
139+
lldb \
140+
llvm \
141+
&& \
142+
sudo apt-get -y autoremove && \
143+
sudo apt-get -y clean && \
144+
sudo rm -rf /var/lib/apt/lists/*
145+
146+
ENV PATH=/home/user/.local/bin/:$PATH
115147

116-
# Check that tools seem to run
117-
RUN ghci --version && ogma --help
148+
# Check that tools seem to run as normal user
149+
RUN . /opt/.ghcup/env && \
150+
ghci --version && \
151+
cabal --version && \
152+
ogma --help
153+
154+
# Transparent uid:gid setup for manual container use
155+
COPY entry.sh /entry.sh
156+
RUN sudo chmod 777 /entry.sh && sudo chown root:root /entry.sh
118157

119158
ENTRYPOINT ["/entry.sh"]

demos/env/Readme.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Environment building notes
2+
3+
## Development
4+
5+
- Make sure to lint `docker run --rm -i hadolint/hadolint < Dockerfile`
6+
- If storage gets full, prune the Docker system `docker system prune -f -a`
7+
8+
### ARM
9+
10+
- Used a ARM64 host from AWS and Ubuntu 24.x
11+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ if [[ ! -z "$HOST_UID" ]]; then
1818
sudo cp -a /home/user/* \
1919
/home/user/.bash* \
2020
/home/user/.cabal \
21+
/home/user/.local \
2122
/home/user/.ghc* \
2223
/home/user/.profile \
2324
/home/$NON_ROOT_USER/

demos/env/setup-env.sh

100644100755
Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ if [[ "$EUID" -eq 0 ]]; then
66
exit 1
77
fi
88
# Check if the script is running on amd64 architecture
9-
if [[ "$(uname -m)" != "x86_64" ]]; then
10-
echo "This script requires an amd64 architecture."
11-
echo " NOTE, this is because the container env and toolchain are build for x86_64 hosts."
12-
exit 1
13-
fi
9+
#if [[ "$(uname -m)" != "x86_64" ]]; then
10+
# echo "This script requires an amd64 architecture."
11+
# echo " NOTE, this is because the container env and toolchain are build for x86_64 hosts."
12+
# exit 1
13+
#fi
1414

1515
# Check if sudo works
1616
if ! sudo -n true 2> /dev/null; then
@@ -20,45 +20,15 @@ fi
2020

2121
echo "Installing prerequisites ..."
2222
{
23-
sudo rm /etc/apt/sources.list.d/docker.list -f #remove prior Docker apt repository
2423
sudo apt-get update &&
25-
sudo apt-get install -y make ca-certificates passwd curl wslu iptables
24+
sudo apt-get install -y docker.io make ca-certificates passwd curl wslu iptables
2625
} || {
2726
echo "Failed to setup Docker prerequisites"
2827
exit 1
2928
}
3029

31-
if ! command -v /usr/bin/docker &> /dev/null; then
32-
# Get Docker pkgs
33-
{
34-
wget https://download.docker.com/linux/ubuntu/dists/noble/pool/stable/amd64/containerd.io_1.7.25-1_amd64.deb
35-
wget https://download.docker.com/linux/ubuntu/dists/noble/pool/stable/amd64/docker-buildx-plugin_0.21.1-1~ubuntu.24.04~noble_amd64.deb
36-
wget https://download.docker.com/linux/ubuntu/dists/noble/pool/stable/amd64/docker-ce-cli_28.0.1-1~ubuntu.24.04~noble_amd64.deb
37-
wget https://download.docker.com/linux/ubuntu/dists/noble/pool/stable/amd64/docker-ce_28.0.1-1~ubuntu.24.04~noble_amd64.deb
38-
wget https://download.docker.com/linux/ubuntu/dists/noble/pool/stable/amd64/docker-compose-plugin_2.33.1-1~ubuntu.24.04~noble_amd64.deb
39-
} || {
40-
echo "Failed to download docker pkgs"
41-
exit 1
42-
}
43-
44-
# Install Docker packages
45-
{
46-
# If something goes wrong, here's the command to undo these installs
47-
# sudo dpkg -r containerd.io docker-buildx-plugin docker-ce docker-ce-cli docker-compose-plugin
48-
sudo dpkg -i ./containerd* \
49-
./docker-ce_* \
50-
./docker-ce-cli_* \
51-
./docker-buildx-plugin_* \
52-
./docker-compose-plugin_*
53-
rm docker-* containerd* -f
54-
} || {
55-
echo "Failed to install Docker packages"
56-
exit 1
57-
}
58-
59-
# Setup user permissions. Ensure the actual user (not root) is used when the script is run with sudo initially to install docker
60-
sudo usermod -aG docker "${SUDO_USER:-$USER}" || {
61-
echo "Failed to configure user permissions"
62-
exit 1
63-
}
64-
fi
30+
# Setup user permissions. Ensure the actual user (not root) is used when the script is run with sudo initially to install docker
31+
sudo usermod -aG docker "${SUDO_USER:-$USER}" || {
32+
echo "Failed to configure user permissions"
33+
exit 1
34+
}

0 commit comments

Comments
 (0)