# Local Run

`docker-compose -f docker-compose.yml up --build -d`

go to localhost:5000

# Deployment

Deployment happens manually right now (until AWS CodePipeline has been sorted out).

## Setting up in production (manually)

We host container image in AWS Elastic Container Registry), and spin up the container service in 
ECS (Elastic Container Service). To push images to ECR (and set up the service), you need to configure
your AWS access on your local machine. Either go edit `~/.aws/config` and `~/.aws/credentials` or 
run `aws configure` if setting up AWS credentials the first time. You can retrieve AWS key/secret from
AWS console, under IAM (Identity & Access Management).

### Create and tag image
1. While in data_processor dir, build container with `docker-compose build`

2. Find the image name with `docker images` and tag the image (it should be `mlflow_mlflow`)
        ```
        docker tag mlflow_mlflow 776891437216.dkr.ecr.eu-west-1.amazonaws.com/fansifter/mlflow
        ```
#### Push image to ECR (Elastic Container Registry)
1. Authenticate with ECR (make sure you have latest version of aws cli). It should say "Login succeeded"
    
    ```
    aws ecr get-login-password | docker login --username AWS --password-stdin 776891437216.dkr.ecr.eu-west-1.amazonaws.com
    ```
    
    If this worked for you, skip to step 2.
    
    If you have multiple AWS profiles configured locally, and have created on for fansifter, execute this instead: 
    
    ```
    aws ecr get-login-password --profile fansifter | \
    sudo docker login --username AWS --password-stdin 776891437216.dkr.ecr.eu-west-1.amazonaws.com
    ```

2. Push the container to ECR (`fansifter/mlflow` is the name of the *pre-created* container repository)
        ```
        docker push 776891437216.dkr.ecr.eu-west-1.amazonaws.com/fansifter/mlflow
        ```

[AWS ECR CLI Official Docs](https://docs.aws.amazon.com/AmazonECR/latest/userguide/getting-started-cli.html)

3. Build a new service in ECS web console, defining 3 environment variables for the container.
    TODO! this should be using CodePipeline to automatically deploy service when merged



# Tips 

1. Notice that you can avoid using sudo with docker if create docker group and add your user there: 
 
    ```
    sudo groupadd docker
    sudo gpasswd -a $USER docker
    ```
   
2. when params field varchar count is too small, run this: `ALTER TABLE public.params ALTER COLUMN value TYPE VARCHAR;`
