Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPII-4171: Initial implementation of gpii-windows-installer #1

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.vagrant
artifacts
node_modules
package-lock.json
provisioning/Chocolatey.ps1
provisioning/CouchDB.ps1
provisioning/Npm.ps1
provisioning/Provisioning.psm1
provisioning/couchdb-2.3.0.msi
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
# gpii-windows-installer
The official installer for the GPII on Windows

The official installer for the GPII on Windows.
This code produces msi installers based on a given set of artifacts.

At this moment, the code does the following:

1. Download and populate the artifacts
1. Create a build folder where the installer is going to be created
1. Run npm install on gpii-app
1. Create the electron package
1. Run MSBuild to create the installer

In addition to these, I need to finish implementing the logic for copying some files (wix merge modules, reset to standard file, etc) into specific folders.

## Running the code

The easiest way to run this code is from the VM that you can set up by running `vagrant up`
The resulting VM includes the required dependencies to perform the build process.

When the VM is ready, you can run `node devTest.js` and the installer will be created automatically.

Take into account that the build process may take some time (around 10 minutes).
34 changes: 34 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.require_version ">= 1.8.0"

# By default this VM will use 2 processor cores and 2GB of RAM. The 'VM_CPUS' and
# "VM_RAM" environment variables can be used to change that behaviour.
cpus = ENV["VM_CPUS"] || 2
ram = ENV["VM_RAM"] || 2048

Vagrant.configure(2) do |config|

config.vm.box = "inclusivedesign/windows10-eval-x64-Apps"
config.vm.guest = :windows

config.vm.communicator = "winrm"
config.winrm.username = "vagrant"
config.winrm.password = "vagrant"
config.vm.network :forwarded_port, guest: 3389, host: 3389, id: "rdp", auto_correct:true
config.vm.network :forwarded_port, guest: 5985, host: 5985, id: "rdp", auto_correct:true

config.vm.provider :virtualbox do |vm|
vm.gui = true
vm.customize ["modifyvm", :id, "--memory", ram]
vm.customize ["modifyvm", :id, "--cpus", cpus]
vm.customize ["modifyvm", :id, "--vram", "256"]
vm.customize ["modifyvm", :id, "--accelerate3d", "off"]
vm.customize ["modifyvm", :id, "--audio", "null", "--audiocontroller", "hda"]
vm.customize ["modifyvm", :id, "--ioapic", "on"]
vm.customize ["setextradata", "global", "GUI/SuppressMessages", "all"]
end

config.vm.provision "shell", path: "provisioning/Build.ps1", args: "-originalBuildScriptPath \"C:\\vagrant\\provisioning\\\""
end
46 changes: 46 additions & 0 deletions data/artifacts.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
// No outputPath, the output location is always c:/installer/gpii-app
"gpii-app": {
"type": "gpii.installer.artifact.githubRepoDownloader",
"options": {
"repo": "https://github.com/GPII/gpii-app",
"hash": "2befbfe96a58533a0954a39203dfc8a4b6b16bd5", // master
"output": "gpii-app"
}
},
// No outputPath, the output location is always c:/installer/
"gpii-wix-installer": {
"type": "gpii.installer.artifact.githubRepoDownloader",
"options": {
"repo": "https://github.com/GPII/gpii-wix-installer",
"hash": "b98474d53e2e5aa667ed610bb19414e56790593a",
"output": "gpii-wix-installer"
}
},
// For the rest of the artifacts, we need to provide the outputPath, always
// relative to the buildFolder, by default, c:/installer
"morphic-documorph-installer": {
"type": "gpii.installer.artifact.downloader",
"options": {
"downloadUrl": "https://github.com/javihernandez/morphic-documorph-installer/releases/download/0.1/documorph.msm",
"output": "documorph.msm",
"outputPath": "documorph.msm"
}
},
"gpii-filebeat-installer": {
"type": "gpii.installer.artifact.downloader",
"options": {
"downloadUrl": "https://github.com/stegru/gpii-filebeat-installer/releases/download/1.0.0/filebeat.msm",
"output": "filebeat.msm",
"outputPath": "filebeat.msm"
}
},
"resetToStandardFile": {
"type": "gpii.installer.artifact.downloader",
"options": {
"downloadUrl": "https://raw.githubusercontent.com/GPII/universal/master/testData/defaultSettings/defaultSettings.win32.json5",
"output": "defaultSettings.json5",
"outputPath": "staging/windows/resources/app/node_modules/gpii-universal/testData/defaultSettings/defaultSettings.json5"
}
}
}
18 changes: 18 additions & 0 deletions devTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var fluid = require("infusion");

var gpii = fluid.registerNamespace("gpii");

require("./index.js");

//fluid.logObjectRenderChars = 1200000;

var m = gpii.installer({});
//console.log("#### buildFolder: ", m.options.buildFolder);

//m.npmInstall();

//m.electronPackager();
//m.runMsbuild();

//m.populateArtifacts();
//console.log("## m: " + JSON.stringify(m, null, 2));
26 changes: 26 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*!
* Morphic automatic installer
*
* Copyright 2019 Raising the Floor - US
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
*
* The R&D leading to these results received funding from the
* Department of Education - Grant H421A150005 (GPII-APCP). However,
* these results do not necessarily represent the policy of the
* Department of Education, and you should not assume endorsement by the
* Federal Government.
*
* You may obtain a copy of the License at
* https://github.com/GPII/universal/blob/master/LICENSE.txt
*/
"use strict"

