From fcd2aae2594db58a2f669ae416e12e7edfaecf00 Mon Sep 17 00:00:00 2001 From: David Allen Date: Tue, 16 Jul 2024 15:53:57 -0600 Subject: [PATCH] Added emulator for testing with docker/compose --- emulator/Dockerfile | 53 ++++++++++++++++++++++++++++++++++++++++ emulator/rf-emulator.yml | 26 ++++++++++++++++++++ emulator/setup.sh | 12 +++++++++ 3 files changed, 91 insertions(+) create mode 100644 emulator/Dockerfile create mode 100644 emulator/rf-emulator.yml create mode 100755 emulator/setup.sh diff --git a/emulator/Dockerfile b/emulator/Dockerfile new file mode 100644 index 0000000..0db9b3a --- /dev/null +++ b/emulator/Dockerfile @@ -0,0 +1,53 @@ +FROM alpine:latest as base + +COPY src/requirements.txt /app/requirements.txt + +USER root + +RUN apk -U upgrade +RUN apk add --no-cache tini bash +RUN apk add --no-cache --update \ + build-base \ + python3 \ + python3-dev \ + py3-pip \ + openssl \ + openssl-dev \ + libffi-dev \ + gcc \ + musl-dev \ + cargo \ + curl \ + --force-missing-repositories + +# added python venv for MacOS builds with brew +RUN python3 -m venv ./env \ + && chmod 777 -R ./env \ + && ./env/bin/activate +RUN ./env/bin/python3 -m pip install --upgrade \ + pip \ + setuptools \ + && ./env/bin/python3 -m pip install wheel \ + && ./env/bin/python3 -m pip install -r /app/requirements.txt +RUN apk del \ + build-base \ + gcc \ + python3-dev \ + openssl-dev \ + libffi-dev \ + musl-dev \ + cargo + +# Insert our emulator extentions +COPY src /app +COPY mockups /app/api_emulator/redfish/static + +EXPOSE 5000 +ENV MOCKUPFOLDER="public-rackmount1" +ENV AUTH_CONFIG="" +ENV PORT=5000 +ENV XNAME="x3000c0s0b0" +ENV MAC_SCHEMA="" +WORKDIR /app +ENTRYPOINT ["/env/bin/python3"] +CMD ["emulator.py"] \ No newline at end of file diff --git a/emulator/rf-emulator.yml b/emulator/rf-emulator.yml new file mode 100644 index 0000000..f996e9f --- /dev/null +++ b/emulator/rf-emulator.yml @@ -0,0 +1,26 @@ +networks: + internal: + +volumes: + emulator: + +services: + emulator: + image: openchami-rie:latest + container_name: rf-emulator + environment: + BMC_PORT: 5000 + MOCKUPFOLDER: EX235a + AUTH_CONFIG: "root:root_password:Administrator" + volumes: + - ./rf-emulator/mockups:/mockups + ports: + - 5000:443 + networks: + - internal + healthcheck: + test: ["CMD", "curl", "--fail", "--silent", "http://127.0.0.1:5000"] + interval: 5s + timeout: 10s + retries: 10 + diff --git a/emulator/setup.sh b/emulator/setup.sh new file mode 100755 index 0000000..8ca9580 --- /dev/null +++ b/emulator/setup.sh @@ -0,0 +1,12 @@ +#/bin/sh + +script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +# clone the CSM redfish emulator if needed +if [ ! -d ${script_dir}/rf-emulator ]; then + git clone https://github.com/Cray-HPE/csm-redfish-interface-emulator ${script_dir}/rf-emulator +fi + +# build docker image and run with docker compose +docker build -t openchami-rie:latest -f ${script_dir}/Dockerfile ${script_dir}/rf-emulator +docker compose -f ${script_dir}/rf-emulator.yml up