Fix custom fedora container for ci cd #17

Merged
JMR-dev merged 4 commits from fix-custom-fedora-container-for-ci-cd into develop 2025-10-01 23:59:48 +00:00
2 changed files with 100 additions and 72 deletions
+26 -72
View File
@@ -30,7 +30,7 @@ on:
required: false
default: "false"
pull_request:
branches: [ main ]
branches: [ main, develop ]
permissions:
contents: write
@@ -323,93 +323,47 @@ jobs:
build-rhel:
needs: [run-unit-tests-linux, run-unit-tests-windows]
if: ${{ github.event_name == 'pull_request' || contains(github.event.inputs.jobs, 'build-rhel') }}
permissions:
contents: read
packages: read
env:
DISTRO_TYPE: rhel
runs-on: ubuntu-latest
container:
image: ghcr.io/jmr-dev/android-file-handler-adb:v0.1.0
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch || github.head_ref || github.ref }}
- name: Update OS and install Docker
- name: Build RHEL package
run: |
set -euo pipefail
sudo apt-get update
# Remove possible conflicting containerd packages that can block docker.io installation
sudo apt-get remove -y --purge containerd containerd.io || true
sudo apt-get autoremove -y || true
# Try installing docker.io from distro packages
if ! sudo apt-get install -y --no-install-recommends ca-certificates curl gnupg lsb-release docker.io git build-essential; then
echo "apt install docker.io failed; falling back to Docker convenience script"
# Fallback: use Docker's official convenience script
curl -fsSL https://get.docker.com | sudo sh
fi
sudo usermod -aG docker $USER || true
export CI_CD=true
export DISTRO_TYPE=rhel
poetry install --no-interaction
poetry run python scripts/build_package_linux.py
- name: Pull Fedora container image
run: |
docker pull fedora:latest
- name: Start Fedora container (background) and mount repo
run: |
# Run container with workspace mounted
docker run -d --name rhel-build -v "$PWD":/workspace -w /workspace fedora:latest sleep infinity
- name: Prepare container build environment (dnf, pyenv, python, poetry, fpm)
run: |
set -euo pipefail
# Update the Fedora image and install build deps
docker exec rhel-build bash -lc "dnf -y update && dnf -y install gcc make zlib-devel bzip2 bzip2-devel readline-devel sqlite-devel openssl-devel libffi-devel wget tar git curl ruby rubygems rpm-build redhat-rpm-config gcc-c++ patch which xz-devel"
# Install pyenv into the container (if not present)
docker exec rhel-build bash -lc "[ -d \"/root/.pyenv\" ] || git clone https://github.com/pyenv/pyenv.git /root/.pyenv && mkdir -p /root/.pyenv/plugins && [ -d \"/root/.pyenv/plugins/python-build\" ] || git clone https://github.com/pyenv/pyenv-build.git /root/.pyenv/plugins/python-build"
# Install Python 3.12 via pyenv and set global using explicit pyenv binary path
# Use single quotes so $PYENV_ROOT and $PATH are expanded inside the container's shell
docker exec rhel-build bash -lc 'export PYENV_ROOT="/root/.pyenv"; export PATH="$PYENV_ROOT/bin:$PATH"; /root/.pyenv/bin/pyenv install -s 3.12.0; /root/.pyenv/bin/pyenv global 3.12.0; /root/.pyenv/bin/pyenv rehash'
# Install Poetry inside the container using the official installer (install to /root/.local/bin)
# Use single quotes so PATH is evaluated inside the container shell rather than the runner
docker exec rhel-build bash -lc 'export PATH="/root/.pyenv/shims:/root/.pyenv/bin:$PATH"; curl -sSL https://install.python-poetry.org | python3 - --yes'
# Verify Poetry is available via explicit path if not on PATH
docker exec rhel-build bash -lc "/root/.local/bin/poetry --version || echo 'Poetry not found in /root/.local/bin'"
# Install fpm (Ruby gem) and ensure rpm build tools exist
docker exec rhel-build bash -lc "dnf -y install ruby rubygems make && gem install --no-document -v \"${FPM_VERSION}\" fpm"
- name: Build inside container using Poetry
run: |
set -euo pipefail
# Use poetry inside the container to build package layouts. Use explicit paths so the runner shell
# doesn't expand $HOME; expansion should occur inside the container.
docker exec rhel-build bash -lc 'export PATH="/root/.local/bin:/root/.pyenv/shims:/root/.pyenv/bin:$PATH"; export CI_CD=true; export DISTRO_TYPE=rhel; cd /workspace && /root/.local/bin/poetry install --no-interaction && /root/.local/bin/poetry run python scripts/build_package_linux.py'
- name: Package RHEL (fpm) inside container
- name: Package RHEL (fpm)
shell: bash
run: |
# Run the entire packaging flow inside the Fedora container so Poetry, PATH and arrays are evaluated in-container.
docker exec rhel-build bash -lc '
set -euo pipefail
VERSION="$(/root/.local/bin/poetry version -s)"
PKG_DIR="pkg_dist_rhel"
mkdir -p dist || true
echo "Packaging from $PKG_DIR (version=$VERSION)"
ls -la "$PKG_DIR" || true
set -euo pipefail
VERSION="$(poetry version -s)"
PKG_DIR="pkg_dist_rhel"
mkdir -p dist
echo "Packaging from $PKG_DIR (version=$VERSION)"
ls -la "$PKG_DIR" || true
ICON_PATH="$PKG_DIR/usr/share/icons/hicolor/256x256/apps/android-file-handler.png"
PKG_ITEMS=( "usr/bin/android-file-handler" "usr/share/applications/android-file-handler.desktop" )
if [ -f "$ICON_PATH" ]; then
PKG_ITEMS+=( "usr/share/icons/hicolor/256x256/apps/android-file-handler.png" )
else
echo "Note: icon not present, packaging without icon"
fi
ICON_PATH="$PKG_DIR/usr/share/icons/hicolor/256x256/apps/android-file-handler.png"
PKG_ITEMS=( "usr/bin/android-file-handler" "usr/share/applications/android-file-handler.desktop" )
if [ -f "$ICON_PATH" ]; then
PKG_ITEMS+=( "usr/share/icons/hicolor/256x256/apps/android-file-handler.png" )
else
echo "Note: icon not present, packaging without icon"
fi
# Run fpm inside the container to produce an RPM
cd /workspace
exec fpm -s dir -t rpm -n android-file-handler -v "$VERSION" --architecture x86_64 --prefix /usr/bin --after-install scripts/rhel_postinst.sh -p "dist/android-file-handler-${VERSION}.x86_64.rpm" -C "$PKG_DIR" "${PKG_ITEMS[@]}"
'
fpm -s dir -t rpm -n android-file-handler -v "$VERSION" --architecture x86_64 --prefix /usr/bin --after-install scripts/rhel_postinst.sh -p "dist/android-file-handler-${VERSION}.x86_64.rpm" -C "$PKG_DIR" "${PKG_ITEMS[@]}"
- name: Upload RHEL artifacts
uses: actions/upload-artifact@v4
+74
View File
@@ -0,0 +1,74 @@
# Dockerfile for RHEL/Fedora build environment
# Automates all setup steps from the build-rhel workflow job
#
# Usage:
# docker build -f scripts/docker/Dockerfile.rhel -t android-file-handler-rhel-builder .
# docker run -v $(pwd):/workspace -w /workspace android-file-handler-rhel-builder
FROM fedora:latest
# Set build argument for fpm version (can be overridden at build time)
ARG FPM_VERSION=1.16.0
# Install system dependencies
RUN dnf -y update && \
dnf -y install \
gcc \
make \
zlib-devel \
bzip2 \
bzip2-devel \
readline-devel \
sqlite-devel \
openssl-devel \
libffi-devel \
wget \
tar \
git \
curl \
ruby \
rubygems \
rpm-build \
redhat-rpm-config \
gcc-c++ \
patch \
which \
xz-devel && \
dnf clean all
# Install pyenv
ENV PYENV_ROOT="/root/.pyenv"
ENV PATH="$PYENV_ROOT/bin:$PATH"
RUN git clone https://github.com/pyenv/pyenv.git /root/.pyenv
# Install Python 3.12 via pyenv
RUN eval "$(pyenv init -)" && \
pyenv install 3.12.0 && \
pyenv global 3.12.0 && \
pyenv rehash
# Update PATH to include pyenv shims
ENV PATH="/root/.pyenv/shims:$PATH"
# Install Poetry
RUN curl -sSL https://install.python-poetry.org | python3 - --yes
# Add Poetry to PATH
ENV PATH="/root/.local/bin:$PATH"
# Verify Poetry installation
RUN poetry --version
# Install fpm
RUN gem install --no-document -v "${FPM_VERSION}" fpm
# Set working directory
WORKDIR /workspace
# Set environment variables for build
ENV CI_CD=true
ENV DISTRO_TYPE=rhel
# Default command runs the build script
CMD ["sh", "-c", "poetry install --no-interaction && poetry run python scripts/build_package_linux.py"]