Skip to content

1instinct/dna-admin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DOCKER SETUP ✻

This repo is using Spree 4.2.4

Build

This should only have to be done once, or whenever the Gemfile is updated.

First try this:

./docker-build.sh

The manual way:

docker-compose build

Create Containers

docker-compose up

DNA Admin should now be available at localhost:8080, but it probably needs to be set up first.

Set up system

In a new terminal run:

docker-compose exec web rails db:create db:schema:load db:migrate &&
docker-compose exec -e ADMIN_EMAIL=spree@example.com -e ADMIN_PASSWORD=spree123 web rails db:seed &&
docker-compose exec web rails spree_sample:load &&
docker-compose restart

OPTIONAL: Create a new admin user. This can be used to reset the admin user also:

docker-compose exec web rails spree_auth:admin:create

default is:

email: spree@example.com

password: spree123

Reset DB

This will reset the existing database back to blank.

docker-compose exec web rails db:reset railties:install:migrations db:migrate spree_sample:load db:seed

You could also blow away all the DB files. WARNING! You'll have to start the install over again if you do this.

sudo rm -rf tmp/db

Rails Console

docker exec -it dna-admin_web_1 bin/rails console

Extensions

The system uses 3 spree extensions

  • spree_reffiliate (Thanks @Gaurav2728) github
  • spree_loyalty_points (Thanks @Gaurav2728) github
  • spree_static_content github
  • spree_digital github
  • spree_promo_users_codes github

Each one is installed after spree, with it's own migrations generated using a specific bundle exec rails g command, which can be found on the README of the github page for each project. This only needs to be done once after spree is installed or upgraded.

CLI Scripts

./tools/docker-scripts.sh reload_db

Swagger UI

Scripts

  1. Generate Affiliate Codes for Existing Users: bundle exec rake reffiliate:generate
  2. Create or reset a New Admin User: docker-compose exec web rails spree_auth:admin:create
  3. Load Spree sample data & seed data: rake db:seed && rails spree_sample:load

Deploy

This uses heroku ruby buildpack on the heroku-20 stack. The master branch on github is hooked in to the deployment.

Heroku

  1. Create a new pipeline & app
  2. Add Postgres: heroku addons:create heroku-postgresql:hobby-dev
  3. Grab ENV vars from another app: heroku config -s -a dna-admin-staging > config.txt
  4. Grab the DB creds from <heroku.com>, add them to config.txt
  5. Edit other vars locally
  6. Upload vars to app: cat config.txt | tr '\n' ' ' | xargs heroku config:set -a dna-admin-staging
  7. Set stack: heroku stack:set heroku-18 -a dna-admin-staging
  8. Set buildpack: heroku buildpacks:add heroku/ruby
  9. Setup DB: heroku run rake db:schema:load db:migrate -a dna-admin-staging
  10. Seed DB: heroku run -a dna-admin-staging rake db:seed
  11. Load Sample Data: heroku run -a dna-admin-staging rake spree_sample:load
  12. Asset Precompile: heroku run -a dna-admin-staging rake assets:precompile

Alternate (container) deploy:

  1. ./docker-build.sh
  2. heroku stack:set container -a dna-admin-prod
  3. heroku container:push dna-admin-web-1 -a dna-admin-prod
  4. heroku container:release web -a dna-admin-prod
  5. heroku config:set SECRET_KEY_BASE=$(docker-compose exec dna-admin-web-1 rails secret) -a kry-admin-prod

Git: https://github.com/POL-Clothing/pol-admin

Testing Production Settings

To test the production settings locally (used to test things like the S3 buckets for active storage), you need to set environment variables directly in the docker-compose.yml file. The production environment is configured to NOT use .env files.

To do this, apply the following patch to docker-compose.yml (after filling in real values for the keys and bucket name):

+++ docker-compose.yml  2021-06-02 10:51:03.267414021 -0400
@@ -16,4 +16,10 @@
     depends_on:
       - db
     environment:
-      DATABASE_URL: postgres://postgres:password@db:5432/dna_admin_development
+      DATABASE_URL: postgres://postgres:password@db:5432/dna_admin_production
+      RAILS_ENV: production
+      AWS_REGION_NAME: us-west-1
+      AWS_BUCKET_NAME:
+      AWS_ACCESS_KEY_ID:
+      AWS_SECRET_ACCESS_KEY:
+      RAILS_SERVE_STATIC_FILES: 1

Keeping Your Code Updated:

When there are lots of active changes occuring on this repo, make sure to regularly:

  1. Commit (or stash) your local changes on your branch
  2. git fetch origin
  3. git checkout main
  4. git pull origin main
  5. git checkout <your_branch>
  6. git merge main
  7. Fix merge conflicts (if any)
  8. git add .
  9. git commit -m 'merge in latest main'

Done! …now you will be up-to-date with latest code. Do this before you submit your PR, and you can be sure it will be a clean merge.

http://localhost:8080/apidocs/swagger_ui Make sure to change the port that the UI is expecting in the search bar

TODO

Other things we may need to cover:

  1. Ruby version

  2. System dependencies

  3. Configuration

  4. Database creation

  5. Database initialization

  6. How to run the test suite

  7. Services (job queues, cache servers, search engines, etc.)

  8. Deployment instructions

About

Spree Commerce but better

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 11