Skip to content

Commit f231356

Browse files
committed
Deployment setup
1 parent bc8fdf6 commit f231356

File tree

5 files changed

+77
-13
lines changed

5 files changed

+77
-13
lines changed

pm2.config.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"apps": [
3+
{
4+
"name": "elevate-projects-pwa",
5+
"script": "server.js",
6+
"args": [],
7+
"instances": "1",
8+
"exec_mode": "cluster",
9+
"watch": false,
10+
"merge_logs": true,
11+
"env": {
12+
"NODE_ENV": "production",
13+
"PORT": 8181
14+
}
15+
}
16+
]
17+
}

server.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const express = require('express');
2+
const path = require('path');
3+
const app = express();
4+
const port = process.env.PORT || 8181;
5+
6+
app.use(express.static(path.join(__dirname, 'www')));
7+
8+
app.get('*', (req, res) => {
9+
res.sendFile(path.join(__dirname, 'www', 'index.html'));
10+
});
11+
12+
app.listen(port, () => {
13+
console.log(`Server is running on port ${port}`);
14+
});

src/deployment/ansible.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
- hosts: elevate
3+
vars:
4+
project_path: /opt/frontend/elevate-project-pwa
5+
root_path: /opt/frontend
6+
tasks:
7+
- name: Slurp host file
8+
slurp:
9+
src: "/opt/backend/deployment/.token"
10+
register: slurpfile
11+
- name: Run vault credentials
12+
shell: "curl --location --request GET '{{ vaultAddress }}elevate-project-pws' --header 'X-Vault-Token: {{ slurpfile['content'] | b64decode }}' | jq '.data' > '{{root_path}}/data2.json'"
13+
register: vaultCurl
14+
- name: Change directory
15+
shell: cd {{project_path}}
16+
- name: Fetch the latest code
17+
git:
18+
repo: https://github.com/ELEVATE-Project/observation-survey-projects-pwa
19+
dest: "{{project_path}}"
20+
version: "{{gitBranch}}"
21+
force: yes
22+
- name: Update npm
23+
shell: cd {{project_path}} && npm i --force
24+
- name: Set permission
25+
shell: chmod 744 {{ project_path }}/src/scripts/json2env.sh
26+
- name: Generate .env
27+
shell: cat {{root_path}}/data2.json | jq '.data' > {{ project_path }}/src/environments/environment.ts && sed -i '1s/^/export const environment = \n/' {{ project_path }}/src/environments/environment.ts
28+
register: envConfig
29+
- debug: msg=" cred {{ envConfig }} "
30+
- name: Change directory
31+
shell: chdir {{project_path}}
32+
- name: Fetch pm2 config file
33+
shell: "curl --location --request GET '{{ vaultAddress }}projetcsPWAPm2Config' --header 'X-Vault-Token: {{ slurpfile['content'] | b64decode }}' | jq '.data.data' > '{{ project_path }}/pm2.config.json'"
34+
register: pm2
35+
- name: Change directory
36+
shell: cd {{project_path}}
37+
- name: Remove www folder
38+
shell: rm -rf www
39+
- name: Build pwa app
40+
shell: cd {{project_path}} && ionic build --prod
41+
- name: Start pm2
42+
shell: cd {{project_path}} && pm2 start pm2.config.json

src/environments/environment.ts

-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,4 @@
1-
// This file can be replaced during build by using the `fileReplacements` array.
2-
// `ng build` replaces `environment.ts` with `environment.prod.ts`.
3-
// The list of file replacements can be found in `angular.json`.
4-
51
export const environment = {
62
production: true,
73
baseURL: 'your baseUrl here',
84
};
9-
10-
/*
11-
* For easier debugging in development mode, you can import the following file
12-
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
13-
*
14-
* This import should be commented out in production mode because it will have a negative impact
15-
* on performance if an error is thrown.
16-
*/
17-
// import 'zone.js/plugins/zone-error'; // Included with Angular CLI.

src/scripts/json2env.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
tr -d '\n' |
3+
grep -o '"[A-Za-z_][A-Za-z_0-9]\+"\s*:\s*\("[^"]\+"\|[0-9\.]\+\|true\|false\|null\)' |
4+
sed 's/"\(.*\)"\s*:\s*"\?\([^"]\+\)"\?/\1= "\2"/'

0 commit comments

Comments
 (0)