Skip to content

Commit 9782a0f

Browse files
committed
refactor(build): unify Dockerfiles and runner script
Replaced separate Fedora and Ubuntu Dockerfiles with a single parameterized Dockerfile using BASE_IMAGE. Removed distro-specific runner scripts and added a unified run.sh supporting both Fedora and Ubuntu via a -d flag. Updated README to reflect new usage. Improved install-node.sh to handle both distros and moved timezone setup into the script for consistency.
1 parent 170c5a9 commit 9782a0f

File tree

8 files changed

+104
-91
lines changed

8 files changed

+104
-91
lines changed

cabal_build_tests/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ARG BASE_IMAGE
2+
FROM ${BASE_IMAGE}
3+
4+
COPY install-node.sh /
5+
RUN chmod +x /install-node.sh
6+
7+
ENTRYPOINT ["./install-node.sh"]

cabal_build_tests/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ The "commit" can be any type of reference, like commit hash, tag or branch name.
1515

1616
### To test cardano-node Cabal build on Ubuntu
1717

18-
`./run-ubuntu.sh -o <cardano-node commit>`
18+
`./run.sh -d ubuntu -o <cardano-node commit>`
1919

2020
### To test cardano-node Cabal build on Fedora
2121

22-
`./run-fedora.sh -o <cardano-node commit>`
22+
`./run.sh -d fedora -o <cardano-node commit>`
2323

2424
If "Success" is shown at the end and the command exits with code 0, then build has completed successfully.

cabal_build_tests/fedora/Dockerfile

Lines changed: 0 additions & 10 deletions
This file was deleted.

cabal_build_tests/install-node.sh

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ CABAL_VERSION="3.12.1.0"
1616
echo ""
1717

1818
if [[ -z "${GIT_OBJECT}" ]]; then
19-
>&2 printf "Please specify 'GIT_OBJECT' on docker run.\ne.g. '-e GIT_OBJECT=10.6.1' for tags, or '-e GIT_OBJECT=78wagy3aw87ef' for commits."
19+
>&2 printf "Please specify 'GIT_OBJECT' on docker run.\ne.g. '-e GIT_OBJECT=10.6.1' for tags, or '-e GIT_OBJECT=78ab9c3a87ef' for commits."
2020
exit 1
2121
fi
2222

@@ -38,30 +38,48 @@ cd ~ || exit 1
3838
# Set up ~/.local/bin
3939
mkdir -p ~/.local/bin || exit 1
4040

41-
if [[ "$PATH" != *"~/.local/bin"* ]]; then
42-
export PATH=~/.local/bin:"$PATH"
41+
if [[ ":${PATH}:" != *":${HOME}/.local/bin:"* ]]; then
42+
export PATH="${HOME}/.local/bin:${PATH}"
4343
else
4444
echo "'PATH' already contains ~/.local/bin"
4545
fi
4646

47-
# Install dependencies
4847

49-
echo "Install dependencies"
48+
# Check OS and install this script's dependencies
49+
distro=""
5050
if [[ "$(</etc/os-release)" == *"fedora"* ]]; then
5151
echo "Running on Fedora"
52-
yum update -y
53-
yum install git gcc gcc-c++ tmux gmp-devel make tar xz wget zlib-devel libtool autoconf -y
54-
yum install systemd-devel ncurses-devel ncurses-compat-libs which jq openssl-devel lmdb-devel -y
52+
distro="fedora"
5553
elif [[ "$(</etc/os-release)" == *"ubuntu"* ]]; then
5654
echo "Running on Ubuntu"
55+
distro="ubuntu"
5756
apt-get update -y
58-
apt-get install automake build-essential pkg-config libffi-dev libgmp-dev libssl-dev libncurses-dev libsystemd-dev zlib1g-dev make g++ tmux git jq wget libtool autoconf liblmdb-dev -y
57+
apt-get install curl -y
5958
else
60-
>&2 echo "/etc/os-relase does not contain 'fedora' or 'ubuntu'"
59+
>&2 echo "/etc/os-release does not contain 'fedora' or 'ubuntu'"
6160
>&2 cat /etc/os-release
6261
exit 1
6362
fi
6463

64+
# Workaround for timezone issues
65+
export TZ=Europe/London
66+
ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime && echo "$TZ" > /etc/timezone
67+
68+
69+
### Checking the actual installation steps ###
70+
71+
# Install dependencies
72+
73+
echo "Install dependencies"
74+
if [[ "$distro" == "fedora" ]]; then
75+
yum update -y
76+
yum install git gcc gcc-c++ tmux gmp-devel make tar xz wget zlib-devel libtool autoconf -y
77+
yum install systemd-devel ncurses-devel ncurses-compat-libs which jq openssl-devel lmdb-devel -y
78+
elif [[ "$distro" == "ubuntu" ]]; then
79+
apt-get update -y
80+
apt-get install automake build-essential pkg-config libffi-dev libgmp-dev libssl-dev libncurses-dev libsystemd-dev zlib1g-dev make g++ tmux git jq wget libtool autoconf liblmdb-dev -y
81+
fi
82+
6583
# Version of iohk-nix
6684
IOHKNIX_VERSION="$(curl "https://raw.githubusercontent.com/IntersectMBO/cardano-node/$GIT_OBJECT/flake.lock" | jq -r '.nodes.iohkNix.locked.rev')"
6785
echo "iohk-nix version: $IOHKNIX_VERSION"

cabal_build_tests/run-fedora.sh

Lines changed: 0 additions & 28 deletions
This file was deleted.

cabal_build_tests/run-ubuntu.sh

Lines changed: 0 additions & 29 deletions
This file was deleted.

cabal_build_tests/run.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
3+
if command -v podman > /dev/null; then
4+
container_manager="podman"
5+
elif command -v docker > /dev/null; then
6+
container_manager="docker"
7+
else
8+
echo "Neither podman nor docker are installed. Please install one of them and try again." >&2
9+
exit 1
10+
fi
11+
12+
GIT_OBJECT=""
13+
DISTRO=""
14+
15+
while getopts "o:d:" flag; do
16+
case "${flag}" in
17+
o) GIT_OBJECT=${OPTARG};;
18+
d) DISTRO=${OPTARG};;
19+
*) echo "Error in command line parsing" >&2
20+
exit 1
21+
;;
22+
esac
23+
done
24+
25+
# Validate required arguments
26+
if [ -z "$GIT_OBJECT" ]; then
27+
echo "Error: -o <git-object> argument is required." >&2
28+
exit 1
29+
fi
30+
31+
# Validate that DISTRO was provided
32+
if [ -z "$DISTRO" ]; then
33+
echo "Error: Missing required -d flag for distro." >&2
34+
exit 1
35+
fi
36+
37+
# Determine correct base image and tag
38+
case "$DISTRO" in
39+
fedora)
40+
BASE_IMAGE="docker.io/library/fedora:latest"
41+
TAG="cardano-node-fedora"
42+
;;
43+
ubuntu)
44+
BASE_IMAGE="docker.io/library/ubuntu:latest"
45+
TAG="cardano-node-ubuntu"
46+
;;
47+
*)
48+
echo "Unsupported distro: $DISTRO. Use 'ubuntu' or 'fedora'." >&2
49+
exit 1
50+
;;
51+
esac
52+
53+
echo "Using base image: $BASE_IMAGE"
54+
echo "Building image: $TAG"
55+
56+
$container_manager build . \
57+
-f Dockerfile \
58+
--build-arg BASE_IMAGE="$BASE_IMAGE" \
59+
-t "$TAG" \
60+
|| exit 1
61+
62+
$container_manager run \
63+
--security-opt label=disable \
64+
-it \
65+
-e GIT_OBJECT="$GIT_OBJECT" \
66+
-e KEEP_RUNNING="${KEEP_RUNNING:-1}" \
67+
"$TAG"

cabal_build_tests/ubuntu/Dockerfile

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)