Skip to content

Commit

Permalink
Merge pull request #278 from dshoreman/installer-fixup
Browse files Browse the repository at this point in the history
See PR for details. Thanks to @stoppert for testing on OSX
  • Loading branch information
dshoreman committed Oct 6, 2020
2 parents 64fea43 + b8206fc commit a1345d9
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 43 deletions.
34 changes: 32 additions & 2 deletions Makefile
@@ -1,18 +1,48 @@
.PHONY: test

GNU_SED := $(shell command -v gsed || command -v sed)
now := `date '+%Y-%m-%d_%H%M'`

installer:
installer: thinkdifferent
@echo -n "Building unified install script... "
@cat build/installer/main.sh build/installer/_*.sh | \
sed -e '1,30s/echo "\(\s\+\[\)/echo " \1/' \
$(GNU_SED) -e '1,30s/echo "\(\s\+\[\)/echo " \1/' \
-e '1,20{/^# shellcheck source=_.*$$/,+1d}' \
-e '/^main "$$@"$$/{H;d};$${p;x;s/^\n//}' \
-e 's^main\.sh^bash ./setup.sh^' \
-e '/^\(SCRIPT_ROOT=\|$$\)/d' \
> setup.sh
@chmod +x setup.sh && echo "Done!"

dev-env:
@echo "Go stick the kettle on, this'll take a while." && sleep 2
@echo
@echo "[1/5] Destroying Vagrant VM and purging package caches..." && \
rm -rf ./composer ./node_modules ./vendor; vagrant destroy -f
@echo
@echo "[2/5] Installing Composer/NPM packages and building assets..."
ifeq (, $(shell command -v composer))
@echo "Composer not available, package installation will run in Vagrant instead."
else
@composer install --no-interaction --no-progress --no-suggest || true
endif
@npm ci && npm run dev
@echo
@echo "[3/5] Creating the new VM..." && \
vagrant up --no-provision || true
@echo
@echo "[4/5] Creating the 'servidor' user..." && \
vagrant provision --provision-with=user
@echo
@echo "[5/5] Restarting Vagrant VM to run installer..." && \
make installer && vagrant reload --provision-with=installer

thinkdifferent:
ifeq (Darwin,$(shell uname)$(shell command -v gsed))
@echo "To build the installer on OSX, you must first brew install gnu-sed"
@exit 1
endif

test:
@vagrant ssh -c "cd /var/servidor && sudo -u www-data phpdbg -qrr vendor/bin/phpunit -c build/phpunit/config.xml"

Expand Down
44 changes: 22 additions & 22 deletions README.md
Expand Up @@ -12,8 +12,9 @@ Servidor is still very much a work in progress, but what has been [added so far]
## Table of Contents

* [Introduction]
* [Table of Contents]
* [Installation]
* [Interactive Setup]
* [Startup Script]
* [Development]
* [Running Tests]
* [Contributing]
Expand All @@ -26,7 +27,10 @@ you also have the ability to manually trigger a `git pull` on any given project

## Installation

> **WARNING!** Servidor is not yet ready for production use!
> **NOTE: Servidor is still a work-in-progress!**
> As such, there are some parts that likely aren't as secure as they could be, so
> **exercise appropriate caution if you intend to use it on a public-facing server!**
> If you find anything that can be improved, PRs are open and greatly appreciated.
#### Interactive Setup

Expand Down Expand Up @@ -59,27 +63,18 @@ curl -s https://raw.githubusercontent.com/dshoreman/servidor/installer/setup.sh

## Development

Servidor is setup to use Vagrant for development. To get started, first clone the repository and run `vagrant up`.

Installation happens automatically as part of the provisioning process, but the installer will not build frontend assets if it
detects Vagrant. Instead, you'll need to install and build them separately after running `vagrant up`:
To get started, run `make dev-env` in the project root. Servidor relies on [Vagrant] for development, so this command
takes care of creating the VM, running the necessary prep, and installation of Servidor within the dev environment.
After the initial setup, standard Vagrant commands can be used to `up`, `suspend`, `reload` and so on.

```sh
# Clean-install NPM packages from the lock file
npm ci

# Compile the frontend assets for development
npm run dev
# tl;dr:
git clone https://github.com/dshoreman/servidor.git
cd servidor && make dev-env
```

Alternatively, you can use `npm run watch` or `npm run hot` to have assets automatically rebuilt during development.

By default, Servidor can be accessed at http://servidor.local:8042. If you have [vagrant-hostsupdater] or similar, this will be
mapped automatically. Alternatively you can use http://192.168.10.100:8042, or run the following to update /etc/hosts:

```sh
echo '192.168.10.100 servidor.local' | sudo tee -a /etc/hosts
```
Due to memory constraints within the VM, static assets are initially built during `make dev-env`.
To recompile assets automatically when you make changes, run `npm run hot` or `npm run watch`.

### Running Tests

Expand All @@ -90,15 +85,20 @@ Other make commands are available such as `make syntax` to run other CI tools. F

## Contributing

As noted above, Servidor is still very young. Your ideas, code and overall feedback are all highly valued, so please feel free to
open an issue or pull request - the latter should go to the develop branch. Thanks! :heart:
Where possible, issues are grouped into one of various projects based on the page/section they apply to, so if you want to
find something to work on in a certain part of Servidor, then the Projects tab is a good place to start. Questions, bug reports,
ideas and PRs are all welcome and highly appreciated, so don't be afraid to ask if there's something you're not sure of!

