Skip to content

Commit

Permalink
Integrate docker-compose changes
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinKruglov committed Nov 11, 2021
1 parent 4391112 commit 6a33578
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 79 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ jobs:
run: docker load -i /tmp/docker-save/snapshot.tar || true
if: steps.cache-docker.outputs.cache-hit == 'true'
- name: Build
run: docker-compose -f docker-compose.ci.yml -p app build
run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml -p app build
- name: Test
run: docker-compose -f docker-compose.ci.yml run --rm test
run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml run --rm app
- name: Prepare Docker cache
run: mkdir -p /tmp/docker-save && docker save app_test:latest -o
/tmp/docker-save/snapshot.tar && ls -lh /tmp/docker-save
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ RUN bundle install --no-binstubs --retry=10 --jobs=4
# ------------------------------------------------------------------------------
# Web
# ------------------------------------------------------------------------------
FROM dependencies AS web
FROM dependencies AS app

RUN mkdir -p ${APP_HOME}
WORKDIR ${APP_HOME}
Expand Down Expand Up @@ -111,15 +111,15 @@ RUN bundle config unset without
# ------------------------------------------------------------------------------
# Dev
# ------------------------------------------------------------------------------
FROM web as dev
FROM app as dev

RUN bundle config set with "development"
RUN bundle install --no-binstubs --retry=10 --jobs=4

# ------------------------------------------------------------------------------
# Test
# ------------------------------------------------------------------------------
FROM web as test
FROM app as test

RUN bundle config set with "test"
RUN bundle install --no-binstubs --retry=10 --jobs=4
Expand Down
38 changes: 9 additions & 29 deletions docker-compose.ci.yml
Original file line number Diff line number Diff line change
@@ -1,53 +1,33 @@
version: '3.8'
version: "3.8"
services:
test:
app:
build:
context: .
target: test
args:
RAILS_ENV: test
cache_from:
- app_test:latest
image: app_test
command: bash -c "wait-for-it test-redis:6379 --strict --timeout=60 -- script/test"
ports:
- 3000:3000
depends_on:
- test-db
- test-redis
command: bash -c "wait-for-it redis:6379 --strict --timeout=60 -- script/test"
env_file:
- .env.test
environment:
DATABASE_URL: postgres://postgres:password@test-db:5432/buy-for-your-school-test
REDIS_URL: redis://test-redis:6379
DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL: 'true'
DOCKER: 'true'
DATABASE_URL: postgres://postgres:password@db:5432/buy-for-your-school-test
DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL: "true"
DOCKER: "true"
SELENIUM_HUB_URL: http://test-chrome:4444/wd/hub
CC_TEST_REPORTER_ID: ${CC_TEST_REPORTER_ID}
GIT_BRANCH: ${GIT_BRANCH}
GIT_COMMIT_SHA: ${GIT_COMMIT_SHA}
networks:
- test

test-db:
image: postgres
volumes:
- db-data:/var/lib/postgresql/data
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_HOST_AUTH_METHOD: trust
db:
networks:
- test

test-redis:
image: redis
volumes:
- redis-data:/data
redis:
networks:
- test

networks:
test:
volumes:
db-data:
redis-data:
48 changes: 8 additions & 40 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,28 @@
version: '3.8'
version: "3.8"
services:
test:
app:
build:
context: .
target: test
args:
RAILS_ENV: test
command: bash -c "wait-for-it test-redis:6379 --strict --timeout=60 -- script/test"
ports:
- 3000:3000
depends_on:
- test-db
- test-redis
- test-chrome
command: bash -c "wait-for-it redis:6379 --strict --timeout=60 -- script/test"
env_file:
- .env.test
environment:
DATABASE_URL: postgres://postgres:password@test-db:5432/buy-for-your-school-test
REDIS_URL: redis://test-redis:6379
DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL: 'true'
DOCKER: 'true'
DATABASE_URL: postgres://postgres:password@db:5432/buy-for-your-school-test
DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL: "true"
DOCKER: "true"
SELENIUM_HUB_URL: http://test-chrome:4444/wd/hub
volumes:
- .:/srv/app
tty: true
stdin_open: true
networks:
- test

test-db:
image: postgres
volumes:
- db-data:/var/lib/postgresql/data
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_HOST_AUTH_METHOD: trust
networks:
- test

test-redis:
image: redis
volumes:
- redis-data:/data
db:
networks:
- test

test-chrome:
image: selenium/standalone-chrome:95.0-chromedriver-95.0
volumes:
- /dev/shm:/dev/shm
redis:
networks:
- test

networks:
test:
volumes:
db-data:
redis-data:
8 changes: 5 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
version: '3.8'
version: "3.8"
services:
web:
app:
build:
context: .
target: web
target: dev
args:
RAILS_ENV: development
# command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
Expand Down Expand Up @@ -33,7 +33,9 @@ services:
volumes:
- db-data:/var/lib/postgresql/data
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_HOST_AUTH_METHOD: trust
networks:
- dev

Expand Down
4 changes: 2 additions & 2 deletions script/spec
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -e
COMMAND_INPUT=$1

if [ -n "$COMMAND_INPUT" ]; then
docker-compose -f docker-compose.test.yml run --rm test bundle exec rspec --format=documentation "$COMMAND_INPUT"
docker-compose -f docker-compose.yml -f docker-compose.test.yml run --rm app bundle exec rspec "$COMMAND_INPUT"
else
docker-compose -f docker-compose.test.yml run --rm test bundle exec rake
docker-compose -f docker-compose.yml -f docker-compose.test.yml run --rm app bundle exec rake
fi

0 comments on commit 6a33578

Please sign in to comment.