diff --git a/README.md b/README.md index f6357743..fdcd132c 100644 --- a/README.md +++ b/README.md @@ -33,13 +33,16 @@ We recommend using `rbenv`. `cp env.example .env` -2. Start basic services (recommended) +2. Copy the local development docker overrides: + `cp compose.override.local.yml compose.override.yml` + +3. Start basic services (recommended) In a new terminal window do: - `docker-compose up app db` + `docker compose up app db` - See the `docker-compose.yml` file `depends_on:` section to see which containers depend on which. + See the `compose.yml` file `depends_on:` section to see which containers depend on which. Available containers: * `app` - Rails app @@ -54,25 +57,25 @@ We recommend using `rbenv`. Start ALL of them (not recommended) with: - `docker-compose up` + `docker compose up` -3. (OPTIONAL) Start Cassandra cluster of 3 nodes +4. (OPTIONAL) Start Cassandra cluster of 3 nodes If you want to start Kairos with 3 Cassandra cluster with 3 nodes: - * Uncomment the other 2 cassandras in `docker-compose.yml` file + * Uncomment the other 2 cassandras in `compose.yml` file * Edit the file `scripts/conf/kairosdb.properties` and change the following line: `kairosdb.datastore.cassandra.cql_host_list=cassandra-1` - `docker-compose up kairos cassandra-1 cassandra-2 cassandra-3` + `docker compose up kairos cassandra-1 cassandra-2 cassandra-3` -4. Create the database (first time only) +5. Create the database (first time only) If you need to perfom many operations, it might be better to `bash` into the container: - `docker-compose exec app bash` + `docker compose exec app bash` and from here you can do @@ -82,13 +85,29 @@ We recommend using `rbenv`. `bin/rails db:seed` - Or you can run them all at once with: `docker-compose exec app bin/rails db:setup` + Or you can run them all at once with: `docker compose exec app bin/rails db:setup` -5. Removing everything +6. Removing everything Remove all containers + data volumes with: - `docker-compose down -v` + `docker compose down -v` + +## Running the tests on a local docker container: + +_(I'm not 100% clear why step (3) is needed, but for some reason the DATABASE_URL overrides the test database details in database.yml which causes problems)_ + +1. Make sure you're running the app and db containers as above: + `docker compose up app db` + +2. In another terminal, get a shell within the app container: + `docker compose exec app bash` + +3. Within that shell, unset the DATABASE_URL environment variable: + `unset DATABASE_URL` + +4. Finally, run the tests (within that shell)! + `bundle exec bin/rake spec` ## Deploying @@ -96,8 +115,8 @@ We recommend using `rbenv`. 1. SSH into the server 1. `git pull` -1. `docker-compose build` -1. `docker-compose up -d` +1. `docker compose build` +1. `docker compose up -d` ## Cassandra diff --git a/docs/mqtt.md b/docs/mqtt.md index af298c93..e5b79289 100644 --- a/docs/mqtt.md +++ b/docs/mqtt.md @@ -12,7 +12,7 @@ The new system makes use of EMQ Shared Subscription system with Load balancing. MQTT host address is held in `.env` under the `ENV["MQTT_HOST"]` variable. Although it must be provided for `'production'`, `127.0.0.1` is set by default on `'test'` and `'development'` environments if not specified. -> NOTE: It is required defining `ENV["MQTT_HOST"]` and `ENV["MQTT_CLIENT"]` for `production` as an exception will be thrown at server startup otherwise. +> NOTE: It is required defining `ENV["MQTT_HOST"]` and `ENV["MQTT_CLIENT"]` for `production` as an exception will be thrown at server startup otherwise. ## End-points @@ -57,7 +57,7 @@ Devices can also publish to the topic `device/sck/device_token:/readings/raw` wi * Messages must be published using QoS (Quality of Service) of 1. -## Development and test +## Development and test ### Working with MQTT locally (no Docker) @@ -85,7 +85,7 @@ The following will send a message from the `app` container to the `mqtt` contain 2. Access the rails console inside the `app` container: - `docker-compose exec app bin/rails console` + `docker compose exec app bin/rails console` 3. Send a message to the `test` topic: diff --git a/scripts/deploy.sh b/scripts/deploy.sh index b4f9fdef..64358441 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -1,13 +1,13 @@ #!/bin/sh # Always pull from master? What if staging should deploy 'dev' branch? git pull origin master; -docker-compose pull auth push; +docker compose pull auth push; # Accept containers as params. Supports starting only 'app db' f.x. -docker-compose build && docker-compose up -d $@ +docker compose build && docker compose up -d $@ # Do we want to auto migrate? # For now, we only check if migration is needed -docker-compose exec app bin/rails db:migrate:status -#docker-compose exec app bin/rails db:migrate +docker compose exec app bin/rails db:migrate:status +#docker compose exec app bin/rails db:migrate echo $(date) $(git rev-parse HEAD) >> deploy_history.txt diff --git a/scripts/docker_backup_db.sh b/scripts/docker_backup_db.sh index 931b046b..fe6ae699 100755 --- a/scripts/docker_backup_db.sh +++ b/scripts/docker_backup_db.sh @@ -5,5 +5,5 @@ if ! [[ $1 ]]; then exit fi -#docker exec -i $(docker-compose ps -q db) pg_dump -Upostgres $1 > dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql +#docker exec -i $(docker compose ps -q db) pg_dump -Upostgres $1 > dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql docker exec -i smartcitizen-api_db_1 pg_dump -Upostgres $1 > backup/dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql diff --git a/scripts/docker_restore_db.sh b/scripts/docker_restore_db.sh index 923ce61a..bc9c1b34 100755 --- a/scripts/docker_restore_db.sh +++ b/scripts/docker_restore_db.sh @@ -5,4 +5,4 @@ if ! [[ $1 ]]; then exit fi -docker exec -i $(docker-compose ps -q db) psql -Upostgres $1 < dump_latest.sql +docker exec -i $(docker compose ps -q db) psql -Upostgres $1 < dump_latest.sql