Commit 40527b5a authored by Richard Smith-Unna's avatar Richard Smith-Unna
Browse files

Merge branch 'fix-ci' into 'master'

Fix ci

Closes #59 and #60

See merge request !16
parents 31aebce7 b1f937a2
Pipeline #4451 passed with stages
in 6 minutes and 24 seconds
......@@ -25,4 +25,7 @@ APPSECRET=765ec374ae0a69f4ce44
INK_EMAIL=admin@admin.com
INK_PASSWORD=abc12345
INK_AUTH=abc12345
RAILS_ENV=production
RAILS_ENV=development
RAILS_LOG_TO_STDOUT=1
DISABLE_DATABASE_ENVIRONMENT_CHECK=1
......@@ -13,6 +13,7 @@
/tmp
.idea/
.DS_Store
public/uploads/*
public/test/*
......
image: tmaier/docker-compose:latest
services:
- docker:dind
- postgres:latest
before_script:
- docker info
- docker-compose --version
stages:
# - build
- build
- test
variables:
POSTGRESQL_HOST: "postgres"
POSTGRESQL_PORT: "6379/1"
POSTGRESQL_PASSWORD: "inkpassword"
POSTGRESQL_USERNAME: "postgres"
REDIS_HOST: "redis"
SECRET_KEY_BASE: "f89c3d1e35cd199ddd4b6d55318de7ce30c9451c27019394bab96a1acc90acb677578bc284b9a0bb53f010952594a2f544b196fb9a18d6019ec37d99f1eaf245"
TEST_SECRET_KEY_BASE: "83dcb9140c078bd7d5a381be700e34b99de33ddf1b5d7f92ba5df356afc7f419bcc605a978649c6d639fe100f05ff721a1a482a7c1e0df416d904eef7a1acee9"
DEVELOPMENT_SECRET_KEY_BASE: "943d29212a265d6d7781b07f2850dde8b5b1bb72c2b713e2f72c74322d24f06a0da6276c8e88d454c976641fe410d9cc0fc4fd5ad7f2169dbb3593cc117e9d33"
DEVELOPMENT_FILE_LOCATION: "./ink_api_files/"
TEST_FILE_LOCATION: "/tmp/ink_api_files/"
PRODUCTION_FILE_LOCATION: "./ink_api_files/"
# remove
# build:
# stage: build
# script:
# - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.inkmap.com:5000
# - docker build -t registry.inkmap.com:5000/devops/ink-api .
# - docker push registry.inkmap.com:5000/devops/ink-api
IMAGE_ORG: inkcoko
IMAGE_NAME: ink-api
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ''
build:
image: docker:latest
stage: build
script:
- docker version
- docker build -t $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA .
- if [ -z "$DOCKERHUB_USERNAME" ] || [ -z "$DOCKERHUB_PASSWORD" ]; then exit 0; fi
- docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD
- echo "Ignore warning! Cannot perform an interactive login from a non TTY device"
- docker push $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA
test:
image: $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA
stage: test
variables:
GIT_STRATEGY: none
POSTGRESQL_HOST: postgres
POSTGRESQL_PORT: '5432'
POSTGRESQL_USERNAME: postgres
TEST_SECRET_KEY_BASE: "83dcb9140c078bd7d5a381be700e34b99de33ddf1b5d7f92ba5df356afc7f419bcc605a978649c6d639fe100f05ff721a1a482a7c1e0df416d904eef7a1acee9"
TEST_FILE_LOCATION: '/tmp/ink_api_files/'
RAILS_ENV: test
script:
- mv .env.sample .env
- mv docker/docker-compose-test.yml docker-compose-test.yml
# - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.inkmap.com:5000
- /bin/sh docker/ci-test.sh
- cd /app
- ./bin/rake db:create
- ./bin/bundle exec rspec spec
FROM ruby:2.2.3
FROM inkcoko/ink-api:base
MAINTAINER Vasilis Kefallinos <vkefallinos@gmail.com>
RUN wget https://github.com/jgm/pandoc/releases/download/1.19.2.1/pandoc-1.19.2.1-1-amd64.deb
RUN dpkg -i pandoc-1.19.2.1-1-amd64.deb
RUN apt-get update && apt-get install -qq -y --no-install-recommends \
build-essential libpq-dev git-core netcat-openbsd openjdk-7-jdk \
openjdk-7-jre zip calibre
COPY .env.sample .rspec .ruby-version Capfile config.ru Gemfile Gemfile.lock Rakefile StepGemfile ./
# Point Bundler at /gems. This will cause Bundler to re-use gems that have already been installed on the gems volume
ENV BUNDLE_PATH /gems
ENV BUNDLE_HOME /gems
COPY bin/bundle bin/bundle
RUN ./bin/bundle
# Increase how many threads Bundler uses when installing. Optional!
ENV BUNDLE_JOBS 4
COPY bin bin
COPY app app
COPY config config
COPY db db
COPY lib lib
COPY log log
COPY public public
COPY spec spec
# How many times Bundler will retry a gem download. Optional!
ENV BUNDLE_RETRY 3
EXPOSE 3000
# Where Rubygems will look for gems, similar to BUNDLE_ equivalents.
ENV GEM_HOME /gems
ENV GEM_PATH /gems
# You'll need something here. For development, you don't need anything super secret.
ENV SECRET_KEY_BASE development123
# Add /gems/bin to the path so any installed gem binaries are runnable from bash.
ENV PATH /gems/bin:$PATH
ENV DOCKERIZED true
RUN gem install bundler
# Setup the directory where we will mount the codebase from the host
VOLUME /app
WORKDIR /app
CMD /bin/bash
CMD ['./bin/server']
......@@ -27,12 +27,6 @@ GIT
specs:
inkstep_coko_demo_steps (1.0.2)
GIT
remote: https://gitlab.coko.foundation/blahah/inkstep_development
revision: a6972d5324d2ea96c78fc7c1cdb4b08fafb0cb51
specs:
inkstep_development (1.0.5)
GEM
remote: https://rubygems.org/
specs:
......@@ -353,7 +347,6 @@ DEPENDENCIES
ink_step!
inkstep_coko_conversion!
inkstep_coko_demo_steps!
inkstep_development!
jbuilder (~> 2.0)
jquery-rails
json_spec
......@@ -378,4 +371,4 @@ DEPENDENCIES
webmock
BUNDLED WITH
1.14.5
1.16.0
......@@ -18,12 +18,17 @@ Follow [the official instructions](https://docs.docker.com/compose/install/) for
Run `docker volume create --name=gems` to create a Docker volume for storing the Ruby gem dependencies outside the container.
Run `docker-compose build` to build the Docker images, then run `./bin/docker` to start the INK API service and its dependencies.
Once started, a command line prompt will open inside the running INK container. From that command line, run `./bin/setup` for initial application setup, or run `./bin/update` when needed for updates and migrations. Run `./bin/server` to start the server - after a while, a message will let you know that it's ready.
Run `docker-compose up` to start the app.
The INK API is now running. See [ink-client](https://gitlab.coko.foundation/INK/ink-client/) for a React front-end for creating and managing recipes.
## Run tests
Run `script/test` to run the tests in a Docker container. You can pass files or directories as arguments to scope the run to particular tests:
script/test spec/models
script/test spec/controllers/v1/admin_controller_spec.rb
## Setup gitlab CI
Go to /admin/runners on gitlab and copy the ci token.
......
docker-compose run --service-ports ink
File mode changed from 100644 to 100755
#!/usr/bin/env bash
set -ex
echo RAILS ENV: $RAILS_ENV
./bin/rake db:create
./bin/rake db:schema:load
./bin/rake setup:create_account_recipe[$INK_EMAIL,$INK_PASSWORD,$INK_AUTH]
(sleep 100; exit) &
echo "Ready and waiting"
nc -l -p 1234
bin/rails s -b 0.0.0.0
#!/usr/bin/env bash
set -ex
./bin/rails s -p 3000 -b 0.0.0.0
#!/usr/bin/env bash
set -e
./bin/rake db:create
./bin/bundle exec rspec "$@"
#!/usr/bin/env bash
# Use this script to test if a given TCP host/port are available
cmdname=$(basename $0)
echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
usage()
{
cat << USAGE >&2
Usage:
$cmdname host:port [-s] [-t timeout] [-- command args]
-h HOST | --host=HOST Host or IP under test
-p PORT | --port=PORT TCP port under test
Alternatively, you specify the host and port as host:port
-s | --strict Only execute subcommand if the test succeeds
-q | --quiet Don't output any status messages
-t TIMEOUT | --timeout=TIMEOUT
Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes
USAGE
exit 1
}
wait_for()
{
if [[ $TIMEOUT -gt 0 ]]; then
echoerr "$cmdname: waiting $TIMEOUT seconds for $HOST:$PORT"
else
echoerr "$cmdname: waiting for $HOST:$PORT without a timeout"
fi
start_ts=$(date +%s)
while :
do
if [[ $ISBUSY -eq 1 ]]; then
nc -z $HOST $PORT
result=$?
else
(echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1
result=$?
fi
if [[ $result -eq 0 ]]; then
end_ts=$(date +%s)
echoerr "$cmdname: $HOST:$PORT is available after $((end_ts - start_ts)) seconds"
break
fi
sleep 1
done
return $result
}
wait_for_wrapper()
{
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
if [[ $QUIET -eq 1 ]]; then
timeout $BUSYTIMEFLAG $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
else
timeout $BUSYTIMEFLAG $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
fi
PID=$!
trap "kill -INT -$PID" INT
wait $PID
RESULT=$?
if [[ $RESULT -ne 0 ]]; then
echoerr "$cmdname: timeout occurred after waiting $TIMEOUT seconds for $HOST:$PORT"
fi
return $RESULT
}
# process arguments
while [[ $# -gt 0 ]]
do
case "$1" in
*:* )
hostport=(${1//:/ })
HOST=${hostport[0]}
PORT=${hostport[1]}
shift 1
;;
--child)
CHILD=1
shift 1
;;
-q | --quiet)
QUIET=1
shift 1
;;
-s | --strict)
STRICT=1
shift 1
;;
-h)
HOST="$2"
if [[ $HOST == "" ]]; then break; fi
shift 2
;;
--host=*)
HOST="${1#*=}"
shift 1
;;
-p)
PORT="$2"
if [[ $PORT == "" ]]; then break; fi
shift 2
;;
--port=*)
PORT="${1#*=}"
shift 1
;;
-t)
TIMEOUT="$2"
if [[ $TIMEOUT == "" ]]; then break; fi
shift 2
;;
--timeout=*)
TIMEOUT="${1#*=}"
shift 1
;;
--)
shift
CLI=("$@")
break
;;
--help)
usage
;;
*)
echoerr "Unknown argument: $1"
usage
;;
esac
done
if [[ "$HOST" == "" || "$PORT" == "" ]]; then
echoerr "Error: you need to provide a host and port to test."
usage
fi
TIMEOUT=${TIMEOUT:-15}
STRICT=${STRICT:-0}
CHILD=${CHILD:-0}
QUIET=${QUIET:-0}
# check to see if timeout is from busybox?
# check to see if timeout is from busybox?
TIMEOUT_PATH=$(realpath $(which timeout))
if [[ $TIMEOUT_PATH =~ "busybox" ]]; then
ISBUSY=1
BUSYTIMEFLAG="-t"
else
ISBUSY=0
BUSYTIMEFLAG=""
fi
if [[ $CHILD -gt 0 ]]; then
wait_for
RESULT=$?
exit $RESULT
else
if [[ $TIMEOUT -gt 0 ]]; then
wait_for_wrapper
RESULT=$?
else
wait_for
RESULT=$?
fi
fi
if [[ $CLI != "" ]]; then
if [[ $RESULT -ne 0 && $STRICT -eq 1 ]]; then
echoerr "$cmdname: strict mode, refusing to execute subprocess"
exit $RESULT
fi
exec "${CLI[@]}"
else
exit $RESULT
fi
......@@ -19,9 +19,7 @@ staging:
development:
<<: *default
database: ink_development
host: localhost
test:
<<: *default
database: ink_test
host: localhost
......@@ -79,6 +79,7 @@ Rails.application.configure do
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
STDOUT.sync = true
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
......
......@@ -42,6 +42,13 @@ Rails.application.configure do
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
if ENV["RAILS_LOG_TO_STDOUT"].present?
STDOUT.sync = true
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
......
......@@ -79,6 +79,7 @@ Rails.application.configure do
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
STDOUT.sync = true
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
......
......@@ -79,6 +79,7 @@ Rails.application.configure do
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
STDOUT.sync = true
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment