Skip to content

Commit

Permalink
Merge pull request #3359 from csordasmarton/web_docker_image_hooks
Browse files Browse the repository at this point in the history
[docker] Web docker image hooks
  • Loading branch information
bruntib authored Jun 15, 2021
2 parents b2a6517 + 6b0ec06 commit ce398f5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
9 changes: 8 additions & 1 deletion web/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ FROM python:3.6-slim-stretch as builder
ARG CC_VERSION=master
ENV CC_VERSION ${CC_VERSION}

COPY hooks/ /hooks

ARG DEBIAN_FRONTEND=noninteractive
RUN set -x && apt-get update -qq \
&& apt-get install -qqy --no-install-recommends \
ca-certificates \
curl \
doxygen \
git \
make \
&& curl -sL https://deb.nodesource.com/setup_12.x | bash - \
Expand All @@ -23,9 +24,15 @@ RUN git clone https://github.com/Ericsson/CodeChecker.git /codechecker
WORKDIR /codechecker
RUN git checkout ${CC_VERSION}

# Run script before the package generation.
RUN chmod a+x /hooks/before_build.sh && sync && /hooks/before_build.sh

# Build CodeChecker web.
RUN make -C /codechecker/web package

# Run script after the package generation is finished.
RUN chmod a+x /hooks/after_build.sh && sync && /hooks/after_build.sh

###############################################################################
#-------------------------- PRODUCTION STAGE ----------------------------#
###############################################################################
Expand Down
32 changes: 20 additions & 12 deletions web/docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
#!/bin/bash

if [ "$(id -u)" == '0' ]; then
# Set PostgreSQL password file from secrets.
pgpass=/run/secrets/pgpass
if [ -f $pgpass ]; then
cp $pgpass /.pgpass
chmod 0600 /.pgpass
chown codechecker:codechecker /.pgpass
export PGPASSFILE=/.pgpass
fi
USER_ID=$($USER)
USER_GROUP="$(id -g)"
WORKSPACE_DIR="/workspace"
PGPASS_FILE=$WORKSPACE_DIR/.pgpass

# Change the owner of the workspace directory
mkdir -p /workspace
chown codechecker:codechecker /workspace
if [ "$(id -u)" = '0' ]; then
# Create workspace directory and change the permission to 'codechecker' user
# if this directory doesn't exists.
if [ ! -d $WORKSPACE_DIR ]; then
mkdir -p $WORKSPACE_DIR
chown -R codechecker:codechecker $WORKSPACE_DIR
fi

# Execute this script again with codechecker user.
exec gosu codechecker "$0" "$@"
fi

# Set PostgreSQL password file from secrets.
pgpass=/run/secrets/pgpass
if [ -f $pgpass ]; then
cat $pgpass > ${PGPASS_FILE}
chmod 0600 ${PGPASS_FILE}
chown ${USER_ID}:${USER_GROUP} ${PGPASS_FILE}
export PGPASSFILE=${PGPASS_FILE}
fi

exec "$@"
5 changes: 5 additions & 0 deletions web/docker/hooks/after_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

# This script can be used to run extra commands before the CodeChecker package
# is built. It can be useful when someone wants to patch some file and to
# create an internal docker image by using our docker image file.
5 changes: 5 additions & 0 deletions web/docker/hooks/before_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

# This script can be used to run extra commands 'after' the CodeChecker package
# is built. It can be useful when someone wants to add some extra files to the
# built CodeChecker package.

0 comments on commit ce398f5

Please sign in to comment.