4.0.7 • Published 4 years ago

inspira-cli v4.0.7

Weekly downloads
1
License
ISC
Repository
-
Last release
4 years ago

INSPIRA-CLI

Command line for creating shopify node apps skeletons.

HOW TO INSTALL

npm install -g inspira-cli

HOW TO BUILD A READY TO WORK PROJECT

inspira-cli <project_name_without_spaces>

Project decription: ....
App scopes comma separated (ex: write_orders,read_customers):   ...
Shopify Api Key: ...
Shopify Api Secret: ...
App url: ...
Store domain url (ex: mystore.myshopify.com): ...
Remote server: ...

Environment variables

There are 3 files generated. The .env will be the one used in local environment. The .env.pipeline will be used when running tests and .env.prod will be used when app gets deployed.

NOTE MongoDB ip needs to be changed

Log files

Log files are accessible after been log in. There 2 base log files that are rolling every day. The first log is where will appear every log we place in the App. The second one will only contain errors.

Info log

  • /admin/logs/info/show?date=YYYY.dd.mm
  • /admin/logs/info/reset?date=YYYY.dd.mm

Error log

  • /admin/logs/error/show?date=YYYY.dd.mm
  • /admin/logs/error/reset?date=YYYY.dd.mm

PROJECT STRUCTURE

.
├── dist                         # Compiled files.
├── routes
    ├── AddShops.ts              # Handles routes for adding allowed shops.
    └── RegisterRoutes.ts        # Handles app installation routes.
├── service                 
    ├── Logger              
    ├── ShopifyTokenHandler      # Receives the token once app is installed and saves it to the DB.
    ├── DbService                # Handles connection with mongoDB.
    ├── ShopifyRestService.ts    # Handles rest servie for all shops installed.
    ├── ShopifyWebhookService.ts # Handles the creation of webhooks in shopify. By default creates the *app/unistalled* webhook.
    └── AllowedShops.ts          # Handles shops allowed to have the app installed.

├── src                          # Frontend code of the APP 
    ├── components               # REACT components.
    ├── css 
    ├── types                    # Typescript typings for the frontend code. 
    ├── app.dev.ts               # Shopify bridge for DEV environment.
    ├── app.pro.ts               # Shopify bridge for Production environment .
    ├── app.ts                   # Shopify bridge for local environment.
    ├── frontend.tsconfig.json   # Typescript config for frontend code.
    ├── index.tsx                # REACT entrypoint.
    ├── webpack.config.js       # Webpack confing for building frontend code.
    └── services                 # Services for REACT components.
├── ansible                      # Ansible configuration for autodeploy to remote server.
    ├── deploy.yml               # Steps to run into remote server.
    └── hosts                    # Remote server connection configuration.
├── views                        # PUG templates.
    ├── dashboard.pug            # APP Shopify dashboard.
    ├── storeManager.pug         # Our dashboard.
    ├── register.pug             # Page from where we can install the APP in other stores.
    └── login.pug                # Login page to get to our dashboard.
├── typings                      # And internal app typings.
├── logs                         # File rolling logging (every day file).
├── .env                         # Local variables.
├── .env.prod                    # production variables.
├── .env.dev                     # Developing variables for test APP.
├── .env.pipeline                # Test variables in bitbucket.
├── .gitignore                   # basic gitignore.
├── run.sh                       # Script that runs in remote server and deploys a new app version.
├── bitbucket-pipelines.yml      # Pipeline steps to run within bitbucket.
├── model
      └── shop.ts                # Model for shops with app installed / allowed.
├── index.ts                     # Node App entry point.
├── tsconfig.json                # COnfiguration for typescript code.
└── README.md

NOTE: Run command from the directory you want to have the project in.

REMOTE DEPLOY

Inspira command line interface builds a project with a CI pipeline integrated which needs to be configured in bitbucket repository and needs a remote server.

BUILD REMOTE SERVER INFRASTRUCTURE USING THE SETUP SH SCRIPT

