1# Build a project image running supervisor on startup and autostarting all daemons
  2
  3# Building requires a more recent docker version than v1.13.1 so don't build from a Centos 7.9 machine
  4
  5# Pull in CHART framework
  6ARG CHART_FRAMEWORK_IMAGE_NAME
  7FROM ${CHART_FRAMEWORK_IMAGE_NAME}
  8
  9WORKDIR /app
 10
 11# Copy application files
 12ARG CHART_REPO_NAME
 13ENV CHART_REPO_NAME="${CHART_REPO_NAME}"
 14COPY . ${CHART_REPO_NAME}/
 15
 16# Create the consolidated static directory
 17ARG CHART_LAUNCHER_NAME
 18ENV CHART_LAUNCHER_NAME="${CHART_LAUNCHER_NAME}"
 19RUN CHART_STATIC_ROOT=/mnt/static ${CHART_REPO_NAME}/bin/${CHART_LAUNCHER_NAME} django_manage collectstatic --no-input
 20
 21# The startup file template is expanded now so it's available on container startup
 22ARG CHART_PROJECT_NAME
 23ENV CHART_PROJECT_NAME="${CHART_PROJECT_NAME}"
 24
 25# Copy the container startup script to /app to make it more visible and
 26# Expand .bashrc as we have everything needed and
 27# Symlink /app/scripts to the actual scripts directory for better visibility
 28# Make log.config writeable by scripts/webserver.sh
 29RUN chown -R root:root /app && \
 30    cp ${CHART_REPO_NAME}/docker/project/startup.sh . && \
 31    envsubst '$CHART_REPO_NAME' < ${CHART_REPO_NAME}/docker/project/bashrc.docker.tmpl > .bashrc && \
 32    chmod +x .bashrc && \
 33    ln -s ${CHART_REPO_NAME}/docker/project/scripts . && \
 34    touch log.config && \
 35    chmod 666 log.config
 36
 37# Fix permissions so the container can be started as a different user to the one who created the image
 38# And make some directories used by the DEV runtime configuration settings
 39RUN chmod 777 /app && \
 40    chmod 777 /app/${CHART_REPO_NAME} && \
 41    chmod 777 /app/${CHART_REPO_NAME}/${CHART_PROJECT_NAME} && \
 42    mkdir /var/log/chart && \
 43    mkdir /run/chart && \
 44    mkdir /work
 45
 46# Make the reports SU writeable by the normal user. This is needed for the DU patch function only
 47RUN chmod -R o+w /app/${CHART_REPO_NAME}/chartepssg_du
 48
 49# Create a default username and uid which is intended to be dynamically replaced at runtime
 50# via custom passwd and groups files
 51# ARG CHART_USERNAME=chart
 52# ARG CHART_UID=1001
 53# RUN useradd ${CHART_USERNAME} --uid ${CHART_UID} --home-dir /app --shell /bin/bash --no-log-init && \
 54    # chown ${CHART_USERNAME} /app
 55# USER ${CHART_USERNAME}
 56
 57# Write a VERSIONS file inside the image
 58ARG PROJECT_VCS_BRANCH
 59ARG PROJECT_VCS_TAG
 60ARG PROJECT_VCS_COMMIT
 61ARG PROJECT_BUILD_DIRTY
 62ARG DU_VCS_BRANCH
 63ARG DU_VCS_TAG
 64ARG DU_VCS_COMMIT
 65ARG DU_BUILD_DIRTY
 66# ARG DU_SRDB_VCS_BRANCH
 67# ARG DU_SRDB_VCS_TAG
 68# ARG DU_SRDB_VCS_COMMIT
 69# ARG DU_SRDB_BUILD_DIRTY
 70ARG PROJECT_BUILD_USER
 71ARG PROJECT_BUILD_HOST
 72ARG PROJECT_BUILD_DIR
 73RUN echo "project.vcs.branch=${PROJECT_VCS_BRANCH}\n\
 74project.vcs.tag=${PROJECT_VCS_TAG}\n\
 75project.vcs.commit=${PROJECT_VCS_COMMIT}\n\
 76project.build.dirty=${PROJECT_BUILD_DIRTY}\n\
 77du.vcs.branch=${DU_VCS_BRANCH}\n\
 78du.vcs.tag=${DU_VCS_TAG}\n\
 79du.vcs.commit=${DU_VCS_COMMIT}\n\
 80du.build.dirty=${DU_BUILD_DIRTY}\n\
 81# du_srdb.vcs.branch=${DU_SRDB_VCS_BRANCH}\n\
 82# du_srdb.vcs.tag=${DU_SRDB_VCS_TAG}\n\
 83# du_srdb.vcs.commit=${DU_SRDB_VCS_COMMIT}\n\
 84# du_srdb.build.dirty=${DU_SRDB_BUILD_DIRTY}\n\
 85project.build.user=${PROJECT_BUILD_USER}\n\
 86project.build.host=${PROJECT_BUILD_HOST}\n\
 87project.build.dir=${PROJECT_BUILD_DIR}"\
 88> ${CHART_REPO_NAME}/VERSIONS
 89
 90# Set image labels
 91LABEL "eum.chart.project.vcs.branch"="${PROJECT_VCS_BRANCH}"
 92LABEL "eum.chart.project.vcs.tag"="${PROJECT_VCS_TAG}"
 93LABEL "eum.chart.project.vcs.commit"="${PROJECT_VCS_COMMIT}"
 94LABEL "eum.chart.project.build.dirty"="${PROJECT_BUILD_DIRTY}"
 95LABEL "eum.chart.du.vcs.branch"="${DU_VCS_BRANCH}"
 96LABEL "eum.chart.du.vcs.tag"="${DU_VCS_TAG}"
 97LABEL "eum.chart.du.vcs.commit"="${DU_VCS_COMMIT}"
 98LABEL "eum.chart.du.build.dirty"="${DU_BUILD_DIRTY}"
 99# LABEL "eum.chart.du.srdb.vcs.branch"="${DU_SRDB_VCS_BRANCH}"
100# LABEL "eum.chart.du.srdb.vcs.tag"="${DU_SRDB_VCS_TAG}"
101# LABEL "eum.chart.du.srdb.vcs.commit"="${DU_SRDB_VCS_COMMIT}"
102# LABEL "eum.chart.du.srdb.build.dirty"="${DU_SRDB_BUILD_DIRTY}"
103LABEL "eum.chart.project.build.user"="${PROJECT_BUILD_USER}"
104LABEL "eum.chart.project.build.host"="${PROJECT_BUILD_HOST}"
105LABEL "eum.chart.project.build.dir"="${PROJECT_BUILD_DIR}"
106
107# On startup run our special creator file that expands runtime template variables
108ENTRYPOINT [ "./startup.sh" ]
109
110# By default launch supervisor on startup
111CMD ["bash"]