var fluid = require("infusion");

fluid.module.register("gpii-windows-installer", __dirname, require);

var gpii = fluid.registerNamespace("gpii");

require("./src/main.js");
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "gpii-windows-installer",
"version": "0.1.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/gpii/gpii-windows-installer.git"
},
"license": "BSD-3-Clause",
"dependencies": {
"adm-zip": "0.4.14",
"dedupe-infusion": "1.0.0",
"electron-packager": "14.0.4",
"fs-extra": "8.1.0",
"infusion": "3.0.0-dev.20190328T144119Z.ec44dbfab",
"json5": "2.1.0",
"node-powershell": "4.0.0",
"request": "2.88.0"
}
}
78 changes: 78 additions & 0 deletions provisioning/Build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<#
This script does the following:
1) Run the provisioning scripts from the windows repository
2) Run WixSetup.ps1
2) Run npm install

If run via a tool (like vagrant) which moves this script to somewhere different
than its original location within the gpii-app repository, the parameter
"-originalBuildScriptPath" should be provided, with the original location of the
script
#>

param (
[string]$originalBuildScriptPath = (Split-Path -parent $PSCommandPath) # Default to script path.
)

# Turn verbose on, change to "SilentlyContinue" for default behaviour.
$VerbosePreference = "continue"

# Store the parent folder of the script (root of the repo) as $mainDir
############
$mainDir = (get-item $originalBuildScriptPath).parent.FullName
Write-OutPut "mainDir set to: $($mainDir)"

# TODO: We should add this to a function or reduce to oneline.
$bootstrapModule = Join-Path $originalBuildScriptPath "Provisioning.psm1"
iwr https://raw.githubusercontent.com/GPII/windows/master/provisioning/Provisioning.psm1 -UseBasicParsing -OutFile $bootstrapModule
Import-Module $bootstrapModule -Verbose -Force

# Retrieve provisioning scripts from the windows repo
# ############
# TODO: Create function for downloading scripts and executing them.
$windowsBootstrapURL = "https://raw.githubusercontent.com/GPII/windows/master/provisioning"
try {
$choco = Join-Path $originalBuildScriptPath "Chocolatey.ps1"
Write-OutPut "Running windows script: $choco"
iwr "$windowsBootstrapURL/Chocolatey.ps1" -UseBasicParsing -OutFile $choco
Invoke-Expression $choco
} catch {
Write-OutPut "Chocolatey.ps1 FAILED"
exit 1
}
try {
$couchdb = Join-Path $originalBuildScriptPath "CouchDB.ps1"
Write-OutPut "Running windows script: $couchdb"
iwr "$windowsBootstrapURL/CouchDB.ps1" -UseBasicParsing -OutFile $couchdb
Invoke-Expression $couchdb
} catch {
Write-OutPut "CouchDB.ps1 FAILED"
exit 1
}
try {
$npm = Join-Path $originalBuildScriptPath "Npm.ps1"
Write-OutPut "Running windows script: $npm"
iwr "$windowsBootstrapURL/Npm.ps1" -UseBasicParsing -OutFile $npm
Invoke-Expression $npm
} catch {
Write-OutPut "Npm.ps1 FAILED"
exit 1
}

## In addition to the previous scripts, we also need to setup Wix
try {
$wix = Join-Path $originalBuildScriptPath "WixSetup.ps1"
Write-OutPut "Setting up Wix: $wix"
Invoke-Expression $Wix
} catch {
Write-OutPut "WixSetup.ps1 FAILED"
exit 1
}

$npmCmd = "npm" -f $env:SystemDrive

## npm install pkg globally
Invoke-Command $npmCmd "install -g pkg"

## Run npm install
Invoke-Command "npm" "install" $mainDir
36 changes: 36 additions & 0 deletions provisioning/WixSetup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<#
This script sets up the system to build an installer.
#>

param (
[string]$provisioningDir = (Split-Path -parent $PSCommandPath) # Default to script path.
)

# Turn verbose on, change to "SilentlyContinue" for default behaviour.
$VerbosePreference = "continue"

# Store the project folder of the script (root of the repo) as $projectDir.
$projectDir = (Get-Item $provisioningDir).parent.FullName

Import-Module (Join-Path $provisioningDir 'Provisioning.psm1') -Force

# Obtaining useful tools location.
$npm = "npm" -f $env:SystemDrive
$chocolatey = "$env:ChocolateyInstall\bin\choco.exe" -f $env:SystemDrive

# Installing required choco packages.
Invoke-Command $chocolatey "install wixtoolset -y"
refreshenv
# The path to WIX can be found in $env:WIX env variable but looks like chocolatey's refreshenv
# is not able to set such variable in this session. As a workaround, we ask the registry
# for such environmental variable and set it so we can use it inside this powershell session.
$wixSetupPath = Join-Path (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' -Name WIX).WIX "bin"
Add-Path $wixSetupPath $true
refreshenv

Invoke-Command $chocolatey "install msbuild.extensionpack -y"
refreshenv

# Install electron-packager globally.
# TODO: Define electron-packager invocation in npm scripts.
Invoke-Command $npm "install electron-packager -g" $projectDir
Loading