Skip to content

Commit

Permalink
Docker runtime image (Ericsson#409)
Browse files Browse the repository at this point in the history
Adding Docker image containing runtimes.
  • Loading branch information
mcserep authored Jul 31, 2020
1 parent db95b30 commit 0f3ab69
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 39 deletions.
41 changes: 34 additions & 7 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ Table of Contents
* [How to parse a project](#how-to-parse-a-project)
* [How to start a webserver](#how-to-start-a-webserver)
* [Deployment](#deployment)
* [Build image for web](#build-image-for-web)
* [How to run CodeCompass webserver in docker](#how-to-run-codecompass-webserver-in-docker)
* [Build image for runtime](#build-image-for-runtime)
* [Build image for webserver](#build-image-for-webserver)
* [How to use the webserver executing container](#how-to-use-the-webserver-executing-container)

# Development
## Build image from development
Expand Down Expand Up @@ -112,18 +113,44 @@ CodeCompass_webserver \

# Deployment

## Build image for web
Build the web environment image from CodeCompass `master` branch:
## Build image for runtime
For a production environment you can build and use the runtime environment image,
which contains the built CodeCompass binaries and their dependencies:
```bash
docker build -t codecompass:runtime --no-cache --file docker/web/Dockerfile .
```

By default this image download the `master` branch of the CodeCompass GitHub
repository and build it in `Release` mode with `sqlite` database configuration.
You can override these default values through the following build-time
variables:

| Variable | Meaning |
| -------------------- | ---------------------------------------- |
| `CC_VERSION` | The branch, version hash or tag of the CodeCompass repository to use. |
| `CC_DATABASE`| Database type. Possible values are **sqlite**, **pgsql**. |
| `CC_BUILD_TYPE` | Specifies the build type. Supported values are **`Debug`** and **`Release`**. |

The below example builds the `codecompass:runtime` image with *pgsql* configuration:
```bash
docker build -t codecompass:runtime --build-arg CC_DATABASE=pgsql \
--no-cache --file docker/web/Dockerfile .
```

*Note*: the `codecompass:dev` is a prerequisite to build the `codecompass:runtime` image.

## Build image for webserver
You can use the `codecompass:runtime` image created
[above](#build-image-for-runtime) to build an executing container for the webserver:
```bash
docker build -t codecompass:web --no-cache --file docker/web/Dockerfile .
```

See more information [below](#how-to-run-codecompass-webserver-in-docker) how
to use this image to start a CodeCompass webserver.

## How to run CodeCompass webserver in docker
You can use the `codecompass:web` image created
[above](#build-image-for-web) to start a CodeCompass webserver.
### How to use the webserver executing container
You can use the `codecompass:web` image to start a CodeCompass webserver.
For this run the following command:
```bash
docker run \
Expand Down
74 changes: 74 additions & 0 deletions docker/runtime/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
###############################################################################
#----------------------------- BUILD STAGE ------------------------------#
###############################################################################

FROM codecompass:dev as builder

ARG CC_VERSION=master
ENV CC_VERSION ${CC_VERSION}

ARG CC_DATABASE=sqlite
ENV CC_DATABASE ${CC_DATABASE}

ARG CC_BUILD_TYPE=Release
ENV CC_BUILD_TYPE ${CC_BUILD_TYPE}

RUN apt-get install -y git

# Download CodeCompass release.
RUN git clone https://github.com/Ericsson/CodeCompass.git /CodeCompass
WORKDIR /CodeCompass
RUN git checkout ${CC_VERSION}

# Build CodeCompass.
RUN mkdir /CodeCompass-build && \
cd /CodeCompass-build && \
cmake /CodeCompass \
-DDATABASE=$CC_DATABASE \
-DCMAKE_INSTALL_PREFIX=/CodeCompass-install \
-DCMAKE_BUILD_TYPE=$CC_BUILD_TYPE && \
make -j $(nproc) && \
make install

###############################################################################
#-------------------------- PRODUCTION STAGE ----------------------------#
###############################################################################

FROM ubuntu:20.04

# tzdata package is installed implicitly in the following command. This package
# sets timezone interactively during the installation process. This environment
# variable prevents this interaction.
ARG DEBIAN_FRONTEND=noninteractive

RUN set -x && apt-get update -qq \
&& apt-get install -qqy --no-install-recommends \
llvm-7 \
libboost-filesystem-dev libboost-log-dev libboost-program-options-dev \
libsqlite3-dev \
postgresql-server-dev-12 \
default-jre \
libgit2-dev \
libssl1.1 \
libgvc6 \
libmagic-dev \
libthrift-dev \
libodb-sqlite-dev \
libodb-pgsql-dev \
ctags \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/ \
&& set +x

ENV TINI_VERSION v0.18.0

# Copy CodeCompass installed directory. (Change permission of the CodeCompass package.)
COPY --from=builder /CodeCompass-install /codecompass

ENV PATH="/codecompass/bin:$PATH"

ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini

ENTRYPOINT ["/tini", "--"]

36 changes: 4 additions & 32 deletions docker/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,11 @@
###############################################################################
#----------------------------- BUILD STAGE ------------------------------#
#---------------------------- IMPORT RUNTIME -----------------------------#
###############################################################################

FROM codecompass:dev as builder

ARG CC_VERSION=master
ENV CC_VERSION ${CC_VERSION}

ARG CC_DATABASE=sqlite
ENV CC_DATABASE ${CC_DATABASE}

ARG CC_BUILD_TYPE=Release
ENV CC_BUILD_TYPE ${CC_BUILD_TYPE}

RUN apt-get install -y git

# Download CodeCompass release.
RUN git clone https://github.com/Ericsson/CodeCompass.git /CodeCompass
WORKDIR /CodeCompass
RUN git checkout ${CC_VERSION}

# Build CodeCompass.
RUN mkdir /CodeCompass-build && \
cd /CodeCompass-build && \
cmake /CodeCompass \
-DDATABASE=$CC_DATABASE \
-DCMAKE_INSTALL_PREFIX=/CodeCompass-install \
-DCMAKE_BUILD_TYPE=$CC_BUILD_TYPE && \
make -j $(nproc) && \
make install
FROM codecompass:runtime as runtime

###############################################################################
#-------------------------- PRODUCTION STAGE ----------------------------#
#------------------------ EXECUTABLE CONTAINER --------------------------#
###############################################################################

FROM ubuntu:20.04
Expand All @@ -51,11 +25,9 @@ RUN set -x && apt-get update -qq \
libgit2-dev \
libssl1.1 \
libgvc6 \
libmagic-dev \
libthrift-dev \
libodb-sqlite-dev \
libodb-pgsql-dev \
ctags \
# To switch user and exec command.
gosu \
&& apt-get clean \
Expand All @@ -75,7 +47,7 @@ RUN groupadd -r codecompass -g ${CC_GID} && \
useradd -r --no-log-init -M -u ${CC_UID} -g codecompass codecompass

# Copy CodeCompass installed directory. (Change permission of the CodeCompass package.)
COPY --from=builder --chown=codecompass:codecompass /CodeCompass-install /codecompass
COPY --from=runtime --chown=codecompass:codecompass /codecompass /codecompass

ENV PATH="/codecompass/bin:$PATH"

Expand Down

0 comments on commit 0f3ab69

Please sign in to comment.