drupal-graphql / drupal-decoupled-app

Decoupled Drupal demo application based on React, GraphQL and Apollo including server-side rendering.
MIT License
311 stars 76 forks source link

Automate start/stop process #391

Closed cjgratacos closed 6 years ago

cjgratacos commented 7 years ago

It will be excellent to have a simple bash file with a set commands that would automate the startup and stop process of the environment.

Oversimplified example on a Mac and Linux: filename: process.sh


#!/usr/bin/env bash

# Validate tools are installed
if [ $(which composer) == '' ]; then
  echo -e "Composer is not installed"
  exit 1;
fi

if [ $(which yarn) == '' ]; then
  echo -e "Yarn is not installed"
  exit 1;
fi

if [ $(which docker-compose) == '' ]; then
  echo -e "Docker Compose is not installed"
  exit 1;
fi

if [ $(which pygmy) == '' ]; then
  echo -e "Pygmy is not installed"
  exit 1;
fi

# Simple wrapper functions
function install_backend() {
  cd backend
  composer install
  cd  ../
}

function install_frontend() {
  cd frontend
  yarn install
  cd ../
}

function start() {
  install_backend
  install_frontend
  pygmy up
  docker-compose up -d

}

function stop() {
  pygmy down
  docker-compose down
}

function nuke() {
  stop
  docker rm $(docker ps -aq)
  docker rmi $(docker images -aq)
  rm -rf frontend/node_modules
  rm -rf backend/vendor
}

$@```

and it gets called with:
- `./process.sh start` // Start Process
- `./process.sh stop` // Stop Process
- `./process.sh nuke` //  Nuke All
fubhy commented 6 years ago

Good suggestion, but that would take quite a bit more effort than what we have here in your comment. I am not sure if it is worth the effort.

Also a few remarks regarding the script that you posted: stop/down on docker-compose are not identical. Down kills the entire thing and drops the database, etc. - Stop just halts it. So you shouid be using "pygmy stop" and "docker-compose stop" instead.

Installing the backend should happen inside the container. So composer install should run within the container. Why? Because some dependencies care about the used php version and will have a different result if your host php version is different than the one inside the container. Also, some people (me) simply don't have php outside of docker :).