Backend Installation

Step-by-step guide to setup Avia Commerce locally for development and contribution.

Setup using docker

Pre-requisites

Docker

  • Docker version 18.06.1 or higher is required.

Setting Up the development environment

Dockerfile

  • Dockerfile for development environment is Dockerfile-dev in config/docker/dev directory.
  • Add values of all the environment variables in Dockerfile-dev.
  • Environment variables are those which have ENV written before them. Dummy values are already assigned to them.

Docker Compose File

  • The docker compose file is docker-compose-dev.yml in config/docker/dev directory.
  • Docker Compose file has db service for postgres database container.
  • Add hostname equal to postgres service in apps/snitch_core/config/dev.exs file which is db in our case.
  config :snitch_core, Snitch.Repo,
    adapter: Ecto.Adapters.Postgres,
    username: "postgres",
    password: "postgres",
    database: "snitch_dev",
    hostname: "db",
    pool_size: 10

Docker commands to run the containers

Below command will

  • download all the required images
  • run containers using them
  • build aviacommerce webapp image and run it in a container

    > docker-compose -f config/docker/dev/docker-compose-dev.yml up --build

After all the containers are up and running and the logs show localhost:4000 as available, click on [http://localhost:4000][15]

Manual Setup

Pre-requisites

Elixir

  • Avia Commerce runs on Elixir 1.7+

    • Install Elixir
    • Check elixir -v to make sure it is 1.7 or higher.
    • For version management we love asdf a lot.

Hex

  • Installing Hex Package Manager

    • mix local.hex
    • To check the version mix hex.info

Postgres

  • At present Avia Commerce has been fully tested and exploited only on Postgres so make sure to have postgres 9.5 or higher.

    • Installation
    • To check run psql and see the version in the prompt.

Node

  • Installing NodeJs
  • The phoenix application in Avia Commerce uses brunch.io for asset management. Brunch uses npm to install dependencies and npm requires node.js
  • Though phoenix suggests version node 5.0.0 or higher but to avoid any unwanted issues we would suggest v 9.11.0 or higher.

Wkhtmltopdf

  • wkhtmltopdf is a command line tool to render HTML into PDF. Used in generating pdf invoices. Download here.

Elasticsearch

Repo

You can find all the repositories related to Avia Commerce here.

We need to clone the avia repository on our local.

To clone this repo, follow the instructions given in the GitHub help on Cloning a repository, and choose one of the following submodule-cloning techniques:

  • Clone this repo and its submodule at the same, use the —recurse-submodules option: git clone --recurse-submodules https://github.com/aviacommerce/avia.git

  • If you’ve already cloned this repo without its submodule, then run this command from the repo root: git submodule update --init --remote

IMPORTANT: Whenever you update your repo, update the submodule as well:
git pull; git submodule update --init --remote

Setting up the Development Environment

Setting up the system environment variables

  • Create a copy of the env/example.env

    > cp env/example.env env/local.env

    The env file has keys, secrets and paths required by application to run. After putting all the details for different keys, source it.

    > source env/local.env

Image Upload Setup

The default configuration to store uploaded images on development environment is local storage.

Setting up for image upload on S3 \TODO

Configuring Postgres

To setup the database we have to modify /apps/snitch_core/config/dev.exs.
The default setup for dev is.

  config :snitch_core, Snitch.Repo,
    adapter: Ecto.Adapters.Postgres,
    username: "postgres",
    password: "postgres",
    database: "snitch_dev",
    hostname: "localhost",
    pool_size: 10

Replace the username and the password field with your local credentials for postgres. You can also change the database field to a name of your choice.

Application Dependencies

From the root of the project run

> mix deps.get

This will install all the dependencies for the project.

Setting Application Database

If you have already configured the database you can go ahead with steps mentioned below, otherwise follow Configuring Postgres.

  • Move in to the snitch core directory

    > cd apps/snitch_core
  • From the root of snitch_core

    • Create Database

      > mix ecto.create
    • Migrate the Database

      > mix ecto.migrate
    • Seed Database

      > mix run priv/repo/seed/seeds.exs
    • Create sample data

      > mix ecto.load.demo

Setting Elasticsearch Indexing

  • keep elasticsearch running on port 9200 (if another port, then config that in local.env)
  • Activate atleast one product in the admin panel, so that it is ready to be indexed. Variants need to be activated from options tab.
  • From root

    > mix cmd --app snitch_core mix elasticsearch.build products --cluster Snitch.Tools.ElasticsearchCluster

Setting up Assets

The admin application in Avia Commerce is phoenix application with html.
To setup the assets:

    > cd apps/admin_app/assets
    > npm install

Running the server

From the project root

> iex -S mix phx.server

This will run two servers one for the admin application and the api application server.

Browser Admin Interface

To run the user interface you will have to go through the frontend installation.

in case you get elm-make command not found error on OS X from the project root:

yarn global add elm@0.18.0 && elm-package install -y

and then type this:

cd apps/admin_app/assets && yarn install && cd elm && elm-package install --yes

this will install old version of elm compatibile with the project

Running Tests

To run all the tests from your project root run the command

> mix test

You can also run the tests of individual applications from the root of those applications. e.g. to run tests of core

> cd apps/snitch_core
> mix test