Skip to content

Commit

Permalink
Use Makefile for deployment
Browse files Browse the repository at this point in the history
Add make targets that use Docker to install PHP and Node dependencies.
Use make targets in ansible build task to make deploy and local dev more
consistent.
  • Loading branch information
gbirke committed Mar 20, 2018
1 parent cfb897e commit 82b7925
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 62 deletions.
26 changes: 17 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
current_user = $(shell id -u)
current_group = $(shell id -g)
current_user := $(shell id -u)
current_group := $(shell id -g)
BUILD_DIR := $(PWD)
TMPDIR := $(BUILD_DIR)/tmp
COMPOSER_FLAGS :=
NPM_FLAGS := --prefer-offline
DOCKER_FLAGS := --interactive --tty

js-install:
-mkdir -p tmp/home
-echo "node:x:$(current_user):$(current_group)::/var/nodehome:/bin/bash" > tmp/passwd
docker run --rm -it --user $(current_user):$(current_group) -v $(PWD):/data:delegated -w /data -v $(PWD)/tmp/home:/var/nodehome:delegated -v $(PWD)/tmp/passwd:/etc/passwd node:8 npm install --prefer-offline
install-js:
-mkdir -p $(TMPDIR)/home
-echo "node:x:$(current_user):$(current_group)::/var/nodehome:/bin/bash" > $(TMPDIR)/passwd
docker run --rm $(DOCKER_FLAGS) --user $(current_user):$(current_group) -v $(BUILD_DIR):/data:delegated -w /data -v $(TMPDIR)/home:/var/nodehome:delegated -v $(TMPDIR)/passwd:/etc/passwd node:8 npm install $(NPM_FLAGS)

install-php:
docker run --rm $(DOCKER_FLAGS) --volume $(BUILD_DIR):/app -w /app --volume ~/.composer:/composer --user $(current_user):$(current_group) composer install --ignore-platform-reqs $(COMPOSER_FLAGS)

js:
docker run --rm -it --user $(current_user):$(current_group) -v $(PWD):/data:delegated -w /data -e NO_UPDATE_NOTIFIER=1 node:8 npm run build-assets
docker run --rm -it --user $(current_user):$(current_group) -v $(PWD):/data:delegated -w /data -e NO_UPDATE_NOTIFIER=1 node:8 npm run copy-assets
docker run --rm $(DOCKER_FLAGS) --user $(current_user):$(current_group) -v $(BUILD_DIR):/data:delegated -w /data -e NO_UPDATE_NOTIFIER=1 node:8 npm run build-assets
docker run --rm $(DOCKER_FLAGS) --user $(current_user):$(current_group) -v $(BUILD_DIR):/data:delegated -w /data -e NO_UPDATE_NOTIFIER=1 node:8 npm run copy-assets

clear:
rm -rf var/cache/

ui: clear js

.PHONY: js js-install clear ui
.PHONY: js clear ui install-php install-js
76 changes: 23 additions & 53 deletions deployment/tasks/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,65 +11,35 @@
git: repo=https://github.com/wmde/FundraisingFrontend.git dest={{ build_dir }} version={{ build_branch }} force=yes

- name: Install PHP dependencies
docker_container:
name: composer
image: composer
detach: no
cleanup: yes
user: "{{ ansible_user_uid }}:{{ ansible_user_gid }}"
command: install --no-dev --ignore-platform-reqs --prefer-dist --optimize-autoloader
volumes:
- "{{ ansible_user_dir }}/.composer:/tmp"
- "{{ build_dir }}:/app"
make:
chdir: "{{ build_dir }}"
target: install-php
params:
COMPOSER_FLAGS: "--no-dev --prefer-dist --optimize-autoloader"
DOCKER_FLAGS: ""
BUILD_DIR: "{{ build_dir }}"

- name: Create fake home for npm install as non-root
file:
path: "{{ build_dir }}/var/npmbuild/home"
path: "{{ build_dir }}/var/npmbuild"
state: directory

- name: Create passwd file for npm install as non-root
copy:
dest: "{{ build_dir }}/var/npmbuild/passwd"
content: "node:x:{{ ansible_user_uid }}:{{ ansible_user_gid }}::/var/nodehome:/bin/bash"

- name: Install npm packages
docker_container:
name: npm_install
image: "node:8"
detach: no
working_dir: /app
user: "{{ ansible_user_uid }}:{{ ansible_user_gid }}"
command: "npm install"
volumes:
- "{{ build_dir }}:/app:delegated"
- "{{ build_dir }}/var/npmbuild/passwd:/etc/passwd"
- "{{ build_dir }}/var/npmbuild/home:/var/nodehome"

- name: Copy compiled Javascript to web folder
docker_container:
name: npm_build
image: "node:8"
detach: no
working_dir: /app
user: "{{ ansible_user_uid }}:{{ ansible_user_gid }}"
command: "npm run build-assets"
env:
NO_UPDATE_NOTIFIER: 1
volumes:
- "{{ build_dir }}:/app"

- name: Copy compiled Javascript to web folder
docker_container:
name: npm_build
image: "node:8"
detach: no
working_dir: /app
user: "{{ ansible_user_uid }}:{{ ansible_user_gid }}"
command: "npm run copy-assets"
env:
NO_UPDATE_NOTIFIER: 1
volumes:
- "{{ build_dir }}:/app"
make:
chdir: "{{ build_dir }}"
target: install-js
params:
TMPDIR: "{{ build_dir }}/var/npmbuild"
DOCKER_FLAGS: ""
BUILD_DIR: "{{ build_dir }}"

- name: Compile & copy Javascript to web folder
make:
chdir: "{{ build_dir }}"
target: js
params:
BUILD_DIR: "{{ build_dir }}"
DOCKER_FLAGS: ""

- name: Create tarball
shell: tar -czf {{ build_dir }}.tar.gz --exclude=".git" --exclude=node_modules -C {{ build_dir }} . warn=no

0 comments on commit 82b7925

Please sign in to comment.