Refactor deploy to build locally, not remotely
This commit is contained in:
parent
d17c4cea8b
commit
edd983c97a
3 changed files with 56 additions and 18 deletions
|
@ -1,23 +1,53 @@
|
|||
---
|
||||
- name: Deploy impress-2020 from `main` on GitHub
|
||||
- name: Deploy impress-2020 from the current local version
|
||||
hosts: webserver
|
||||
vars:
|
||||
skip_build: no # Can override this by running `yarn deploy-skip-build`
|
||||
local_app_root: "{{ playbook_dir }}/../.."
|
||||
tasks:
|
||||
- name: Pull impress-2020 from `main` on GitHub
|
||||
git:
|
||||
repo: https://github.com/matchu/impress-2020.git
|
||||
dest: /srv/impress-2020/latest-version
|
||||
version: main
|
||||
- name: Install dependencies with yarn
|
||||
# For our deployment, our server resources are more constrained than our
|
||||
# dev machine, and builds are an expensive uncommon RAM & CPU spike. Let's
|
||||
# use our local machine for it! (I found that, running remotely, 2GB RAM
|
||||
# was not enough to build impress-2020 😅)
|
||||
- name: Run `yarn build` locally to build the current version
|
||||
delegate_to: localhost
|
||||
command:
|
||||
chdir: /srv/impress-2020/latest-version
|
||||
cmd: yarn install
|
||||
register: result
|
||||
changed_when: '"Already up-to-date." not in result.stdout'
|
||||
- name: Copy our local .env secrets file to the server
|
||||
copy:
|
||||
src: ../../.env
|
||||
dest: /srv/impress-2020/latest-version
|
||||
- name: Run `yarn build` to build the production app
|
||||
command:
|
||||
chdir: /srv/impress-2020/latest-version
|
||||
chdir: "{{ local_app_root }}"
|
||||
cmd: yarn build
|
||||
when: not skip_build
|
||||
|
||||
- name: Generate a version number from the current timestamp
|
||||
command: date '+%Y-%m-%dT%H:%M:%S'
|
||||
register: new_app_version
|
||||
|
||||
- name: Save new remote folder path to a variable
|
||||
set_fact:
|
||||
remote_app_root: "/srv/impress-2020/versions/{{ new_app_version.stdout }}"
|
||||
|
||||
- name: Create new remote folder for the new version
|
||||
file:
|
||||
path: "{{ remote_app_root }}"
|
||||
state: directory
|
||||
|
||||
- name: Copy local app's source files to new remote folder
|
||||
ansible.posix.synchronize:
|
||||
src: "{{ local_app_root }}"
|
||||
dest: "{{ remote_app_root }}"
|
||||
rsync_opts:
|
||||
- "--exclude=.git"
|
||||
- "--filter=':- .gitignore'"
|
||||
|
||||
- name: Copy local app's build files to new remote folder
|
||||
ansible.posix.synchronize:
|
||||
src: "{{ local_app_root }}/build"
|
||||
dest: "{{ remote_app_root }}/build"
|
||||
|
||||
- name: Copy local app's .env secrets file to new remote folder
|
||||
copy:
|
||||
src: "{{ local_app_root }}/.env"
|
||||
dest: "{{ remote_app_root }}"
|
||||
|
||||
- name: Run `yarn install` to install dependencies remotely
|
||||
command:
|
||||
chdir: "{{ remote_app_root }}"
|
||||
cmd: yarn install
|
||||
|
|
|
@ -6,12 +6,14 @@
|
|||
become: yes
|
||||
group:
|
||||
name: web
|
||||
|
||||
- name: Add current user to web group
|
||||
become: yes
|
||||
user:
|
||||
name: "{{ ansible_user_id }}"
|
||||
group: web
|
||||
append: yes
|
||||
|
||||
- name: Create the app folder
|
||||
become: yes
|
||||
file:
|
||||
|
@ -21,26 +23,31 @@
|
|||
# may only read it.
|
||||
group: web
|
||||
mode: "u=rwx,g=rwx,o=rx"
|
||||
|
||||
- name: Add Nodesource apt key
|
||||
become: yes
|
||||
apt_key:
|
||||
id: 9FD3B784BC1C6FC31A8A0A1C1655A0AB68576280
|
||||
url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
|
||||
|
||||
- name: Add Node v16 apt repository
|
||||
become: yes
|
||||
apt_repository:
|
||||
repo: deb https://deb.nodesource.com/node_16.x focal main
|
||||
|
||||
- name: Install Node v16
|
||||
become: yes
|
||||
apt:
|
||||
update_cache: yes
|
||||
name: nodejs
|
||||
state: present
|
||||
|
||||
- name: Install Yarn
|
||||
become: yes
|
||||
npm:
|
||||
name: yarn
|
||||
global: yes
|
||||
|
||||
- name: Install node-canvas dependencies
|
||||
become: yes
|
||||
apt:
|
||||
|
|
|
@ -68,6 +68,7 @@
|
|||
"lint": "next lint --dir src --dir pages",
|
||||
"deploy-setup": "echo $'Setup requires you to become the root user. You\\'ll need to enter the password for your account on the remote web server below, and you must be part of the `sudoers` user group.' && ansible-playbook -K -i deploy/inventory.cfg deploy/playbooks/setup.yml",
|
||||
"deploy": "ansible-playbook -i deploy/inventory.cfg deploy/playbooks/deploy.yml",
|
||||
"deploy-skip-build": "ansible-playbook -i deploy/inventory.cfg deploy/playbooks/deploy.yml --extra-vars='{\"skip_build\": true}'",
|
||||
"cypress": "cypress open",
|
||||
"mysql": "mysql --host=impress.openneo.net --user=$(dotenv -p IMPRESS_MYSQL_USER) --password=$(dotenv -p IMPRESS_MYSQL_PASSWORD) --database=openneo_impress",
|
||||
"mysql-dev": "mysql --host=localhost --user=impress_2020_dev --password=impress_2020_dev --database=impress_2020_dev",
|
||||
|
|
Loading…
Reference in a new issue