Skip to content

Commit

Permalink
Added production parameter recognition feature (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
Murat Ursavas committed Jan 28, 2023
1 parent 4b0e204 commit f41a38e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .hadolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignored:
- SC1091
22 changes: 15 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ WORKDIR /tmp/build
RUN \
install_packages \
build-essential \
libdbus-glib-1-dev

RUN pip3 install --no-cache-dir --target="$PYTHON_DEPENDENCIES_DIR" .
libdbus-glib-1-dev && \
pip3 install --no-cache-dir --target="$PYTHON_DEPENDENCIES_DIR" .

# firehose build, the tar is obtained from quectel.
# there is no install target in Makefile, doing manual copy
Expand Down Expand Up @@ -48,8 +47,6 @@ WORKDIR /opt/

# Import gpg key
COPY keys/manufacturing-key.gpg ./
RUN gpg --import manufacturing-key.gpg
RUN rm manufacturing-key.gpg

# @TODO: Re-enable health-check once Balena supports it fully.
# HEALTHCHECK \
Expand All @@ -74,10 +71,21 @@ COPY --from=builder /tmp/build/alembic.ini /opt/migrations/alembic.ini

# copy start admin session script
COPY --from=builder /tmp/build/start_admin_session /usr/sbin/start_admin_session
RUN chmod 700 /usr/sbin/start_admin_session

# Getting RUN layers together
RUN gpg --import manufacturing-key.gpg && \
rm manufacturing-key.gpg && \
chmod 700 /usr/sbin/start_admin_session && \
mkdir -p /opt/nebra

# Add python dependencies to PYTHONPATH
ENV PYTHONPATH="${PYTHON_DEPENDENCIES_DIR}:${PYTHONPATH}"
ENV PATH="${PYTHON_DEPENDENCIES_DIR}/bin:${PATH}"

ENTRYPOINT ["gunicorn", "--bind", "0.0.0.0:5000", "--timeout", "300", "hw_diag.wsgi:wsgi_app"]
# Copy environment variables startup script
COPY setenv.sh /opt/nebra/setenv.sh

# Copy container startup script
COPY start.sh /opt/nebra/start.sh

ENTRYPOINT ["/opt/start.sh"]
43 changes: 43 additions & 0 deletions setenv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

freq_file_name="/var/nebra/envvars/FREQ"
variant_file_name="/var/nebra/envvars/VARIANT"

# Create necessary folder if it doesn't exist
if [ ! -d "/var/nebra/envvars" ]; then
mkdir "/var/nebra/envvars"
fi

#FREQ
if [ -z ${FREQ+x} ]; then
if [ -f ${freq_file_name} ]; then
FREQ=$(<${freq_file_name});
export FREQ=${FREQ}
echo "FREQ is set as ${FREQ}";
else
echo "Error: Cannot set FREQ variable.";
fi
else
echo "FREQ variable is already set as ${FREQ}.";
if [ ! -f ${freq_file_name} ]; then
echo "FREQ parameter file doesn't exist. Setting it as ${FREQ} now.";
echo "${FREQ}" > ${freq_file_name}
fi
fi

#VARIANT
if [ -z ${VARIANT+x} ]; then
if [ -f ${variant_file_name} ]; then
VARIANT=$(<${variant_file_name});
export VARIANT=${VARIANT}
echo "VARIANT is set as ${VARIANT}";
else
echo "Error: Cannot set VARIANT variable.";
fi
else
echo "VARIANT variable is already set as ${VARIANT}.";
if [ ! -f ${variant_file_name} ]; then
echo "VARIANT parameter file doesn't exist. Setting it as ${VARIANT} now.";
echo "${VARIANT}" > ${variant_file_name}
fi
fi
6 changes: 6 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/sh

# shellcheck source=/dev/null
. /opt/nebra/setenv.sh

gunicorn --bind 0.0.0.0:5000 --timeout 300 hw_diag.wsgi:wsgi_app

0 comments on commit f41a38e

Please sign in to comment.