Skip to content

Commit

Permalink
Move the git commit parsing out of the start.sh and into the build tl…
Browse files Browse the repository at this point in the history
…-its-umich-edu#1462

THIS IS A draft: It was suggested to have this command to parse git in a
separate file and also need to add to Dockerfile.openshift.

Also this is going to need to be rebased.
  • Loading branch information
jonespm committed Jan 12, 2023
1 parent 4a2ab59 commit e91ca04
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
23 changes: 17 additions & 6 deletions dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,14 @@ RUN apt-get update && \
build-essential curl apt-transport-https libpq-dev netcat jq python3-dev xmlsec1 cron git && \
apt-get upgrade -y




# Install MariaDB from the mariadb repository rather than using Debians
# https://mariadb.com/kb/en/mariadb-package-repository-setup-and-usage/
RUN curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | bash && \
apt install -y --no-install-recommends libmariadb-dev

# Clean up anything we don't need anymore
RUN apt-get purge -y curl libcurl4 && \
apt autoremove -y && \
apt-get clean -y && \
rm -rf /var/lib/apt/lists/*

RUN pip install --no-cache-dir -r requirements.txt

# copy built react and node libraries for production mode
Expand All @@ -65,6 +62,20 @@ COPY --from=node-prod-deps /usr/src/app/node_modules node_modules
# NOTE: project files likely to change between dev builds
COPY . .

# Generate git version information
RUN bash -l -c 'GIT_REPO="$(git config --local remote.origin.url)"; \
GIT_COMMIT="$(git rev-parse HEAD)"; \
GIT_BRANCH="$(git name-rev "$GIT_COMMIT" --name-only)"; \
echo "export GIT_REPO=$GIT_REPO" > /etc/git.version; \
echo "export GIT_COMMIT=$GIT_COMMIT" >> /etc/git.version; \
echo "export GIT_BRANCH=$GIT_BRANCH" >> /etc/git.version'

# Clean up anything we don't need anymore
RUN apt-get purge -y git curl libcurl4 libcurl3-gnutls && \
apt autoremove -y && \
apt-get clean -y && \
rm -rf /var/lib/apt/lists/* .git

RUN python manage.py collectstatic --verbosity 0 --noinput

# Sets the local timezone of the docker image
Expand Down
14 changes: 5 additions & 9 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
# Case insensitive match
shopt -s nocaseglob

# Load in git version information
source /etc/git.version

echo "Git tag is $GIT_BRANCH"

if [ -z "${ENV_FILE}" ]; then
ENV_FILE="/secrets/env.hjson"
fi
Expand Down Expand Up @@ -52,15 +57,6 @@ while ! nc -z "${MYSQL_HOST}" "${MYSQL_PORT}"; do
sleep 1 # wait 1 second before check again
done

if [ -d .git ]; then
GIT_REPO="$(git config --local remote.origin.url)"
export GIT_REPO
GIT_COMMIT="$(git rev-parse HEAD)"
export GIT_COMMIT
GIT_BRANCH="$(git name-rev "$GIT_COMMIT" --name-only)"
export GIT_BRANCH
fi;

echo Running python startups
python manage.py migrate

Expand Down

0 comments on commit e91ca04

Please sign in to comment.