Step 1.

  • Go to DigitalOcean and create a dropplet with one of the SSH keys that we have setup.

Step 2.

  • Go to DigitalOcean network tab and create 2 new subdomains, the live APP and the test APP domain. Examples: test-cellar-app.inspirasoftware.co.uk & cellar-app.inspirasoftware.co.uk
  • Make sure that the domain points to your Digital Ocean remote server. This can be done via the "Will Direct To" section; either set this to a ip of the server or select the server in the dropdown box.
  • Once done, use this website to check the domain is up, it might take some time to populate across the interwebs! https://mxtoolbox.com/SuperTool.aspx#

Step 3.

  • Access to the remote server and run the setup.
touch setup.sh
chmod 700 setup.sh
  • Copy the content from the file remoteserversetup.sh
  • Copy the file nginx.conf in the same directory.
  • Run the script to create a runing NGINX with a SSL Certificate installed with a mongo DOCKER Container running. The script does also create the ansible user needed while setting up the bitbucket pipeline.

NOTE: Always place the the live domain before the test one.

./setup.sh mongo=true <user> <password> -d live.appira.com test.appira.com

Check that NGINX is Running

BUILD REMOTE SERVER INFRASTRUCTURE BY HAND

  • Nginx. Installed in the server as normall ubuntu installation.
  • Docker. Install docker.
docker network create --subnet=172.18.0.0/16 inspira

MongoDB

We use docker to run Mongo. Mongo docker container is started using the following command:

docker run -p 27017:27017 --net inspira --ip 172.18.0.21 -v /mongo/db:/data/db -d mongo:3.4

ANSIBLE

Ansible is used to connect ssh from bitbucket to instant buy server in order to automatically deploy changes.

Ansible set up

Finish CI pipeline by following next steps:

  • Create a ansible user in remote server.

 
sudo useradd -m ansible
  • Create a key value pair in bitbucket pipeline settings.
  • Copy this public key to ~/.ssh/authorized_keys on the remote host.
  • Add know_hosts entry in the same bitbucket configuration screen, just below the generated key.
  • On remote host create another key value pair that will allow us to connect to bitbucket with read-only access. Do not add pass_phrase.

 
ssh-keygen
  • Copy the id_rsa public key to bitbucket repo within "Access keys" option
  • Check ansible hosts and deploy file to make sure keys are correctly placed.
  • Add key to ssh
eval `ssh-agent`; 
ssh-add /home/ansible/.ssh/id_rsa
  • Add ansible to docker group in remote host.
 
sudo groupadd docker
sudo gpasswd -a ansible docker

Docker installation In Ubuntu

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04

Nginx installation In Ubuntu

https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-16-04

Install a green certificate

https://certbot.eff.org/

SET UP A HEALTH CHECK

Step 1

Add your new App domain in the ssl-checker repository in both files index.ts and healthcheck.ts files.

Step 2

Push to master and wait for it to run the pipeline.

4.0.7

4 years ago

4.0.6

4 years ago

4.0.5

4 years ago

4.0.4

4 years ago

4.0.3

4 years ago

4.0.2

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.5.2

4 years ago

3.5.1

4 years ago

3.5.0

4 years ago

3.4.3

4 years ago

3.4.2

4 years ago

3.4.1

4 years ago

3.4.0

4 years ago

3.2.0

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.0.0

5 years ago

1.9.0

5 years ago

1.8.7

5 years ago

1.8.6

5 years ago

1.8.5

5 years ago

1.8.4

5 years ago

1.8.3

5 years ago

1.8.2

5 years ago

1.8.1

5 years ago

1.7.4

5 years ago

1.7.3

5 years ago

1.7.2

5 years ago

1.7.1

5 years ago

1.7.0

5 years ago

1.6.9

5 years ago

1.6.8

5 years ago

1.6.7

5 years ago

1.6.6

5 years ago

1.6.5

5 years ago

1.6.4

5 years ago

1.6.3

5 years ago

1.6.2

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.2

5 years ago

1.5.1

6 years ago

1.4.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago