Browse Source

Merge branch '52-ci-with-docker' into 'develop'

CI with docker

Closes #52

See merge request tobias.wach/ccats!65
Sander, Paul 4 years ago
parent
commit
ba0168a5c1
2 changed files with 82 additions and 0 deletions
  1. 29 0
      .gitlab-ci.yml
  2. 53 0
      Dockerfile

+ 29 - 0
.gitlab-ci.yml

@@ -0,0 +1,29 @@
+image: docker:19.03.1
+
+services:
+  - docker:dind
+
+stages:
+  - build
+  - test
+
+build-image:
+  stage: build
+  before_script:
+  - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
+  script:
+    - docker build --pull -t "$CI_REGISTRY_IMAGE" .
+    - docker push "$CI_REGISTRY_IMAGE"
+     
+jsonCommaderTest:
+  stage: test
+  before_script:
+  - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
+  after_script:
+  - docker stop cont
+  - docker rm cont
+  script:
+  - docker pull "$CI_REGISTRY_IMAGE"
+  - docker run -d --name cont "$CI_REGISTRY_IMAGE" 
+  - docker exec cont test/jsonCommanderTest
+    

+ 53 - 0
Dockerfile

@@ -0,0 +1,53 @@
+FROM debian
+
+RUN apt-get update -y && apt-get install -y \
+    build-essential git cmake libpcap-dev libjsoncpp-dev wget libssl-dev
+
+WORKDIR /root/build
+
+RUN wget https://dl.bintray.com/boostorg/release/1.72.0/source/boost_1_72_0.tar.gz \
+    && tar xfz boost_1_72_0.tar.gz \
+    && rm boost_1_72_0.tar.gz \
+    && cd boost_1_72_0 \
+    && ./bootstrap.sh --prefix=/usr/local \
+    && ./b2 install \
+    && cd .. \
+    && rm -rf boost_1_72_0
+
+# Build and install libtins
+RUN git clone https://github.com/mfontanini/libtins.git \
+    && cd libtins && git checkout v4.2 \
+    && mkdir build && cd build \
+    && cmake ../ -DLIBTINS_ENABLE_CXX11=1 && make && make install \
+    && cd ../.. && rm -rf libtins
+
+# Build and install googletest
+RUN git clone https://github.com/google/googletest.git \
+    && cd googletest \
+    && mkdir build && cd build \
+    && cmake .. && make && make install \
+    && cd ../.. && rm -rf googletest
+
+RUN mkdir /root/build/files \
+    && touch /root/build/config.txt \
+    && echo "port=1234" >> /root/build/config.txt \
+    && echo "interface=lo" >> /root/build/config.txt \
+    && echo "userdatabase=userStorage.txt" >> /root/build/config.txt \
+    && echo "filedirectory=./files" >> /root/build/config.txt
+
+# Copy all required data into image
+COPY .cmake_modules/ /root/.cmake_modules
+COPY /daemon/include /root/build/include
+COPY /daemon/src /root/build/src
+COPY /daemon/test /root/build/test
+COPY /daemon/CMakeLists.txt /root/build
+
+# Compile ccats with tests
+RUN cmake -DENABLE_TESTS=true . && make \
+    && rm -rf src include CMakeFiles \
+    && rm Makefile CMakeCache.txt cmake_install.cmake CMakeLists.txt \
+    CTestTestfile.cmake
+
+# Set entrypoint and expose port
+ENTRYPOINT /root/build/bin/ccats
+EXPOSE 1234