From 6a33578bcb53146772c482ddff133a44b6877f96 Mon Sep 17 00:00:00 2001 From: Edwin Kruglov Date: Thu, 11 Nov 2021 15:41:06 +0000 Subject: [PATCH] Integrate docker-compose changes --- .github/workflows/continuous-integration.yml | 4 +- Dockerfile | 6 +-- docker-compose.ci.yml | 38 ++++------------ docker-compose.test.yml | 48 ++++---------------- docker-compose.yml | 8 ++-- script/spec | 4 +- 6 files changed, 29 insertions(+), 79 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index ce5091a95..c9c1d8da1 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -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 diff --git a/Dockerfile b/Dockerfile index bbf4614ba..87c7ff65b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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} @@ -111,7 +111,7 @@ 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 @@ -119,7 +119,7 @@ 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 diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml index f43f69452..567cf7f05 100644 --- a/docker-compose.ci.yml +++ b/docker-compose.ci.yml @@ -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: diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 25e7ab3bc..65120d752 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -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: diff --git a/docker-compose.yml b/docker-compose.yml index 12cf948e1..8995e952b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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'" @@ -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 diff --git a/script/spec b/script/spec index f77251dfa..4bce842c8 100755 --- a/script/spec +++ b/script/spec @@ -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