<commit_before># Development Setup Instructions
- [Docker](#docker)
- [Mac OS X / Mac OS](#mac-os-x)

## Docker

### What is Docker?
>Docker containers wrap a piece of software in a complete filesystem that contains everything needed
>to run: code, runtime, system tools, system libraries – anything that can be installed on a server.
>This guarantees that the software will always run the same, regardless of its environment.
[Docker - What is Docker?](https://www.docker.com/what-docker)

#### Installing Docker
The latest Docker downloads and setup instructions for your operating system can be found
in the [Docker downloads page](https://www.docker.com/products/docker).

### Getting Up and Running with Docker

Build the Bizport docker image:
```
$ docker-compose build
```

#### Preparing the Database
First, spin up the DB docker image:
```
$ docker-compose up db
```

Next, access the command line of the Bizport DB docker image:
```
$ docker exec -it bizport_db_1 /bin/bash
```

Switch to the `postgres` user:
```
$ su postgres
```

Create your dev and test databases at the command line with the postgres shortcut `createdb`:
```
$ createdb bizport_development
```

```
$ createdb bizport_test
```

Close/terminate your bash sessions.

Next, setup the database via rake: 
```
$ docker-compose run web rake db:setup
```

#### Loading Seed Data

There are two options for loading seed data: fixtures or a production database import. Fixtures are more portable if you're setting up on a computer without access to the production Heroku account. Importing direct from the Heroku account is likely to produce an environment with better production parity, and is the recommended approach.

##### Production Database Import
Heroku provides a database import feature. Because importing an entire database is a major operation, and has the potential to overwrite or destroy data, the command line utility has several warnings before it begins work.
First, access the command line of the Bizport DB docker image:
```
$ docker exec -it bizport_web_1 /bin/bash
```
Next, login to Heroku with your account credentials:
```
$ heroku
```
Then begin the database copy with:
```
$ heroku pg:pull DATABASE_URL bizport_development
```
Note that you may be prompted to drop your local database before pulling the new one. Also note that `DATABASE_URL` is the default name for the main DB URL of a Heroku application. If this doesn't work, you can use `heroku pg:info` to check the correct URL name for your database.

##### Fixtures
In order to load the `bizport` CMS fixtures, the CMS needs to have a `Site` object in the DB called `bizport` with which to associate the fixtures. To do this, open the Rails console and add a site object with the site name.
```
$ docker-compose run web bundle exec rails console
> Comfy::Cms::Site.create(identifier:'bizport')
```

Close/terminate the `web` image bash session.

Import fixtures. 

To *import* CMS fixtures: `heroku run bundle exec rake comfortable_mexican_sofa:fixtures:import FROM=bizport TO=bizport`
To *export* CMS fixtures: `heroku run bundle exec rake comfortable_mexican_sofa:fixtures:export FROM=bizport TO=bizport`

To copy CMS fixtures from remote to local: `docker-compose run web scp -r <username>@<host>:<path/to/app/folder>/db/cms_fixtures/bizport db/cms_fixtures/`

### Starting the Application

You should now be able to boot the application by running `docker-compose up` or `docker-compose up web` if the `db` container is already running. Visit `localhost:3000` to verify that everything is working. The homepage uses a blend of code and database content to render, and so is a fairly complete test that everything is set up correctly.

### Deploying to Heroku Container Registry and Runtime
Heroku's Container Registry and Runtime is a service specifically for deploying Docker containers. BizPort's docker-compose file specifies two containers, `web` and `db`, but Heroku will simply connect the `web` container to its hosted DB service, so we only need to deploy the `web` container.<commit_msg>Updated dev docs to document how to seed db from heroku using docker<commit_after># Development Setup Instructions
- [Docker](#docker)
- [Mac OS X / Mac OS](#mac-os-x)

## Docker

### What is Docker?
>Docker containers wrap a piece of software in a complete filesystem that contains everything needed
>to run: code, runtime, system tools, system libraries – anything that can be installed on a server.
>This guarantees that the software will always run the same, regardless of its environment.
[Docker - What is Docker?](https://www.docker.com/what-docker)

#### Installing Docker
The latest Docker downloads and setup instructions for your operating system can be found
in the [Docker downloads page](https://www.docker.com/products/docker).

### Getting Up and Running with Docker

Build the Bizport docker image:
```
$ docker-compose build
```

#### Preparing the Database
First, spin up the DB docker image:
```
$ docker-compose up db
```

Next, access the command line of the Bizport DB docker image:
```
$ docker exec -it bizport_db_1 /bin/bash
```

Switch to the `postgres` user:
```
$ su postgres
```

Create your dev and test databases at the command line with the postgres shortcut `createdb`:
```
$ createdb bizport_development
```

```
$ createdb bizport_test
```

Close/terminate your bash sessions.

Next, setup the database via rake: 
```
$ docker-compose run web rake db:setup
```

#### Loading Seed Data

There are two options for loading seed data: fixtures or a production database import. Fixtures are more portable if you're setting up on a computer without access to the production Heroku account. Importing direct from the Heroku account is likely to produce an environment with better production parity, and is the recommended approach.

##### Production Database Import
Heroku provides a database import feature. Because importing an entire database is a major operation, and has the potential to overwrite or destroy data, the command line utility has several warnings before it begins work.

First, access the command line of the Bizport DB docker image:
```
$ docker exec -it bizport_web_1 /bin/bash
```

Next, login to Heroku with your account credentials:
```
$ heroku
```

Afterward, create a new backup of the current state of the database:
```
$ heroku pg:backups capture --app bizport
```

Download the dump to the project delivery:
```
$ curl -o latest.dump `heroku pg:backups public-url --app bizport`
```

Next, access the command line of the Bizport DB docker image:
```
$ docker exec -it bizport_db_1 /bin/bash
```

cd to the `bizport` volume:
```
$ cd /bizport
```

Then restore from latest.dump with `pg_restore`:
```
$ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d bizport_development latest.dump
```

Note that you may be prompted to drop your local database before pulling the new one. If this doesn't work, you can use `heroku pg:info` to check the correct URL name for your database.

##### Fixtures
In order to load the `bizport` CMS fixtures, the CMS needs to have a `Site` object in the DB called `bizport` with which to associate the fixtures. To do this, open the Rails console and add a site object with the site name.
```
$ docker-compose run web bundle exec rails console
> Comfy::Cms::Site.create(identifier:'bizport')
```

Close/terminate the `web` image bash session.

Import fixtures. 

To *import* CMS fixtures: `heroku run bundle exec rake comfortable_mexican_sofa:fixtures:import FROM=bizport TO=bizport`
To *export* CMS fixtures: `heroku run bundle exec rake comfortable_mexican_sofa:fixtures:export FROM=bizport TO=bizport`

To copy CMS fixtures from remote to local: `docker-compose run web scp -r <username>@<host>:<path/to/app/folder>/db/cms_fixtures/bizport db/cms_fixtures/`

### Starting the Application

You should now be able to boot the application by running `docker-compose up` or `docker-compose up web` if the `db` container is already running. Visit `localhost:3000` to verify that everything is working. The homepage uses a blend of code and database content to render, and so is a fairly complete test that everything is set up correctly.

### Deploying to Heroku Container Registry and Runtime
Heroku's Container Registry and Runtime is a service specifically for deploying Docker containers. BizPort's docker-compose file specifies two containers, `web` and `db`, but Heroku will simply connect the `web` container to its hosted DB service, so we only need to deploy the `web` container.
{'fraction_non_alphanumeric': 0.08157064391726072, 'fraction_numerical': 0.0015192240271123057, 'mean_word_length': 4.728246318607765, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5751445', 'n_tokens_mistral': 2496, 'n_tokens_neox': 2261, 'n_words': 1173}