Merge: Ci: move services to specific hostnames
authorJean Privat <jean@pryen.org>
Thu, 21 Feb 2019 23:38:28 +0000 (18:38 -0500)
committerJean Privat <jean@pryen.org>
Thu, 21 Feb 2019 23:38:28 +0000 (18:38 -0500)
Testing nit with various services is a PITA.

The previous solution was to test them on localhost and requires that the services are available and configured on each test node (it is not always as easy as it seems).
Another problem with `localhost` is that testing within docker is complex as running multiple services in a single container is discouraged.

Here, we propose to simply move the service from localhost to specific hostnames.
This is to be the current "good" practice and is supported out-of-the-box bu various CI infrastructure including gitlab-ci.

Pull-Request: #2737

1  2 
.gitlab-ci.yml
lib/neo4j/neo4j.nit
misc/docker/ci/Dockerfile
tests/gitlab_ci.skip

diff --combined .gitlab-ci.yml
@@@ -1,10 -1,16 +1,18 @@@
  image: nitlang/nit-ci
  
+ services:
+   - mongo
+   - neo4j:2.3
+   - postgres
+ variables:
+   NEO4J_AUTH: none
  cache:
    paths:
      - .ccache
 +    - .gradle/caches
 +    - .gradle/wrapper
    key: "$CI_JOB_NAME"
  
  stages:
  before_script:
    - date
    - export CCACHE_DIR=$PWD/.ccache
 +  - export GRADLE_USER_HOME=$PWD/.gradle
    - export PATH=$PWD/bin:$PATH
    - pwd
    - ccache -s
    - ccache -M 500M
 +  - du -sh .gradle || true
    - type -a nitc nitdoc || true # is there some nit tools?
    - "> status.txt"
  
  after_script:
    - export CCACHE_DIR=$PWD/.ccache
    - ccache -s
 +  - du -sh .gradle || true
    - git status --ignored
    - date
    - tail status.txt
@@@ -86,7 -89,7 +94,7 @@@ nitunit_some
    dependencies:
      - build_tools
    script:
 -    - git diff --name-only origin/master..HEAD -- "*.nit" "*.res" "README.*" | grep -v "^tests/" > list0.txt
 +    - git diff --name-only origin/master..HEAD -- "*.nit" "*.res" "README.*" | grep -v "^tests/" > list0.txt || true
      - xargs nitls -pP < list0.txt > list.txt
      - xargs nitunit < list.txt
    artifacts:
@@@ -103,19 -106,9 +111,19 @@@ nitpick_full
      - build_tools
    script:
      - nitls lib src examples contrib
 -    - nitls -Pp lib src examples | grep -v -f tests/gitlab_ci.skip > list.txt # filter what is skipped by tests.sh
 +    - nitls -Pp lib src examples | grep -v -f tests/gitlab_ci.skip > list.txt || true # filter what is skipped by tests.sh
      - xargs nitpick < list.txt
  
 +basic_android:
 +  stage: test
 +  dependencies:
 +    - build_tools
 +  script:
 +    - make -C contrib/asteronits android
 +  artifacts:
 +    paths:
 +      - contrib/asteronits/bin/*.apk
 +
  # TEST FULL #########################################################
  
  test_full_nitcs:
@@@ -215,7 -208,7 +223,7 @@@ nitunit_lib
    dependencies:
      - build_tools
    script:
 -    - nitls -Pp lib | grep -v -f tests/gitlab_ci.skip > list.txt # filter what is skipped by tests.sh
 +    - nitls -Pp lib | grep -v -f tests/gitlab_ci.skip > list.txt || true # filter what is skipped by tests.sh
      - xargs nitunit -v < list.txt| tee log.txt
      - grep -e KO log.txt > status.txt || true
      - tail -3 log.txt >> status.txt
@@@ -232,7 -225,7 +240,7 @@@ nitunit_src
    dependencies:
      - build_tools
    script:
 -    - nitls -Pp src examples | grep -v -f tests/gitlab_ci.skip > list.txt # filter what is skipped by tests.sh
 +    - nitls -Pp src examples | grep -v -f tests/gitlab_ci.skip > list.txt || true # filter what is skipped by tests.sh
      - xargs nitunit -v < list.txt| tee log.txt
      - grep -e KO log.txt > status.txt || true
      - tail -3 log.txt >> status.txt
@@@ -254,21 -247,6 +262,21 @@@ test_contribs
      - test ! -s status.txt # no lines, no errors
    allow_failure: true
  
 +test_contribs_android:
 +  stage: more_test
 +  dependencies:
 +    - build_tools
 +  script:
 +    - misc/jenkins/check_contrib.sh android
 +    - grep 'error message' *.xml > status.txt || true
 +    - mkdir -p apk
 +    - find . -name '*.apk' -exec cp {} apk/ ";"
 +    - test ! -s status.txt # no lines, no errors
 +  artifacts:
 +    paths:
 +      - "apk"
 +    when: always
 +
  build_oot:
    stage: more_test
    dependencies:
diff --combined lib/neo4j/neo4j.nit
  
  # Neo4j connector through its JSON REST API using curl.
  #
  # In order to connect to Neo4j you need a connector:
  #
  #     # Create new Neo4j client
- #     var client = new Neo4jClient("http://localhost:7474")
+ #     var client = new Neo4jClient("http://neo4j:7474")
  #     assert client.is_ok
  #
  # The fundamental units that form a graph are nodes and relationships.
@@@ -66,39 -60,9 +60,9 @@@ module neo4
  import curl_json
  import error
  
- # Handles Neo4j server start and stop command
- #
- # `neo4j` binary must be in `PATH` in order to work
- class Neo4jServer
-       # Start the local Neo4j server instance
-       fun start: Bool do
-               sys.system("neo4j start console")
-               return true
-       end
-       # Like `start` but redirect the console output to `/dev/null`
-       fun start_quiet: Bool do
-               sys.system("neo4j start console > /dev/null")
-               return true
-       end
-       # Stop the local Neo4j server instance
-       fun stop: Bool do
-               sys.system("neo4j stop")
-               return true
-       end
-       # Like `stop` but redirect the console output to `/dev/null`
-       fun stop_quiet: Bool do
-               sys.system("neo4j stop > /dev/null")
-               return true
-       end
- end
  # `Neo4jClient` is needed to communicate through the REST API
  #
- #     var client = new Neo4jClient("http://localhost:7474")
+ #     var client = new Neo4jClient("http://neo4j:7474")
  #     assert client.is_ok
  class Neo4jClient
  
        # REST service to send cypher requests
        private var cypher_url: String
  
 -      private var curl = new Curl
 -
        init(base_url: String) do
                self.base_url = base_url
                var root = service_root
  
        # Save the node in base
        #
-       #     var client = new Neo4jClient("http://localhost:7474")
+       #     var client = new Neo4jClient("http://neo4j:7474")
        #
        #     # Create a node
        #     var andres = new NeoNode
        # Save the edge in base
        # From and to nodes will be created.
        #
-       #     var client = new Neo4jClient("http://localhost:7474")
+       #     var client = new Neo4jClient("http://neo4j:7474")
        #
        #     var andres = new NeoNode
        #     var kate = new NeoNode
  
        # Retrieve all nodes with specified `lbl`
        #
-       #     var client = new Neo4jClient("http://localhost:7474")
+       #     var client = new Neo4jClient("http://neo4j:7474")
        #
        #     var andres = new NeoNode
        #     andres.labels.add_all(["Human", "Male"])
  
        # Retrieve nodes belonging to all the specified `labels`.
        #
-       #     var client = new Neo4jClient("http://localhost:7474")
+       #     var client = new Neo4jClient("http://neo4j:7474")
        #
        #     var andres = new NeoNode
        #     andres.labels.add_all(["Human", "Male"])
@@@ -387,7 -353,7 +351,7 @@@ en
  #
  # Example:
  #
- #     var client = new Neo4jClient("http://localhost:7474")
+ #     var client = new Neo4jClient("http://neo4j:7474")
  #     var query = new CypherQuery
  #     query.nmatch("(n)-[r:LOVES]->(m)")
  #     query.nwhere("n.name=\"Andres\"")
@@@ -506,7 -472,7 +470,7 @@@ en
  # Then we can link the entity to the base:
  #
  #     # Init client
- #     var client = new Neo4jClient("http://localhost:7474")
+ #     var client = new Neo4jClient("http://neo4j:7474")
  #     client.save_node(andres)
  #     # The node is now linked
  #     assert andres.is_linked
@@@ -598,7 -564,7 +562,7 @@@ en
  #
  # Creating new nodes:
  #
- #     var client = new Neo4jClient("http://localhost:7474")
+ #     var client = new Neo4jClient("http://neo4j:7474")
  #
  #     var andres = new NeoNode
  #     andres.labels.add "Person"
@@@ -711,7 -677,7 +675,7 @@@ en
  #
  # Create a relationship:
  #
- #     var client = new Neo4jClient("http://localhost:7474")
+ #     var client = new Neo4jClient("http://neo4j:7474")
  #     # Create nodes
  #     var andres = new NeoNode
  #     andres["name"] = "Andres"
@@@ -804,7 -770,7 +768,7 @@@ en
  #
  # Example:
  #
- #     var client = new Neo4jClient("http://localhost:7474")
+ #     var client = new Neo4jClient("http://neo4j:7474")
  #
  #     var node1 = new NeoNode
  #     var node2 = new NeoNode
@@@ -1011,7 -977,7 +975,7 @@@ en
  # This is a representation of a neo job in JSON Format
  #
  # Each job description should contain a `to` attribute, with a value relative to the data API root
- # (so http://localhost:7474/db/data/node becomes just /node), and a `method` attribute containing
+ # (so http://neo4j:7474/db/data/node becomes just /node), and a `method` attribute containing
  # HTTP verb to use.
  #
  # Optionally you may provide a `body` attribute, and an `id` attribute to help you keep track
@@@ -47,7 -47,8 +47,8 @@@ RUN dpkg --add-architecture i386 
                libsqlite3-dev \
                libx11-dev \
                libxdg-basedir-dev \
-               postgresql \
+               netcat \
+               psmisc \
                # Packages needed for contrib, platforms and FFI
                ant \
                clang \
@@@ -56,7 -57,6 +57,7 @@@
                file \
                gnupg \
                gnuplot-nox \
 +              imagemagick \
                inkscape \
                libopenmpi-dev \
                time \
        && apt-get install -y nodejs \
        && rm -rf /var/lib/apt/lists/*
  
 +# Install OpenGL validator
 +RUN git clone https://github.com/KhronosGroup/glslang.git --depth=1 \
 +      && mkdir -p glslang/build \
 +      && cd glslang/build \
 +      && cmake .. \
 +      && make \
 +      && make install
 +
 +# Install android sdk/ndk
 +RUN mkdir -p /opt \
 +      && cd /opt \
 +      # Android SDK
 +      && curl https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip -o android-sdk-linux.zip \
 +      && unzip -q android-sdk-linux.zip -d android-sdk-linux \
 +      # Download a specific ndk version because old versions are not available trough sdkmanager
 +      && curl https://dl.google.com/android/repository/android-ndk-r17c-linux-x86_64.zip -o android-ndk-linux.zip \
 +      && unzip -q android-ndk-linux.zip \
 +      && mv android-ndk-r17c android-sdk-linux/ndk-bundle \
 +      && rm android-sdk-linux.zip android-ndk-linux.zip
 +RUN cd /opt \
 +      && yes | android-sdk-linux/tools/bin/sdkmanager "build-tools;27.0.0" "cmake;3.6.4111459" platform-tools tools  --verbose\
 +      && yes | android-sdk-linux/tools/bin/sdkmanager --licenses --verbose
 +# TODO: predownload bwdgc and gradle?
 +
  # Setup environment variables
 +ENV ANDROID_HOME=/opt/android-sdk-linux/
  ENV JAVA_HOME=/usr/lib/jvm/default-java/
  ENV JNI_LIB_PATH=$JAVA_HOME/jre/lib/amd64/server/
  ENV LD_LIBRARY_PATH=$JAVA_HOME/jre/lib/amd64/server/
  
 +# Used by CI to render junit files to html
  RUN pip3 install junit2html
  
  #  Prepare to install npm (npm is not packaged for debian:stretch)
diff --combined tests/gitlab_ci.skip
@@@ -1,10 -1,9 +1,6 @@@
  emscripten
  java
  glsl
- mongo
  mpi
- neo
  objc
- postgres
- nitrpg
 -action_nitro
 -asteronits
  wiringPi