Skip to content

Commit

Permalink
consistently use docker compose instead of docker-compose everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
timcowlishaw committed Dec 21, 2023
1 parent 504b1f5 commit eb2ff09
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 23 deletions.
47 changes: 33 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -82,22 +85,38 @@ 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

### Using Docker

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

Expand Down
6 changes: 3 additions & 3 deletions docs/mqtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:

Expand Down
8 changes: 4 additions & 4 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion scripts/docker_backup_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion scripts/docker_restore_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit eb2ff09

Please sign in to comment.