Commit 25062d8d authored by Aanand Prasad's avatar Aanand Prasad
Browse files

Break docker-compose.yml out

- Separate files for core, dev and testing
- Fix bin/ci-test
- Add bin/test for running tests locally
- Some small YAML tweaks
parent ab7f7d56
Pipeline #4037 failed with stage
in 16 seconds
stages:
stages:
- test
test:
......
......@@ -14,16 +14,16 @@ It uses Rails 5 in API version.
Follow [the official instructions](https://docs.docker.com/compose/install/) for installation of Docker and Docker Compose.
(optional) If your INK steps have Docker dependencies, add those services to a `docker-compose.override.yml` file in this directory.
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 `bin/test` to run the tests in a Docker container.
## Setup gitlab CI
Go to /admin/runners on gitlab and copy the ci token.
......
#!/bin/sh
set -ex
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
export COMPOSE_PROJECT_NAME=inkapi
export COMPOSE_FILE=docker-compose.yml:docker-compose.test.yml
export RAILS_ENV=test
# docker-compose config
# exit
# kill and remove any running containers
cleanup () {
docker-compose -p inkapi kill
docker-compose down -v
docker-compose -p inkapi rm -f
docker-compose down -v --timeout=1
}
# run cleanup now in case the last run didn't exit properly
cleanup
# catch unexpected failures, do cleanup and output an error message
trap 'cleanup ; printf "${RED}Tests Failed For Unexpected Reasons${NC}\n"'\
HUP INT QUIT PIPE TERM
# build composed services and run the tests
export RAILS_ENV=test; docker-compose -p inkapi up --build
if [ $? -ne 0 ] ; then
printf "${RED}Docker Compose Failed${NC}\n"
exit 1
fi
# build composed services and run the tests
docker-compose build
docker-compose up -d postgres redis
docker-compose run ink
# wait for the test service to complete and grab the exit code
TEST_EXIT_CODE=`docker wait inkapi_ink_1`
TEST_EXIT_CODE=$?
# inspect the output of the test and display respective message
if [[ "$TEST_EXIT_CODE" -ne 0 ]] ; then
printf "${RED}Tests Failed${NC} - Exit Code: $TEST_EXIT_CODE\n"
......
......@@ -5,12 +5,9 @@ set -ex
echo RAILS ENV: $RAILS_ENV
./bin/rake db:create
if [[ $RAILS_ENV != 'test' ]]; then
./bin/rake db:schema:load
./bin/rake setup:create_account_recipe[$INK_EMAIL,$INK_PASSWORD,$INK_AUTH]
fi
./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
......@@ -3,6 +3,7 @@
set -ex
if [[ $RAILS_ENV == 'test' ]]; then
./bin/rake db:create
./bin/bundle exec rspec spec
else
./bin/rails s -p 3000 -b 0.0.0.0
......
#!/bin/bash
set -ex
export COMPOSE_FILE=docker-compose.yml:docker-compose.test.yml
export RAILS_ENV=test
docker-compose up -d postgres redis
docker-compose run -v "$PWD:/app" -v "gems:/gems" ink
version: '3'
services:
sidekiq:
build: .
env_file:
- '.env.sample'
environment:
# override rails_env through shell
- RAILS_ENV
depends_on:
- postgres
- redis
- slanger
- ink
volumes:
- ink-api-files-volume:/ink-api/ink_api_files
command: ['./bin/wait-for-it', 'postgres:5432', '-s', '-t', '40', '--', './bin/bundle', 'exec', 'sidekiq']
slanger:
image: inkmap/slanger:1.0.3
env_file:
- '.env.sample'
ports:
- 4567:4567
- 8080:8080
depends_on:
- redis
seed_db:
build: .
env_file:
- '.env.sample'
environment:
# override rails_env through shell
- RAILS_ENV
depends_on:
- postgres
- redis
- slanger
command: ['./bin/wait-for-it', 'postgres:5432', '-s', '-t', '40', '--', './bin/seed-db']
ink:
build: .
env_file:
- '.env.sample'
environment:
# override rails_env through shell
- RAILS_ENV
depends_on:
- postgres
- redis
- slanger
- seed_db
ports:
- 3000:3000
volumes:
- .:/app
- gems:/gems
- ink-api-files-volume:/ink-api/ink_api_files
command: ['./bin/wait-for-it', 'seed_db:1234', '-s', '-t', '100', '--', './bin/start']
version: '3'
services:
ink:
build: .
env_file:
- '.env.sample'
environment:
# override rails_env through shell
- RAILS_ENV
depends_on:
- postgres
- redis
command: ['./bin/wait-for-it', 'postgres:5432', '-s', '-t', '40', '--', './bin/start']
......@@ -15,65 +15,6 @@ services:
volumes:
- redis-volume:/var/lib/redis/data
slanger:
image: inkmap/slanger:1.0.3
env_file:
- '.env.sample'
ports:
- 4567:4567
- 8080:8080
depends_on:
- redis
sidekiq:
build: .
env_file:
- '.env.sample'
environment:
# override rails_env through shell
- RAILS_ENV=${RAILS_ENV}
depends_on:
- postgres
- redis
- slanger
- ink
volumes:
- ink-api-files-volume:/ink-api/ink_api_files
command: ['./bin/wait-for-it', 'postgres:5432', '-s', '-t', '40', '--', './bin/bundle', 'exec', 'sidekiq']
seed_db:
build: .
env_file:
- '.env.sample'
environment:
# override rails_env through shell
- RAILS_ENV=${RAILS_ENV}
depends_on:
- postgres
- redis
- slanger
command: ['./bin/wait-for-it', 'postgres:5432', '-s', '-t', '40', '--', './bin/seed-db']
ink:
build: .
env_file:
- '.env.sample'
environment:
# override rails_env through shell
- RAILS_ENV=${RAILS_ENV}
depends_on:
- postgres
- redis
- slanger
- seed_db
ports:
- 3000:3000
volumes:
- .:/app
- gems:/gems
- ink-api-files-volume:/ink-api/ink_api_files
command: ['./bin/wait-for-it', 'seed_db:1234', '-s', '-t', '100', '--', './bin/start']
volumes:
redis-volume:
postgres-volume:
......
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