diff --git a/roles/appsmith/defaults/main.yml b/roles/appsmith/defaults/main.yml index 3480328..69681e1 100644 --- a/roles/appsmith/defaults/main.yml +++ b/roles/appsmith/defaults/main.yml @@ -35,3 +35,6 @@ appsmith_email_tls: "{{ (appsmith_email_port == 587) | ternary(True,False) }}" # Encryption settings. If not defined, random values will be created and used # appsmith_encryption_pass: p@ssw0rd # appsmith_encryption_salt: Salt + +# Public URL used to access appsmith +appsmith_public_url: http://{{ inventory_hostname }} diff --git a/roles/appsmith/meta/main.yml b/roles/appsmith/meta/main.yml index f387b2f..cb8d365 100644 --- a/roles/appsmith/meta/main.yml +++ b/roles/appsmith/meta/main.yml @@ -8,3 +8,4 @@ dependencies: when: appsmith_redis_url | urlsplit('hostname') in ['localhost','127.0.0.1'] - role: mongodb_server when: appsmith_mongo_url | urlsplit('hostname') in ['localhost','127.0.0.1'] + - role: nginx diff --git a/roles/appsmith/tasks/.install.yml.swp b/roles/appsmith/tasks/.install.yml.swp new file mode 100644 index 0000000..65217a7 Binary files /dev/null and b/roles/appsmith/tasks/.install.yml.swp differ diff --git a/roles/appsmith/tasks/cleanup.yml b/roles/appsmith/tasks/cleanup.yml index a3cfcbf..7524f1b 100644 --- a/roles/appsmith/tasks/cleanup.yml +++ b/roles/appsmith/tasks/cleanup.yml @@ -4,4 +4,6 @@ file: path={{ item }} state=absent loop: - "{{ appsmith_root_dir }}/archives/{{ appsmith_current_version }}" + - "{{ appsmith_root_dir }}/tmp/appsmith-{{ appsmith_version }}" + - "{{ appsmith_root_dir }}/tmp/appsmith-{{ appsmith_version }}.tar.gz" tags: appsmith diff --git a/roles/appsmith/tasks/conf.yml b/roles/appsmith/tasks/conf.yml index 610be72..ffe7ab5 100644 --- a/roles/appsmith/tasks/conf.yml +++ b/roles/appsmith/tasks/conf.yml @@ -6,3 +6,8 @@ - env notify: restart appsmith-server tags: appsmith + +- name: Deploy nginx conf + template: src=nginx.conf.j2 dest=/etc/nginx/ansible_conf.d/appsmith.conf + notify: reload nginx + tags: appsmith diff --git a/roles/appsmith/tasks/install.yml b/roles/appsmith/tasks/install.yml index 67eb7f1..428efac 100644 --- a/roles/appsmith/tasks/install.yml +++ b/roles/appsmith/tasks/install.yml @@ -79,6 +79,35 @@ copy: src={{ item }} dest={{ appsmith_root_dir }}/server/plugins/ remote_src=True loop: "{{ appsmith_plugins_jar.stdout_lines }}" + - name: Install yarn + npm: + name: yarn + path: "{{ appsmith_root_dir }}/src/app/client" + + - name: Install NodeJS dependencies + command: ./node_modules/yarn/bin/yarn install --ignore-engines + args: + chdir: "{{ appsmith_root_dir }}/src/app/client" + + # Not sure why but yarn installs webpack 4.46.0 while appsmith wants 4.44.2 + - name: Install correct webpack version + command: ./node_modules/yarn/bin/yarn add webpack@4.44.2 --ignore-engines + args: + chdir: "{{ appsmith_root_dir }}/src/app/client" + + - name: Build the client + command: ./node_modules/.bin/craco --max-old-space-size=4096 build --config craco.build.config.js + args: + chdir: "{{ appsmith_root_dir }}/src/app/client" + + - name: Move the client to its final dir + synchronize: + src: "{{ appsmith_root_dir }}/src/app/client/build/" + dest: "{{ appsmith_root_dir }}/client/" + compress: False + delete: True + delegate_to: "{{ inventory_hostname }}" + tags: appsmith - name: Deploy systemd unit diff --git a/roles/appsmith/templates/nginx.conf.j2 b/roles/appsmith/templates/nginx.conf.j2 new file mode 100644 index 0000000..627b447 --- /dev/null +++ b/roles/appsmith/templates/nginx.conf.j2 @@ -0,0 +1,34 @@ +server { + listen 80; + server_name {{ appsmith_public_url | urlsplit('hostname') }}; + include /etc/nginx/ansible_conf.d/acme.inc; + root {{ appsmith_root_dir }}/client; + client_max_body_size 10M; + + if ($request_method !~ ^(GET|POST|HEAD|PUT|DELETE|PATCH)$ ) { + return 405; + } + + # Send info about the original request to the backend + proxy_set_header X-Forwarded-For "$proxy_add_x_forwarded_for"; + proxy_set_header X-Real-IP "$remote_addr"; + proxy_set_header X-Forwarded-Proto "$scheme"; + proxy_set_header X-Forwarded-Host "$host"; + proxy_set_header Host "$host"; + + location / { + try_files $uri /index.html =404; + } + location /f { + proxy_pass https://cdn.optimizely.com/; + } + location /api { + proxy_pass http://127.0.0.1:{{ appsmith_server_port }}; + } + location /oauth2 { + proxy_pass http://127.0.0.1:{{ appsmith_server_port }}; + } + location /login { + proxy_pass http://127.0.0.1:{{ appsmith_server_port }}; + } +}