From 21b7e6e567727a6bf383591fb502ae79e80f251c Mon Sep 17 00:00:00 2001 From: Neal Chambers Date: Tue, 24 Sep 2024 09:30:28 +0900 Subject: [PATCH] Use Dockerv2 --- .github/workflows/mapi.yml | 8 ++++---- docker/README.md | 10 +++------- docker/build-log | 8 ++++---- docker/build-log.ps1 | 4 ++-- docker/cop | 6 +++--- docker/cop.ps1 | 2 +- docker/qtest-log | 8 ++++---- docker/run | 6 +++--- docker/seed | 18 +++++++++--------- docker/seed.ps1 | 6 +++--- docker/server-log | 4 ++-- docker/server.ps1 | 6 +++--- docker/test | 12 ++++++------ docker/test.ps1 | 4 ++-- 14 files changed, 49 insertions(+), 53 deletions(-) diff --git a/.github/workflows/mapi.yml b/.github/workflows/mapi.yml index cc285a2894..aab701947b 100644 --- a/.github/workflows/mapi.yml +++ b/.github/workflows/mapi.yml @@ -14,12 +14,12 @@ jobs: steps: - uses: actions/checkout@v3 - run: docker/build - - run: docker-compose up --detach + - run: docker compose up --detach - run: until curl -f -s http://localhost:3000; do echo "waiting for api server"; sleep 1; done - - run: docker-compose exec -T db psql postgresql://ofn:f00d@localhost:5432/open_food_network_dev --command="update spree_users set spree_api_key='testing' where login='ofn@example.com'" + - run: docker compose exec -T db psql postgresql://ofn:f00d@localhost:5432/open_food_network_dev --command="update spree_users set spree_api_key='testing' where login='ofn@example.com'" # equivalent to Flipper.enable(:api_v1) - - run: docker-compose exec -T db psql postgresql://ofn:f00d@localhost:5432/open_food_network_dev --command="insert into flipper_features (key, created_at, updated_at) values ('api_v1', localtimestamp, localtimestamp)" - - run: docker-compose exec -T db psql postgresql://ofn:f00d@localhost:5432/open_food_network_dev --command="insert into flipper_gates (feature_key, key, value, created_at, updated_at) values ('api_v1', 'boolean', 'true', localtimestamp, localtimestamp)" + - run: docker compose exec -T db psql postgresql://ofn:f00d@localhost:5432/open_food_network_dev --command="insert into flipper_features (key, created_at, updated_at) values ('api_v1', localtimestamp, localtimestamp)" + - run: docker compose exec -T db psql postgresql://ofn:f00d@localhost:5432/open_food_network_dev --command="insert into flipper_gates (feature_key, key, value, created_at, updated_at) values ('api_v1', 'boolean', 'true', localtimestamp, localtimestamp)" # Run Mayhem for API - name: Run Mayhem for API diff --git a/docker/README.md b/docker/README.md index 0d8b34bae8..c6d3b50a6e 100644 --- a/docker/README.md +++ b/docker/README.md @@ -3,7 +3,7 @@ ## What's the point? * Setting up the Open Food Network app on your local machine is quick and easy with the aid of Docker. * Docker provides a common virtual environment available to all developers and resolves the infamous "but it works on my machine" problem. -* Use the scripts in this directory to execute tasks in Docker. Please note that these scripts are intended to be executed from this app's root directory (/openfoodnetwork). These scripts allow you to bypass the need to keep typing "docker-compose run web". +* Use the scripts in this directory to execute tasks in Docker. Please note that these scripts are intended to be executed from this app's root directory (/openfoodnetwork). These scripts allow you to bypass the need to keep typing "docker compose run web". ## Limitations 1. The docker environment can't directly control your host system browser, which means that browser specs (under `/spec/system/`) and email previews will not work. You may be able to find a solution with [this article](https://evilmartians.com/chronicles/system-of-a-test-setting-up-end-to-end-rails-testing). If so, please contribute! @@ -17,10 +17,6 @@ * Visit https://docs.docker.com/engine/install/#server and select your Linux distribution to install Docker Engine. Note: There is no need to install Docker Desktop on Linux. * Follow the installation instructions provided. Installing from Docker repositories is recommended. -* Install Docker Compose V1. Docker Engine comes with Docker Compose V2 which is not yet supported by our Docker scripts. -```sh -$ sudo apt install docker-compose -``` * To run Docker commands as a regular user instead of as root (with sudo), follow the instructions at https://docs.docker.com/engine/install/linux-postinstall/. #### Windows @@ -93,7 +89,7 @@ You may need to wait several minutes before getting the server up and running pr * If you’re getting the following error: ```sh dockerpycreds.errors.InitializationError: docker-credential-desktop not installed or not available in PATH -[8929] Failed to execute script docker-compose +[8929] Failed to execute script docker compose ``` Just change the entry in ~/.docker/config.json like this (credStore instead of credsStore), and you’re good to go: ```sh @@ -125,7 +121,7 @@ See [#8421](https://github.com/openfoodfoundation/openfoodnetwork/issues/8421) f ## Script Summary * docker/build(.ps1): This script builds the Docker containers specified for this app, seeds the database, and logs the screen output for these operations. After you use "git clone" to download this repository, run the docker/build script to start the setup process. -* docker/server(.ps1): Use this script to run this app in the Rails server. This script executes the "docker-compose up" command and logs the results. If all goes well, you will be able to view this app on your local browser at http://localhost:3000/. +* docker/server(.ps1): Use this script to run this app in the Rails server. This script executes the "docker compose up" command and logs the results. If all goes well, you will be able to view this app on your local browser at http://localhost:3000/. * docker/test(.ps1): Use this script to run the entire test suite. **Note limitation with system specs mentioned above**. * docker/qtest: Use this script to run the entire test suite in quiet mode. The deprecation warnings are removed to make the test results easier to read. * docker/run: Use this script to run commands within the Docker container. If you want shell access, enter "docker/run bash". To execute "ls -l" within the Docker container, enter "docker/run ls -l". diff --git a/docker/build-log b/docker/build-log index 7e7903c2a1..d2cbc2fa75 100755 --- a/docker/build-log +++ b/docker/build-log @@ -1,12 +1,12 @@ #!/bin/bash set +e -docker-compose down -v --remove-orphans +docker compose down -v --remove-orphans wait echo '###########################' -echo 'BEGIN: docker-compose build' +echo 'BEGIN: docker compose build' echo '###########################' -docker-compose build # Set up the Docker containers +docker compose build # Set up the Docker containers echo '##############################' -echo 'FINISHED: docker-compose build' +echo 'FINISHED: docker compose build' echo '##############################' diff --git a/docker/build-log.ps1 b/docker/build-log.ps1 index d3eed93e3a..15139fe4d8 100644 --- a/docker/build-log.ps1 +++ b/docker/build-log.ps1 @@ -1,5 +1,5 @@ Write-Host "Docker cleaning: remove old containers" -ForegroundColor Blue -docker-compose.exe down -v --remove-orphans +docker compose down -v --remove-orphans Write-Host "Docker build: set up the docker containers" -ForegroundColor Blue -docker-compose.exe build +docker compose build Write-Host "Docker build finished" \ No newline at end of file diff --git a/docker/cop b/docker/cop index 2df10f3522..739947d514 100755 --- a/docker/cop +++ b/docker/cop @@ -3,9 +3,9 @@ # This script runs RuboCop. echo '-------------------------------------------------' -echo 'BEGIN: docker-compose run web bundle exec rubocop' +echo 'BEGIN: docker compose run web bundle exec rubocop' echo '-------------------------------------------------' -docker-compose run web bundle exec rubocop +docker compose run web bundle exec rubocop echo '-----------------------------------------------' -echo 'END: docker-compose run web bundle exec rubocop' +echo 'END: docker compose run web bundle exec rubocop' echo '-----------------------------------------------' diff --git a/docker/cop.ps1 b/docker/cop.ps1 index 497db04d33..68123b341e 100644 --- a/docker/cop.ps1 +++ b/docker/cop.ps1 @@ -1,4 +1,4 @@ # This script runs RuboCop Write-Host "bundle exec rubocop : runs rubocop" -ForegroundColor Blue -docker-compose.exe run web bundle exec rubocop \ No newline at end of file +docker compose run web bundle exec rubocop \ No newline at end of file diff --git a/docker/qtest-log b/docker/qtest-log index 49389a5e75..72c96cdeff 100755 --- a/docker/qtest-log +++ b/docker/qtest-log @@ -1,17 +1,17 @@ #!/bin/bash echo '--------------------------------------------------------------' -echo 'BEGIN: docker-compose run web bundle exec rake db:test:prepare' +echo 'BEGIN: docker compose run web bundle exec rake db:test:prepare' echo '--------------------------------------------------------------' -docker-compose run web bundle exec rake db:test:prepare +docker compose run web bundle exec rake db:test:prepare echo '------------------------------------------------------------' -echo 'END: docker-compose run web bundle exec rake db:test:prepare' +echo 'END: docker compose run web bundle exec rake db:test:prepare' echo '------------------------------------------------------------' echo '--------------------------------------' echo 'BEGIN: running test suite (quiet mode)' echo '--------------------------------------' -docker-compose run web bundle exec rspec spec | grep -v 'DEPRECATION WARNING' | grep -v 'Post.includes(:comments)' | grep -v 'Currently, Active Record recognizes the table in the string' | grep -v "If you don't rely on implicit join references" +docker compose run web bundle exec rspec spec | grep -v 'DEPRECATION WARNING' | grep -v 'Post.includes(:comments)' | grep -v 'Currently, Active Record recognizes the table in the string' | grep -v "If you don't rely on implicit join references" echo '------------------------------------' echo 'END: running test suite (quiet mode)' echo '------------------------------------' diff --git a/docker/run b/docker/run index f5f0bf870a..51e7c77105 100755 --- a/docker/run +++ b/docker/run @@ -2,7 +2,7 @@ set -e -# Use this script to execute commaands in the Docker container. +# Use this script to execute commands in the Docker container. # Example: To run the "ls -l" command in the Docker container, enter the command "docker/run ls -l". function cleanup { @@ -12,11 +12,11 @@ function cleanup { # ignore errors set +e - docker-compose down + docker compose down exit $code } trap cleanup EXIT -docker-compose run web $@ +docker compose run web $@ diff --git a/docker/seed b/docker/seed index 7e02a16810..c594dc4302 100755 --- a/docker/seed +++ b/docker/seed @@ -3,25 +3,25 @@ # This is the data seeding script. echo '-------------------------------------------------------' -echo 'BEGIN: docker-compose run web bundle exec rake db:reset' +echo 'BEGIN: docker compose run web bundle exec rake db:reset' echo '-------------------------------------------------------' -docker-compose run web bundle exec rake db:reset +docker compose run web bundle exec rake db:reset echo '-----------------------------------------------------' -echo 'END: docker-compose run web bundle exec rake db:reset' +echo 'END: docker compose run web bundle exec rake db:reset' echo '-----------------------------------------------------' echo '--------------------------------------------------------------' -echo 'BEGIN: docker-compose run web bundle exec rake db:test:prepare' +echo 'BEGIN: docker compose run web bundle exec rake db:test:prepare' echo '--------------------------------------------------------------' -docker-compose run web bundle exec rake db:test:prepare +docker compose run web bundle exec rake db:test:prepare echo '------------------------------------------------------------' -echo 'END: docker-compose run web bundle exec rake db:test:prepare' +echo 'END: docker compose run web bundle exec rake db:test:prepare' echo '------------------------------------------------------------' echo '--------------------------------------------------------------' -echo 'BEGIN: docker-compose run web bundle exec rake ofn:sample_data' +echo 'BEGIN: docker compose run web bundle exec rake ofn:sample_data' echo '--------------------------------------------------------------' -docker-compose run web bundle exec rake ofn:sample_data +docker compose run web bundle exec rake ofn:sample_data echo '------------------------------------------------------------' -echo 'END: docker-compose run web bundle exec rake ofn:sample_data' +echo 'END: docker compose run web bundle exec rake ofn:sample_data' echo '------------------------------------------------------------' diff --git a/docker/seed.ps1 b/docker/seed.ps1 index edd67aaa63..8771bd3208 100644 --- a/docker/seed.ps1 +++ b/docker/seed.ps1 @@ -4,10 +4,10 @@ # - seed the database with sample data Write-Host "bundle exec rake db:reset : reset the dev and test databases" -ForegroundColor Blue -docker-compose.exe run web bundle exec rake db:reset +docker compose run web bundle exec rake db:reset Write-Host "bundle exec rake db:test:prepare : prepare the database" -ForegroundColor Blue -docker-compose.exe run web bundle exec rake db:test:prepare +docker compose run web bundle exec rake db:test:prepare Write-Host "bundle exec rake ofn:sample_data : seed the database with sample data" -ForegroundColor Blue -docker-compose.exe run web bundle exec rake ofn:sample_data \ No newline at end of file +docker compose run web bundle exec rake ofn:sample_data \ No newline at end of file diff --git a/docker/server-log b/docker/server-log index 08f0d3487e..683d260f03 100755 --- a/docker/server-log +++ b/docker/server-log @@ -2,8 +2,8 @@ set +e echo '########################' -echo 'BEGIN: docker-compose up' +echo 'BEGIN: docker compose up' echo '########################' echo 'View this app in your web browser at' echo 'http://localhost:3000/' -docker-compose up +docker compose up diff --git a/docker/server.ps1 b/docker/server.ps1 index 40c6f7a546..d57f37f995 100644 --- a/docker/server.ps1 +++ b/docker/server.ps1 @@ -1,6 +1,6 @@ # This script launches the whole stack of containers (web server, database, webpack, redis, etc.) $DateTime=Get-Date -Format "yyyyMMdd-HHmmss" -Write-Host "Docker-compose up: launches the whole stack of containers" -ForegroundColor Blue -docker-compose.exe up -d > log/server-$DateTime.log 2>&1 -Write-Host "Docker-compose up finished : View this app in your web browser at http://localhost:3000/" -ForegroundColor Blue \ No newline at end of file +Write-Host "Docker compose up: launches the whole stack of containers" -ForegroundColor Blue +docker compose up -d > log/server-$DateTime.log 2>&1 +Write-Host "Docker compose up finished : View this app in your web browser at http://localhost:3000/" -ForegroundColor Blue \ No newline at end of file diff --git a/docker/test b/docker/test index 212df0f277..bc6da82f5d 100755 --- a/docker/test +++ b/docker/test @@ -7,17 +7,17 @@ set -e DATE=`date +%Y%m%d-%H%M%S-%3N` echo '--------------------------------------------------------------' -echo 'BEGIN: docker-compose run web bundle exec rake db:test:prepare' +echo 'BEGIN: docker compose run web bundle exec rake db:test:prepare' echo '--------------------------------------------------------------' -docker-compose run web bundle exec rake db:test:prepare 2>&1 | tee log/test-prepare-$DATE.log +docker compose run web bundle exec rake db:test:prepare 2>&1 | tee log/test-prepare-$DATE.log echo '------------------------------------------------------------' -echo 'END: docker-compose run web bundle exec rake db:test:prepare' +echo 'END: docker compose run web bundle exec rake db:test:prepare' echo '------------------------------------------------------------' echo '----------------------------------------------------' -echo 'BEGIN: docker-compose run web bundle exec rspec spec' +echo 'BEGIN: docker compose run web bundle exec rspec spec' echo '----------------------------------------------------' -docker-compose run web bundle exec rspec --no-color spec 2>&1 | tee log/test-rspec-$DATE.log +docker compose run web bundle exec rspec --no-color spec 2>&1 | tee log/test-rspec-$DATE.log echo '--------------------------------------------------' -echo 'END: docker-compose run web bundle exec rspec spec' +echo 'END: docker compose run web bundle exec rspec spec' echo '--------------------------------------------------' \ No newline at end of file diff --git a/docker/test.ps1 b/docker/test.ps1 index f5a1bf958c..e049dcea30 100644 --- a/docker/test.ps1 +++ b/docker/test.ps1 @@ -4,6 +4,6 @@ $DateTime=Get-Date -Format "yyyyMMdd-HHmmss" Write-Host "bundle exec rake db:test:prepare : prepare the database for rspec tests" -ForegroundColor Blue -docker-compose.exe run web bundle exec rake db:test:prepare > log/test-prepare-$DateTime.log 2>&1 +docker compose run web bundle exec rake db:test:prepare > log/test-prepare-$DateTime.log 2>&1 Write-Host "bundle exec rspec spec : launch the rspec tests" -ForegroundColor Blue -docker-compose.exe run web bundle exec rspec spec > log/test-rspec-$DateTime.log 2>&1 \ No newline at end of file +docker compose run web bundle exec rspec spec > log/test-rspec-$DateTime.log 2>&1 \ No newline at end of file