direct_delivery
===============

Vector code base setup instructions:

#### Clone Direct Delivery on your work machine

#### Create your directory

If you haven't done so already, run the [jenkins job to setup your own user directory on your squad server](https://pipeline.theorchard.io/job/dev-squad-box-setup/).
This will create a directory with your username and clone the orchard and api (VAPI) repositories (but not the direct_delivery repository).

If you prefer to instead work manually, then log on to your squad server
and create a directory using the root user

```shell
sudo mkdir html_{{username}}
sudo chown -R devorch:devorch html_{{username}}
```

#### Sync your local copy with devbox

Rsync your local copy to the devbox
`rsync -zrp direct_delivery/ devorch@vector.devorch.com:/var/www/html_{{username}}/direct_delivery`



#### Setup your IDE to sync with devbox

Using IntelliJ or PhpStorm, you can sync your local copy to the copy you made on the devbox. Generate a new ssh key using PEM format `ssh-keygen -m PEM -t rsa`
If you obtained access to the devbox using a standard SSH key and not the PEM one: do not override your existing key because that will make you update your Github key. Make a new key and then ask for systems to add this newly generated key to the list of keys to sync on the devbox. You can quickly test this by editing `~/.ssh/authorized_keys` on the devbox, but keep in mind that Chef will overwrite your changes to that file.

The following screenshots will show you what settings/configurations you will need for your IDE


The settings you to configure when to sync your local code changes to the devbox code
![PHP storm code sync options](https://github.com/theorchard/distro-wiki/blob/master/code-sync-options.png)

The settings you will need to enable phpstorm to use the right PHP executable
![PHP storm link local php](https://github.com/theorchard/distro-wiki/blob/master/linking-local-php.png)

The settings for configuring where your local code changes should sync to the devbox code
![PHP storm code sync options](https://github.com/theorchard/distro-wiki/blob/master/setup-sftp-sync.png)

Continuing on from the last step:
![PHP storm code sync options](https://github.com/theorchard/distro-wiki/blob/master/sync-setup-mapping.png) 

The setting to exclude syncing for your local vendor folder
![PHP storm code exclusion options](https://github.com/theorchard/distro-wiki/blob/master/sync-setup-exclusion.png)


#### Install required PHP version locally

Install PHP 5.6 on your local machine using homebrew

```shell
brew tap exolnet/homebrew-deprecated
brew install php@5.6
```



#### Configure settings and Install packages

Install packages using `composer up`
Edit your `composer.json` file and replace `vcs` with `git`

Copy and configure the `log.yml.shadow` file and set
* `sentry.options_or_dsn`: `https://426d67d71e644358a3442aa456e63b80:8c7664f78d25485980e447571f724700@app.getsentry.com/5387`
* `ows1_udp_handler.connectionString`: `udp://qa-fluentd-applications-udp.theorchard.io:5160`

Ask for kibana access from systems if you don't have it.

Edit the `public/.htaccess` file and on the first line set the `APPLICATION_ENV` to `development`
Edit the `application/configs/application.ini` file and set the `resources.doctrine.connection_string` and `resources.doctrine.dd_connection_string` to the relevant DB that you want to use.

#### Setup your host

Change the httpd.conf file to point `DocumentRoot` to your `direct_delivery` codebase on the devbox
copy one of the existing conf file in /etc/httpd
`sudo cp /etc/httpd/sites-available/{{some_existing_user}}.conf /etc/httpd/sites-available/{{your_username}}.conf`

Edit the newly created file and replace any values with your username and the path to your `direct_delivery` directory.
It should look like this

```xml
<VirtualHost *:80>
    ServerAdmin {{username}}@theorchard.com
    DocumentRoot /var/www/html_{{username}}/direct_delivery/public
    ServerName dd.{{username}}.vector.devorch.com

    RewriteEngine off
    <Directory /var/www/html_{{username}}/direct_delivery/public>
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
```

Symlink your file into the enabled sites:

```shell
cd /etc/httpd/sites-enabled
sudo ln -s ../sites-available/{{username}}.conf .
```

Restart Apache
`sudo systemctl restart httpd`

#### Testing to see if your direct_delivery is running correctly
Now if you hit the home page for direct delivery you should be able to see `I am the INDEX` text show up.

Alternatively, you can hit this endpoint:

`/asset/getassetlocation?upc=<upc>&physical_location_id=1&asset_type_ids=1&format=json`

which hits your direct_delivery service and queries the DB thus ensuring your direct_delivery service is running properly.

## Containerized Encoder Setup (BETA WIZ-1415)

### Setup

#### Github Token
To install some private packages, you need to be able to autheticate with Github.

* Create Github access token [here](https://github.com/settings/tokens) with all **repo** scope only.
* Create `auth.json` file
```
$ cp auth.json.shadow auth.json
```
* Add token in `auth.json` under `github.com` key.

#### Credentials

* Create `.env` file
```
$ cp .env.shadow .env
```
* Enter **dev** values in `.env` for
  * DD_USER
  * DD_PASS
  * AR_USER
  * AR_PASS
  * AWS_KEY_ID
  * AWS_ACCESS_KEY

#### AWS ECR Access

Install [ecr-credentials-helper](https://www.notion.so/AWS-Access-f841b9dd815d4443a80e96a86c92cd2f#ad5d3a529a7d41b299daa604c517ebf2) to automatically use your configured AWS credentials when pulling down ECR images.

### Build and Run

* Build and run
```
$ docker-compose up --build encoder
```
