# Use a base image suitable for OpenBMC
FROM ubuntu:24.04

# Install necessary dependencies for OpenBMC
RUN apt-get update && apt-get install -y \
    git \
    build-essential \
    cmake \
    qemu-system \
    bash \
    locales \
    chrpath \
    cpio \
    diffstat \
    file \
    gawk \
    lz4 \
    wget \
    zstd \
    && rm -rf /var/lib/apt/lists/*

RUN mkdir -p /opt/openbmc
RUN chown 65534 /opt/openbmc
# Set up locale
RUN locale-gen en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8

USER 65534

# Set working directory
WORKDIR /opt/openbmc


# Clone OpenBMC repository
RUN git clone https://github.com/openbmc/openbmc.git /opt/openbmc

# Set the shell to bash so we can have nice things like `source`
SHELL ["/bin/bash", "-c"]


# Copy and configure local.conf
RUN TEMPLATECONF=meta-phosphor/conf/templates/default source oe-init-build-env build

# Build OpenBMC
RUN TEMPLATECONF=meta-phosphor/conf/templates/default . ./openbmc-env && bitbake obmc-phosphor-image

# Expose necessary ports (e.g., SSH, IPMI)
EXPOSE 22 623

# Start the OpenBMC service (example command, adjust as needed)
CMD ["bash", "-c", "qemu-system-arm -m 256 -M palmetto-bmc -nographic -drive file=obmc-phosphor-image-palmetto.ext4,format=raw -net nic -net user,hostfwd=tcp::2222-:22"]: