Procházet zdrojové kódy

Add docker/test image

Michael Andrews před 7 roky
rodič
revize
e74bb73f77
5 změnil soubory, kde provedl 138 přidání a 0 odebrání
  1. 1 0
      .gitignore
  2. 29 0
      docker/test/Dockerfile
  3. 30 0
      docker/test/README.md
  4. 68 0
      docker/test/develop.yml
  5. 10 0
      docker/test/scripts/test_env

+ 1 - 0
.gitignore

@@ -27,3 +27,4 @@ deployment/cookbooks
 manifest.yml
 config/unicorn.rb
 db/schema.rb
+.local/

+ 29 - 0
docker/test/Dockerfile

@@ -0,0 +1,29 @@
+FROM huginn/huginn-single-process
+
+ENV PHANTOM_VERSION "phantomjs-2.1.1"
+ENV PHANTOM_JS "${PHANTOM_VERSION}-linux-x86_64"
+
+RUN apt-get update && \
+    apt-get -y install \
+      build-essential \
+      chrpath \
+      libssl-dev \
+      libxft-dev \
+      libfreetype6 \
+      libfreetype6-dev \
+      libfontconfig1 \
+      libfontconfig1-dev curl && \
+    curl -Ls https://bitbucket.org/ariya/phantomjs/downloads/${PHANTOM_JS}.tar.bz2 \
+      | tar jxvf - --strip-components=2 -C /usr/local/bin/ ${PHANTOM_JS}/bin/phantomjs
+
+ENV RAILS_ENV test
+RUN chown -R huginn:huginn /app && \
+    sudo -u huginn -H LC_ALL=en_US.UTF-8 ON_HEROKU=true bundle install --with test development --path vendor/bundle -j 4
+
+ADD "docker/scripts/setup_env" "/scripts/"
+ADD "docker/test/scripts/" "/scripts/"
+
+USER huginn
+WORKDIR /app
+ENTRYPOINT ["/scripts/test_env"]
+CMD ["rake spec"]

+ 30 - 0
docker/test/README.md

@@ -0,0 +1,30 @@
+Docker image for Huginn testing
+=================================================
+
+This image allows the [Huginn](https://github.com/cantino/huginn) test suite to be run in a container, against multiple databases.
+
+It was inspired by the [official docker container for huginn](https://registry.hub.docker.com/u/cantino/huginn)
+
+In Development Mode, the source code of the current project directory is mounted as a volume overlaying the packaged `/app` directory.
+
+## Development Usage
+
+Build a docker image that contains huginn, as well as huginn test dependencies using `docker-compose`:
+    cd docker/test
+    docker-compose -f develop.yml build
+
+Run all specs against a MySQL database using `docker-compose`:
+
+    cd docker/test
+    docker-compose -f develop.yml run huginn_test_mysql
+    docker-compose -f develop.yml down
+
+Run all specs against a Postgres database using `docker-compose`:
+
+    cd docker/test
+    docker-compose -f develop.yml run huginn_test_postgres
+    docker-compose -f develop.yml down
+
+Run a specific spec using `docker-compose`:
+    docker-compose -f develop.yml run huginn_test_postgres rspec ./spec/helpers/dot_helper_spec.rb:82
+    docker-compose -f develop.yml down

+ 68 - 0
docker/test/develop.yml

@@ -0,0 +1,68 @@
+# This needs at least compose 1.6.0
+version: '2'
+
+services:
+  mysqldata:
+    image: mysql:5.7
+    command: /bin/true
+
+  mysql:
+    image: mysql:5.7
+    volumes_from:
+      - mysqldata
+    environment:
+      MYSQL_ROOT_PASSWORD: myrootpassword
+      MYSQL_DATABASE: huginn
+      MYSQL_USER: huginn
+      MYSQL_PASSWORD: myhuginnpassword
+
+  postgresdata:
+    image: postgres:9.5
+    command: /bin/true
+
+  postgres:
+    image: postgres:9.5
+    volumes_from:
+      - postgresdata
+    environment:
+      POSTGRES_PASSWORD: myhuginnpassword
+      POSTGRES_USER: huginn
+
+  huginn_test_mysql:
+    build:
+      context: ../../
+      dockerfile: docker/test/Dockerfile
+    restart: 'no'
+    environment:
+      DATABASE_ADAPTER: mysql2
+      DATABASE_NAME: huginn
+      TEST_DATABASE_NAME: huginn
+      DATABASE_USERNAME: huginn
+      DATABASE_PASSWORD: myhuginnpassword
+      MYSQL_PORT_3306_TCP_ADDR: mysql
+      MYSQL_PORT_3306_TCP_PORT: 3306
+    links:
+      - mysql
+    volumes:
+      - ../../:/app
+      - /app/vendor/bundle
+
+  huginn_test_postgres:
+    build:
+      context: ../../
+      dockerfile: docker/test/Dockerfile
+    restart: 'no'
+    environment:
+      DATABASE_ADAPTER: postgresql
+      TEST_DATABASE_NAME: huginn
+      DATABASE_NAME: huginn
+      DATABASE_USERNAME: huginn
+      DATABASE_PASSWORD: myhuginnpassword
+      DATABASE_SOCKET:
+      POSTGRES_PORT_5432_TCP_ADDR: postgres
+      POSTGRES_PORT_5432_TCP_PORT: 5432
+    links:
+      - postgres
+    volumes:
+      - ../../:/app
+      - /app/vendor/bundle

+ 10 - 0
docker/test/scripts/test_env

@@ -0,0 +1,10 @@
+#!/bin/bash
+set -e
+
+/scripts/setup_env
+source /app/.env
+
+export RAILS_ENV=test
+bundle install --with test development --path vendor/bundle -j 4
+bundle exec rake db:create db:migrate
+bundle exec "$@"