If you use IRC, find me in *#servidor* on Freenode where I'll be happy to answer questions in a more real-time fashion.

[Introduction]: #servidor
[Table of Contents]: #table-of-contents
[What it Does]: #what-it-does
[added so far]: #what-it-does
[Installation]: #installation
[Interactive Setup]: #interactive-setup
[Startup Script]: #startup-script
[Development]: #development
[Running Tests]: #running-tests
[Contributing]: #contributing
[Vagrant]: https://vagrantup.com
[vagrant-hostsupdater]: https://github.com/agiledivider/vagrant-hostsupdater#installation
34 changes: 23 additions & 11 deletions Vagrantfile
Expand Up @@ -9,27 +9,39 @@ Vagrant.configure("2") do |config|
config.vm.network "private_network",
ip: "192.168.10.100"

config.vm.provider "virtualbox" do |vb|
vb.name = "servidor-dev"
vb.linked_clone = true
vb.memory = "1024"
end

config.vm.provision "user", type: "shell", run: "never" do |s|
s.inline = "useradd -b /var -UG www-data -s /usr/sbin/nologin --system servidor && echo 'User added!'"
end

config.vm.provision "installer",
path: "setup.sh", args: "-v",
type: "shell", run: "never"

config.vm.synced_folder ".", "/vagrant",
disabled: true

config.vm.synced_folder ".", "/var/servidor",
create: true, owner: "998", group: "998",
create: true, owner: "servidor", group: "servidor",
mount_options: ["dmode=775,fmode=664"]

config.vm.synced_folder "./resources/test-skel", "/var/servidor/resources/test-skel",
config.vm.synced_folder "./storage", "/var/servidor/storage",
create: false, owner: "servidor", group: "www-data",
mount_options: ["dmode=770,fmode=660"]

config.vm.synced_folder "./resources/test-skel",
"/var/servidor/resources/test-skel",
create: false, owner: "www-data", group: "www-data",
mount_options: ["dmode=775,fmode=664"]

config.vm.synced_folder "./resources/test-skel/protected", "/var/servidor/resources/test-skel/protected",
config.vm.synced_folder "./resources/test-skel/protected",
"/var/servidor/resources/test-skel/protected",
create: false, owner: "vagrant", group: "vagrant",
mount_options: ["dmode=775,fmode=600"]

config.vm.provider "virtualbox" do |vb|
vb.name = "servidor-dev"
vb.linked_clone = true
vb.memory = "1024"
end

config.vm.provision :shell, path: "setup.sh", args: "-v"

end
11 changes: 7 additions & 4 deletions build/installer/_install.sh
Expand Up @@ -14,24 +14,27 @@ install_servidor() {
}

prepare_home() {
log " Creating servidor system user..."
useradd -b /var -UG www-data -s /usr/sbin/nologin --system servidor
if ! is_vagrant; then
log "Creating servidor system user..."
useradd -b /var -UG www-data -s /usr/sbin/nologin --system servidor
mkdir /var/servidor && chown servidor:servidor /var/servidor
else
log "Skipped system user creation - when running in Vagrant, this is done by make dev-env."
fi

log "Adding www-data to the servidor group..."
usermod -aG servidor www-data
}

clone_and_install() {
cd /var/servidor || (err "Could not create system user!"; exit 1)
cd /var/servidor || (err "Home directory for servidor was not created!"; exit 1)

if ! is_vagrant; then
sudo -u servidor git clone -qb "${branch}" https://github.com/dshoreman/servidor.git .
fi

log "Installing required Composer packages..."
is_vagrant && c_dev="" || c_dev="--no-dev"
is_vagrant && c_dev="--prefer-source" || c_dev="--no-dev"
sudo -Hu servidor composer install ${c_dev} --no-interaction --no-progress --no-suggest

log "Compiling static assets..."
Expand Down
10 changes: 6 additions & 4 deletions setup.sh
Expand Up @@ -81,21 +81,23 @@ install_servidor() {
finalise && print_success
}
prepare_home() {
log " Creating servidor system user..."
useradd -b /var -UG www-data -s /usr/sbin/nologin --system servidor
if ! is_vagrant; then
log "Creating servidor system user..."
useradd -b /var -UG www-data -s /usr/sbin/nologin --system servidor
mkdir /var/servidor && chown servidor:servidor /var/servidor
else
log "Skipped system user creation - when running in Vagrant, this is done by make dev-env."
fi
log "Adding www-data to the servidor group..."
usermod -aG servidor www-data
}
clone_and_install() {
cd /var/servidor || (err "Could not create system user!"; exit 1)
cd /var/servidor || (err "Home directory for servidor was not created!"; exit 1)
if ! is_vagrant; then
sudo -u servidor git clone -qb "${branch}" https://github.com/dshoreman/servidor.git .
fi
log "Installing required Composer packages..."
is_vagrant && c_dev="" || c_dev="--no-dev"
is_vagrant && c_dev="--prefer-source" || c_dev="--no-dev"
sudo -Hu servidor composer install ${c_dev} --no-interaction --no-progress --no-suggest
log "Compiling static assets..."
if is_vagrant; then
Expand Down

0 comments on commit a1345d9

Please sign in to comment.