-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves Issue #1 - This makes it much more portable.
This also reworks the way node/composer packages are installed, making the coldboot much faster.
- Loading branch information
Showing
2 changed files
with
65 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,31 +6,36 @@ NAME = derp | |
BUILD ?= 01 | ||
UFPORT ?= 8086 | ||
|
||
SMTP_SERVER ?= mail.example.com | ||
SMTP_USER ?= [email protected] | ||
SMTP_PASSWORD ?= password | ||
|
||
VERSION := $(shell date +%Y%m%d).$(BUILD) | ||
|
||
SSHAGENT = -v $(shell readlink -f ${SSH_AUTH_SOCK}):/ssh-agent -e SSH_AUTH_SOCK=/ssh-agent | ||
PARAMS = --name=$(NAME) -p $(UFPORT):80 $(SSHAGENT) -e DEVMODE=true --network=uf_default $(MOUNTS) $(ENVVARS) | ||
|
||
MOUNTS = -v $(shell pwd)/git/userfrosting:/var/www -v $(shell pwd)/git/userfrosting/public:/var/www/html $(SMOUNTS) | ||
MOUNTS = -v $(shell pwd)/git/userfrosting:/var/www -v $(shell pwd)/git/userfrosting/public:/var/www/html $(SMOUNTS) $(COMPOSERMOUNT) | ||
SMOUNTS = $(foreach s,$(wildcard sprinkles/*),-v $(shell pwd)/$(s):/var/www/app/sprinkles/$(notdir $(s))) | ||
COMPOSERMOUNT = -v $(HOME)/.composer:/root/.composer | ||
|
||
ENVVARS = -e DB_DRIVER=mysql -e DB_HOST=coredb -e DB_PORT=3306 -e DB_NAME=userfrosting -e DB_USER=userfrosting -e DB_PASSWORD=$(MYSQLUSERPASSWORD) | ||
ENVVARS = -e DB_DRIVER=mysql -e DB_HOST=ufdb -e DB_PORT=3306 -e DB_NAME=userfrosting -e DB_USER=userfrosting -e DB_PASSWORD=$(MYSQLUSERPASSWORD) | ||
|
||
COMPOSERVERSION=1.23.1 | ||
WEBUSER=www-data | ||
UNAME_S = $(shell uname -s) | ||
|
||
# gtar is required on Macs | ||
ifeq ($(UNAME_S),Linux) | ||
TARCMD=$(shell which tar) | ||
TAR=$(shell which tar) | ||
endif | ||
ifeq ($(UNAME_S),Darwin) | ||
TARCMD=$(shell which gtar) | ||
TAR=/usr/local/bin/gtar | ||
endif | ||
|
||
# Pull UserFrosting from git and rebuild if the json changes | ||
PACKAGES := packages/userfrosting.tar.bz2 | ||
|
||
# Note that 'make nuke' does a 'git checkout --force' of these repositories. | ||
# Don't use it unless you really need to. | ||
USERFROSTING_REPO = [email protected]:userfrosting/UserFrosting.git | ||
USERFROSTING_BRANCH = origin/master | ||
USERFROSTING_MOUNT = /var/www/ | ||
|
@@ -46,53 +51,63 @@ SPRINKLES_FILES = $(shell find sprinkles -type f -name '*') | |
|
||
export | ||
|
||
UL = $(shell tput smul) | ||
ENDUL = $(shell tput rmul) | ||
SO = $(shell tput smso) | ||
ENDSO = $(shell tput rmso) | ||
all: $(PACKAGES) build debug-run watch | ||
|
||
all: $(PACKAGES) build run watch | ||
|
||
build: package-sprinkles $(PACKAGES) link-packages | ||
build: composer node $(PACKAGES) package-sprinkles link-packages | ||
docker build -t $(NAME):$(VERSION) --rm image | ||
|
||
run: start-prereq stop | ||
docker run -it -d $(PARAMS) $(NAME):$(VERSION) | ||
# We need to require autoload AND slim, because slim doesn't get loaded the first | ||
# time composer is run. This could be fixed by creating a better (one that contains | ||
# the gd module) composer container but, just running it twice works. | ||
composer: gensprinkles git/userfrosting/app/vendor/autoload.php git/userfrosting/app/vendor/slim | ||
|
||
# Adding package.json as a dep means we'll rebuild everything when it changes | ||
node: git/userfrosting/build/node_modules git/userfrosting/app/assets/package.json | ||
|
||
debug-run: start-prereq stop | ||
docker run -it -d $(PARAMS) $(MOUNTS) $(NAME):$(VERSION) | ||
|
||
watch: git/userfrosting/app/vendor/autoload.php git/userfrosting/build/node_modules fixperms | ||
docker logs -f $(NAME) | ||
|
||
# We do an 'update' here, because there's some incompatible .lock files that | ||
# cause confusion inside composer. I didn't look where. | ||
git/userfrosting/app/vendor/autoload.php: | ||
docker exec -it -w /var/www $(NAME) composer update | ||
|
||
# We tag the package.json as a dep, so if it's updated we'll rebuild the mode modules | ||
# | ||
# Yes. This has to happen twice, because slim isn't installed the first time. | ||
# | ||
git/userfrosting/app/vendor/autoload.php: git/userfrosting/.git | ||
@docker run -it $(MOUNTS) -e COMPOSER_CACHE_DIR=/root/.composer -w /var/www --rm composer composer update --ignore-platform-reqs || : | ||
git/userfrosting/app/vendor/slim: | ||
@docker run -it $(MOUNTS) -e COMPOSER_CACHE_DIR=/root/.composer -w /var/www --rm composer composer update --ignore-platform-reqs || : | ||
|
||
# We tag the package.json as a dep, so if it's updated we'll rebuild the mode modules. Above, | ||
# that is marked as a dependancy of THIS, but make is smart enough to figure out what we want | ||
# to achieve. | ||
git/userfrosting/build/node_modules: git/userfrosting/build/package.json | ||
docker exec -it -w /var/www/build $(NAME) npm install | ||
@docker run -it $(MOUNTS) -w /var/www/build --rm node:lts-jessie npm install | ||
@touch $@ | ||
|
||
git/userfrosting/app/assets/package.json: | ||
docker exec -it -w /var/www/build $(NAME) npm run uf-assets-install | ||
git/userfrosting/app/assets/package.json: git/userfrosting/.git | ||
@docker run -it $(MOUNTS) -w /var/www/build --rm node:lts-jessie npm run uf-assets-install | ||
@touch $@ | ||
|
||
gensprinkles: $(SPRINKLES_FILES) $(SPRINKLES_DIRS) | ||
@echo '{ "require": { }, "base": [' > git/userfrosting/app/sprinkles.json.new | ||
@for s in $(SPRINKLES) $(foreach s,$(wildcard sprinkles/*),$(notdir $(s))); do echo -n \"$$s\",; done | sed 's/,$$/\n/' >> git/userfrosting/app/sprinkles.json.new | ||
@echo ']}' >> git/userfrosting/app/sprinkles.json.new | ||
@[ ! -e git/userfrosting/app/sprinkles.json ] && cp git/userfrosting/app/sprinkles.json.new git/userfrosting/app/sprinkles.json || : | ||
@cmp --silent git/userfrosting/app/sprinkles.json git/userfrosting/app/sprinkles.json.new || /bin/cp -f git/userfrosting/app/sprinkles.json.new git/userfrosting/app/sprinkles.json | ||
@rm -f git/userfrosting/app/sprinkles.json.new | ||
@echo '{ "require": { }, "base": [' > /tmp/sprinkles.json.new | ||
@for s in $(SPRINKLES) $(foreach s,$(wildcard sprinkles/*),$(notdir $(s))); do echo -n \"$$s\",; done | sed 's/,$$/\n/' >> /tmp/sprinkles.json.new | ||
@echo ']}' >> /tmp/sprinkles.json.new | ||
@[ ! -e git/userfrosting/app/sprinkles.json ] && cp /tmp/sprinkles.json.new git/userfrosting/app/sprinkles.json || : | ||
@cmp --silent git/userfrosting/app/sprinkles.json /tmp/sprinkles.json.new || /bin/cp -f /tmp/sprinkles.json.new git/userfrosting/app/sprinkles.json | ||
@rm -f /tmp/sprinkles.json.new | ||
|
||
package-sprinkles: gensprinkles packages/sprinkles.tar.bz2 | ||
|
||
packages/sprinkles.tar.bz2: $(SPRINKLES_FILES) $(SPRINKLES_DIRS) | ||
rm -f packages/sprinkles.tar.bz2 | ||
cd sprinkles && $(TARCMD) -jcvf ../packages/sprinkles.tar.bz2 $(foreach s,$(wildcard sprinkles/*),$(notdir $(s))) | ||
packages/sprinkles.tar.bz2: $(TAR) $(SPRINKLES_FILES) $(SPRINKLES_DIRS) | ||
@for s in $(foreach s,$(wildcard sprinkles/*),$(notdir $(s))); do \ | ||
docker run -it --rm -w /var/www/app $(MOUNTS) php:7.3.5-apache-stretch find sprinkles/$$s -name '*.php' -exec php -l {} \;; done | ||
@rm -f packages/sprinkles.tar.bz2 | ||
@cd sprinkles && $(TAR) -jcf ../packages/sprinkles.tar.bz2 $(foreach s,$(wildcard sprinkles/*),$(notdir $(s))) | ||
|
||
fixperms: git/userfrosting/app/.env | ||
@docker exec -it -w /var/www $(NAME) chown $(WEBUSER) app/logs app/cache app/sessions app/.env | ||
|
||
git/userfrosting/app/.env: | ||
docker exec -it -w /var/www $(NAME) php bakery bake | ||
fixperms: | ||
@[ ! -e git/userfrosting/app/.env ] && echo -e 'SMTP_HOST=$(SMTP_HOST)\nSMTP_USER=$(SMTP_USER)\nSMTP_PASSWORD=$(SMTP_PASSWORD)\n' > git/userfrosting/app/.env || : | ||
@docker run --rm $(MOUNTS) -w /var/www $(NAME):$(VERSION) chown $(WEBUSER) app/logs app/cache app/sessions app/.env | ||
|
||
shell: | ||
docker exec -it $(NAME) bash | ||
|
@@ -127,7 +142,7 @@ generate-passwords: | |
docker-compose: /usr/bin/docker-compose-$(COMPOSERVERSION) | ||
|
||
/usr/bin/docker-compose-$(COMPOSERVERSION): | ||
yum -y remove docker-compose 2>/dev/null || : | ||
@[ -e /usr/bin/yum ] && yum -y remove docker-compose 2>/dev/null || : | ||
curl -L "https://github.com/docker/compose/releases/download/$(COMPOSERVERSION)/docker-compose-$(shell uname -s)-$(shell uname -m)" -o $@ | ||
chmod 755 $@ | ||
rm -f /usr/bin/docker-compose | ||
|
@@ -138,9 +153,9 @@ link-packages: | |
@mkdir image/packages | ||
@ln packages/* image/packages | ||
|
||
packages/%.tar.bz2: git/%/_GIT_UPDATE_ | ||
packages/%.tar.bz2: $(TAR) git/%/_GIT_UPDATE_ | ||
mkdir -p packages | ||
cd git/$(*F) && $(TARCMD) --mtime="2019-01-01 01:01:01" --owner=0 --group=0 --numeric-owner --exclude-vcs --exclude='*.tgz' --exclude='node_modules' -jcf ../../$@ . | ||
cd git/$(*F) && $(TAR) --mtime="2019-01-01 01:01:01" --owner=0 --group=0 --numeric-owner --exclude-vcs --exclude='*.tgz' --exclude='node_modules' -jcf ../../$@ . | ||
|
||
git/%/_GIT_UPDATE_: git/%/.git | ||
$(eval BRANCH = $($(shell echo $(*F) | tr '[:lower:]' '[:upper:]')_BRANCH)) | ||
|
@@ -157,3 +172,11 @@ git/%/.git: | |
mkdir -p git && git clone --recursive $(REPO) git/$(*F) | ||
|
||
|
||
# For the macs! | ||
/usr/local/bin/gtar: | ||
@if [ "$(strip $(shell uname -s))" == "Darwin" ]; then \ | ||
brew install gnu-tar; \ | ||
else \ | ||
ln -s /usr/bin/tar /usr/local/bin/gtar; \ | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters