Commit daacaa9f authored by Emiliano Balbuena's avatar Emiliano Balbuena Committed by Brian Hatchet

Local stack tweaks

parent 5e2daac4
......@@ -22,6 +22,9 @@
# Declare files that will always have LF line endings on checkout.
*.pem eol=lf
*.sh eol=lf
*.cql eol=lf
containers/** eol=lf
# Denote all files that are truly binary and should not be modified.
*.png binary
......
......@@ -33,7 +33,7 @@ server {
port_in_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host nginx;
proxy_set_header Host localhost:8080;
proxy_set_header X-NginX-Proxy true;
proxy_pass $upstream;
proxy_redirect off;
......
version: "2.2"
services:
## EXTRA DEPENDENCY FOR WEB SERVER
nginx:
depends_on:
- front-live-server
## WEB APP
front-live-server:
build:
context: ./front/containers/live-server
dockerfile: ./Dockerfile
mem_limit: 2GB
depends_on:
- front-live-server-compiler
networks:
- app
volumes:
- ./front/:/var/www/Minds/front:cached
front-live-server-compiler:
build:
context: ./front/containers/live-server-compiler
dockerfile: ./Dockerfile
mem_limit: 2GB
networks:
- app
volumes:
- ./front/:/var/www/Minds/front:delegated
......@@ -22,42 +22,6 @@ services:
volumes:
- ./front/:/var/www/Minds/front:cached
## WEB APP
front-live-server:
build:
context: ./front/containers/live-server
dockerfile: ./Dockerfile
mem_limit: 2GB
depends_on:
- front-live-server-compiler
networks:
- app
volumes:
- ./front/:/var/www/Minds/front:delegated
front-live-server-compiler:
build:
context: ./front/containers/live-server-compiler
dockerfile: ./Dockerfile
mem_limit: 2GB
networks:
- app
volumes:
- ./front/:/var/www/Minds/front:delegated
# UNUSED (for now)
# - Disabled because docker complains if there's no dist/ folder
# front:
# # Static server
# build:
# context: ./front/dist
# dockerfile: ../containers/server/Dockerfile
# networks:
# - app
# volumes:
# - ./front/dist/:/dist:cached
## APP ENGINE
php-fpm:
......
@echo off
:: Clone the main repo
git pull
:: Setup the other repos
git clone https://github.com/Minds/front front
git clone https://github.com/Minds/engine engine
[CmdletBinding()]
Param(
[switch] $Ssh
)
Set-StrictMode -Version latest
$ErrorActionPreference = "Stop"
Push-Location $PSScriptRoot
function Exec
{
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
[Parameter(Position=1,Mandatory=0)][string]$errorMessage = ("Error executing command {0}" -f $cmd)
)
& $cmd
if ($lastexitcode -ne 0) {
Throw ("Exec: " + $errorMessage)
}
}
Try {
$RemoteRoot = "https://gitlab.com/minds"
If ($Ssh) {
$RemoteRoot = "[email protected]:minds"
}
Write-Host "Using $RemoteRoot"
# Fetch latest
Exec { git pull }
# Setup the other repos
Exec { git clone $RemoteRoot/front.git front --config core.autocrlf=input }
Exec { git clone $RemoteRoot/engine.git engine --config core.autocrlf=input }
Exec { git clone $RemoteRoot/sockets.git sockets --config core.autocrlf=input }
}
Catch {
Pop-Location
Exit 1
}
Finally {
Pop-Location
Exit 0
}
#!/usr/bin/env bash
set -e
usage () {
echo "Usage: init.sh [--ssh]"
}
# Argument parsing
ssh=
while [ "$1" != "" ]; do
case $1 in
--ssh ) ssh=1
;;
* ) usage
exit 1
esac
shift
done
#
REMOTE_ROOT="https://gitlab.com/minds"
if [ "$ssh" = "1" ]; then
REMOTE_ROOT="[email protected]:minds"
fi
#
cd "$(dirname "${BASH_SOURCE[0]}")"
# Clone the main repo
git pull
# Setup the other repos
git clone https://gitlab.com/Minds/front front
git clone https://gitlab.com/Minds/engine engine
git clone $REMOTE_ROOT/front front --config core.autocrlf=input
git clone $REMOTE_ROOT/engine engine --config core.autocrlf=input
git clone $REMOTE_ROOT/sockets sockets --config core.autocrlf=input
# Local Stack
## Requirements
- git
- docker 18 or higher, with docker-compose
- node 10.x or higher, with npm and npx
- port 8080 open
### Extra requirements for Windows
- Windows 10 Pro (needed for Docker)
- Any modern x86_64 multi-core CPU that supports virtualization.
- 16GB of RAM (of which around 7.5GB should be devoted to Docker VM on macOS and Windows).
- 3GB storage for Minds repositories and packages, and at least 20GB for Docker VM/Images.
- Internet connectivity (only needed for downloading and provisioning the stack).
### Software requirements
- Git
- Docker 18 or higher, with docker-compose
- Node.js 10.x or higher, with npm and npx
- Port 8080 open
#### Extra requirements for Windows
- Windows 10 Pro with Hyper-V enabled (for Docker)
- PowerShell
## Creating an alias
## Before installing
### Windows line endings
Git on Windows defaults `core.autocrlf` setting to `true`, which causes installation, provisioning and entry-point scripts to become corrupted with Windows-style line endings.
Before installing Minds, make sure you change it to `input` either globally **BEFORE** downloading the repositories (1); or by setting it when cloning (2).
(1): `git config --global core.autocrlf input`
(2): `git clone [repo] --config core.autocrlf=input`
If you already downloaded Minds repositories, you'll have to either download it again, or do a hard reset in all the repositories, as seen on https://stackoverflow.com/a/10118312.
You will get a warning every time your run the local stack if any of the repositories has the wrong `core.autocrlf` value.
## Run-from-anywhere aliases
This is an optional step, but all examples in this document will be using the alias.
### Linux/macOS
Add to your ~/.bashrc (or ~/.zshrc) file
```sh
alias minds=/path/to/minds/local/local
alias minds-front-build=/path/to/minds/local/front-build
alias minds-ssr-build=/path/to/minds/local/ssr-build
alias minds-ssr-serve=/path/to/minds/local/ssr-serve
export $MINDSROOT=/path/to/minds
alias minds=$MINDSROOT/local/local
alias minds-front-build=$MINDSROOT/local/front-build
alias minds-ssr-build=$MINDSROOT/local/ssr-build
alias minds-ssr-serve=$MINDSROOT/local/ssr-serve
```
After saving the profile script, restart your terminal windows.
### Windows
Open PowerShell and run
```powershell
......@@ -29,25 +54,28 @@ echo $profile
```
That command will output the location to your profile script. Edit it and add
```powershell
Set-Alias -Name minds -Value X:\Path\To\minds\local\local.ps1
Set-Alias -Name minds-front-build -Value X:\Path\To\minds\local\front-build.ps1
Set-Alias -Name minds-ssr-build -Value X:\Path\To\minds\local\ssr-build.ps1
Set-Alias -Name minds-ssr-serve -Value X:\Path\To\minds\local\ssr-serve.ps1
$env:MINDSROOT = 'X:\Path\To\minds'
Set-Alias -Name minds -Value $env:MINDSROOT\local\local.ps1
Set-Alias -Name minds-front-build -Value $env:MINDSROOT\local\front-build.ps1
Set-Alias -Name minds-ssr-build -Value $env:MINDSROOT\local\ssr-build.ps1
Set-Alias -Name minds-ssr-serve -Value $env:MINDSROOT\local\ssr-serve.ps1
```
After saving the profile script, restart your terminal windows.
## Preparing your OS
### Linux
- Nothing to do.
### macOS
- Setup Docker VM to have at least 6.5GB and it uses at leas 2 CPUs.
- Setup Docker VM to have at least 7.5GB and it uses at least 2 CPUs.
### Windows
- Setup Docker VM to have at least 6.5GB and it uses at leas 2 CPUs.
- Setup Docker VM to have at least 7.5GB and it uses at least 2 CPUs.
- Enable Shared Drives availability to the drive that has the Minds repository (https://docs.docker.com/docker-for-windows/#file-sharing).
## Installing Minds
> **Important!**
>
......@@ -60,6 +88,16 @@ Run
minds install
```
### Troubleshooting
#### Random errors when building or starting the Docker containers
Git might corrupted Docker container scripts line endings. [Read this](#windows-line-endings).
#### There are random ENOENT or EPERM errors when cleaning up or building the frontend app during install on Windows
Close any application that might be actively watching the folder, such as VSCode, TortoiseGit, etc. If it still fails, reboot your computer to release any rogue lock.
## Running
### Starting the containers
......@@ -91,24 +129,6 @@ minds rebuild
## Running the frontend stack
### Linux
#### App
Run
```sh
minds-front-build
```
#### SSR Server
SSR server runs inside two Docker containers: `front-live-server` and `front-live-server-compiler`.
To check out their activity, open a terminal in the `minds` directory and run
```sh
docker-compose logs -f --tail=40 front-live-server front-live-server-compiler
```
### macOS/Windows
#### App
Run
```sh
......
const yargs = require('yargs');
const getMissingDeps = require('./helpers/get-missing-deps');
const repoHealth = require('./helpers/repo-health');
return (async () => {
const missingDeps = await getMissingDeps();
......@@ -11,6 +12,8 @@ return (async () => {
return process.exit(1);
}
await repoHealth();
return yargs
.option('verbose', {
description: 'Verbose output',
......@@ -20,8 +23,8 @@ return (async () => {
description: 'Silent output',
boolean: true
})
.command('up', 'Start the containers', require('./commands/up'))
.command('down', 'Stop the containers', require('./commands/down'))
.command(['up', 'start'], 'Start the containers', require('./commands/up'))
.command(['down', 'stop'], 'Stop the containers', require('./commands/down'))
.command('restart', 'Restart the containers', require('./commands/restart'))
.command('rebuild', 'Rebuild the containers', require('./commands/rebuild'))
.command('install', 'Installs and provisions the compose stack', require('./commands/install'))
......
......@@ -10,6 +10,10 @@ module.exports.handler = async argv => {
renderer = 'silent'
}
if (process.platform === 'win32') {
console.log('\nWARNING: Close any tool that might be watching Minds folder (e.g. VSCode, TortoiseGit, etc.)\n');
}
const prompt = await prompts([
{
type: 'toggle',
......
......@@ -3,4 +3,4 @@ set -e
cd "$(dirname "${BASH_SOURCE[0]}")"
cd ../front && NODE_OPTIONS=--max_old_space_size=4096 npm run build:dev
cd ../front && NODE_OPTIONS=--max_old_space_size=4096 npm run build:dev -- --delete-output-path=false
Push-Location $PSScriptRoot\..\front
try {
$env:NODE_OPTIONS = '--max_old_space_size=4096'; npm run build:dev
$env:NODE_OPTIONS = '--max_old_space_size=4096'; npm run build:dev -- --delete-output-path=false
if ($LastExitCode -ne 0) {
throw "Something failed"
......
const exec = require('../lib/exec');
module.exports = async function() {
const getAutoCrLf = async dir => {
try {
const subprocess = await exec.in(dir, 'git', ['config', '--get', 'core.autocrlf']);
return (subprocess.stdout || '').trim().toLowerCase();
} catch (e) {
return false;
}
}
const badAutoCrLfValue = 'true';
const willCauseIssues = (await Promise.all([
getAutoCrLf(''),
getAutoCrLf('front'),
getAutoCrLf('engine'),
getAutoCrLf('sockets'),
])).some(autocrlf => autocrlf === badAutoCrLfValue);
if (willCauseIssues) {
process.stderr.write(
`\nWARNING: One or more repositories have 'core.autocrlf' set to '${badAutoCrLfValue}'. ` +
'This will cause issues with containerized scripts and provisioners. Please check ' +
'Minds Developers documentation.\n\n'
);
}
};
const exec = require('./exec');
let upstreamUrl;
let useFrontContainer;
let upstreamEndpoint;
switch (process.platform) {
case 'win32':
case 'darwin':
upstreamUrl = 'host.docker.internal:4200';
useFrontContainer = false;
upstreamEndpoint = 'host.docker.internal:4200';
break;
default:
upstreamUrl = 'front-live-server:4200';
useFrontContainer = true;
upstreamEndpoint = '$remote_addr:4200';
useFrontContainer = false;
break;
}
function buildDefaultArgs() {
const args = [
return [
'-f',
'docker-compose.yml',
'-f',
'docker-compose.with-phpspec.yml',
];
if (useFrontContainer) {
args.push(
'-f',
'docker-compose.with-front.yml'
);
}
return args;
];
}
function buildEnv() {
return {
UPSTREAM_ENDPOINT: upstreamUrl,
UPSTREAM_ENDPOINT: upstreamEndpoint,
};
}
......@@ -45,4 +34,4 @@ module.exports = function (...args) {
...buildDefaultArgs(),
...args
], buildEnv());
}
};
Push-Location $PSScriptRoot\..\front
try {
......
Push-Location $PSScriptRoot\..\front
try {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment