@webqit/webflo 0.11.40 → 0.11.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -186,7 +186,7 @@ cd my-app
186
186
 
187
187
  With [npm available on your terminal](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), run the following command to install Webflo to your project:
188
188
 
189
- > System Requirements: Node.js 14.0 or later
189
+ > System Requirements: Node.js 18.0 (having stable Fetch API support) or later
190
190
 
191
191
  ```shell
192
192
  npm i @webqit/webflo
@@ -0,0 +1,43 @@
1
+ # Base installations
2
+ # (Node 18 is the minimum required version: stable Fetch API, etc)
3
+ FROM node:18-alpine
4
+ RUN apk add git
5
+ RUN apk add certbot
6
+
7
+ # Refer to https://www.digitalocean.com/community/tutorials/how-to-build-a-node-js-application-with-docker
8
+ # By default, the Docker Node image includes a non-root node user that we can use to avoid running the application container as root.
9
+ USER node
10
+
11
+ # Create the working directory with node-user permissions
12
+ RUN mkdir -p /home/node/www/app && chown -R node:node /home/node/www
13
+ WORKDIR /home/node/www
14
+
15
+ # Adding this COPY instruction before running npm install or copying the application code allows you to take advantage of Docker’s caching mechanism.
16
+ COPY -chown=node:node package*.json ./
17
+
18
+ # Install
19
+ RUN npm install
20
+ # If you are building your code for production
21
+ # RUN npm ci --only=production
22
+
23
+ # Copy application code with node-user permissions
24
+ COPY --chown=node:node . .
25
+
26
+ # Install Webflo and friends globally
27
+ RUN npm install @webqit/webflo -g
28
+ RUN npm install @webqit/oohtml-cli -g
29
+ RUN npm install pm2 -g
30
+
31
+ # The deployment directory
32
+ WORKDIR /home/node/www/app
33
+
34
+ # To auto-start app (flags optional), we would add...
35
+ # CMD ["webflo", "start"]
36
+
37
+ # To build the image locally...
38
+ # docker build --no-cache -t webflo ./docker
39
+
40
+ # To publish to docker hub...
41
+ # docker login -u webqit
42
+ # docker tag webflo webqit/webflo
43
+ # docker push webqit/webflo
@@ -0,0 +1,91 @@
1
+ # Webflo Container
2
+
3
+ This is simply a node.js container with the `@webqit/webflo` framework installed. Once started, any webflo app can be deployed into the container from any git repository.
4
+
5
+ ## Usage
6
+
7
+ This container image lives on Docker Hub and can be pulled to a local machine or a remote Virtual Machine (VM) on any cloud platform.
8
+
9
+ + [To Use Locally](#to-use-locally)
10
+ + [To Use In the Cloud](#to-use-in-the-cloud)
11
+ * [To Deploy An App From Any Repo](#to-deploy-an-app-from-any-repo)
12
+
13
+ ### To Use Locally
14
+
15
+ Ensure you have docker installed on your computer and run the following command from any location on your terminal:
16
+
17
+ ```shell
18
+ docker pull webqit/webflo:latest
19
+ ```
20
+
21
+ The above command pulls the `webqit/webflo` image to your local machine. (But this can be automatically done by docker on running any docker commands that reference the `webqit/webflo` image.)
22
+
23
+ Next is to use the following commands to start the container and the Webflo runtime. In each case, the first part of the command starts the container, while the second part (from `webflo start`) starts the application.
24
+
25
+ #### To Start
26
+
27
+ Start the container using `docker run`; map a port (e.g `80`) of your host machine to `3000` of the container; optionally, give your container a name; reference `webqit/webflo` as the image to use; and lastly, start webflo using `webflo start`.
28
+
29
+ ```shell
30
+ docker run -d -p 80:3000 --name my-app webqit/webflo webflo start
31
+ ```
32
+
33
+ > Unless a port has been explicitly set via `webflo config server`, webflo *HTTP* port defaults to `3000` or the value specified in an environmental variable named `PORT`. If a `PORT` variable has been defined, then port mapping above would now need to use that variable: `-p 80:${PORT}`.
34
+
35
+ Visit [localhost](http://localhost) to view your app.
36
+
37
+ #### To Run In HTTPS Mode
38
+
39
+ To run Webflo apps in HTTPS inside a container, you basically need to map the appropriate SSL port from the host machine to a custom port in the container.
40
+
41
+ Below, we're now mapping port `443` to an application-level port defined as `${SSL_PORT}`.
42
+
43
+ ```shell
44
+ docker run -d -p 80:${PORT} 443:${SSL_PORT} --name my-app webqit/webflo webflo start
45
+ ```
46
+
47
+ > Unless an SSL port has been explicitly set via `webflo config server`, webflo *HTTPS* port defaults to `0` (no HTTPS) or the value specified in an environmental variable named `SSL_PORT`.
48
+
49
+ If you will be managing your SSL certificates in the host machine, you would also need to *bind-mount* the appropriate certificate volume from the host to the container.
50
+
51
+ Below, we're now mapping the directory `/etc/letsencrypt/` - the default location for `letsencrypt` certificates - to an equivalent directory in the container.
52
+
53
+ ```shell
54
+ docker run -d -p 80:${PORT} 443:${SSL_PORT} -v /etc/letsencrypt/:/etc/letsencrypt/ --name my-app webqit/webflo webflo start
55
+ ```
56
+
57
+ > Webflo lets you generate `letsencrypt` certificates with the `webflo generate:cert <domain1,domain2,etc>` command. Just be sure to have your app running in HTTP mode to enable the process handle certbot's `http` challenge.
58
+
59
+ #### To Start In Dev Mode
60
+
61
+ Webflo's *dev* mode is the perfect mode for developing locally. All you do is append the `--env=dev --watch` flags to your webflo commands. [(Learn more)](#)
62
+
63
+ ```shell
64
+ docker run -d -p 80:3000 --name my-app webqit/webflo webflo start --env=dev --watch
65
+ ```
66
+
67
+ In *dev* mode, webflo automatically restarts as you make changes to your codebase. But since webflo now lives inside a container, you'll need to *bind* the directory of your source code on your host machine to the `/home/node/www/app` directory of the container.
68
+
69
+ ```shell
70
+ docker run -d -v /Users/me/my-app:/home/node/www/app -p 80:3000 --name my-app webqit/webflo webflo start --env=dev --watch
71
+ ```
72
+
73
+ ### To Use In the Cloud
74
+
75
+ TODO
76
+
77
+ ### To Deploy An App From Any Repo
78
+
79
+ Whether running locally or in the cloud, webflo can easily take your application from any git repo. This follows webflo's normal `deploy` command.
80
+
81
+ Simply point docker at your container (using `docker exec [container-name]`) and execute the `webflo deploy` command.
82
+
83
+ ```shell
84
+ docker exec my-app webflo deploy https://github.com/me/my-app.git
85
+ ```
86
+
87
+ If you will need to install any npm dependencies, you would run `npm install` from within your container.
88
+
89
+ ```shell
90
+ docker exec my-app npm install
91
+ ```
@@ -0,0 +1,3 @@
1
+ {
2
+ "name": "webqit/webflo-docker"
3
+ }
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "vanila-javascript"
13
13
  ],
14
14
  "homepage": "https://webqit.io/tooling/webflo",
15
- "version": "0.11.40",
15
+ "version": "0.11.41",
16
16
  "license": "MIT",
17
17
  "repository": {
18
18
  "type": "git",
@@ -31,6 +31,7 @@ export default class Origins extends Dotfile {
31
31
  return this.merge({
32
32
  entries: [{
33
33
  host: hostname,
34
+ access_token: '',
34
35
  repo: origin,
35
36
  branch: 'master',
36
37
  tag: 'root',
@@ -74,6 +75,12 @@ export default class Origins extends Dotfile {
74
75
  choices: CHOICES.host,
75
76
  validation: ['input', 'important'],
76
77
  },
78
+ {
79
+ name: 'access_token',
80
+ type: 'text',
81
+ message: 'Enter your Personal Acess Token at host (if exists)',
82
+ validation: ['input', 'important'],
83
+ },
77
84
  {
78
85
  name: 'repo',
79
86
  type: 'text',
@@ -4,16 +4,16 @@
4
4
  */
5
5
  import { Dotfile } from '@webqit/backpack';
6
6
 
7
- export default class Virtualization extends Dotfile {
7
+ export default class Proxy extends Dotfile {
8
8
 
9
9
  // Base name
10
10
  get name() {
11
- return 'virtualization';
11
+ return 'proxy';
12
12
  }
13
13
 
14
14
  // @desc
15
15
  static get ['@desc']() {
16
- return 'Layout virtualization config.';
16
+ return 'Layout proxy config.';
17
17
  }
18
18
 
19
19
  // Defaults merger
@@ -5,7 +5,7 @@
5
5
  import Env from './Env.js';
6
6
  import Layout from './Layout.js';
7
7
  import Origins from './Origins.js';
8
- import Virtualization from './Virtualization.js';
8
+ import Proxy from './Proxy.js';
9
9
 
10
10
  /**
11
11
  * @exports
@@ -14,5 +14,5 @@ export {
14
14
  Env,
15
15
  Layout,
16
16
  Origins,
17
- Virtualization,
17
+ Proxy,
18
18
  }
@@ -19,10 +19,10 @@ export default class Server extends Dotfile {
19
19
  // Defaults merger
20
20
  withDefaults(config) {
21
21
  return this.merge({
22
- port: process.env.port || 3000,
22
+ port: process.env.PORT || 3000,
23
23
  domains: [],
24
24
  https: {
25
- port: 0,
25
+ port: process.env.SSL_PORT || 0,
26
26
  domains: [],
27
27
  keyfile: '/etc/letsencrypt/live/[domain]/privkey.pem',
28
28
  certfile: '/etc/letsencrypt/live/[domain]/fullchain.pem',
@@ -55,6 +55,7 @@ export async function deploy(origin) {
55
55
  }
56
56
  }
57
57
  // ---------------
58
+ const accessToken = origin.access_token;
58
59
  const isDeployPathSet = origin.deploy_path;
59
60
  origin.deploy_path = Path.join(cx.CWD || '', origin.deploy_path || '.');
60
61
  // ---------------
@@ -72,8 +73,8 @@ export async function deploy(origin) {
72
73
  await git.init();
73
74
 
74
75
  const hosts = {
75
- github: 'https://github.com',
76
- bitbucket: 'https://bitbucket.org',
76
+ github: `https://${ accessToken ? accessToken + '@' : '' }github.com`,
77
+ bitbucket: `https://${ accessToken ? accessToken + '@' : '' }bitbucket.org`,
77
78
  };
78
79
  const url = origin.url || hosts[origin.host] + '/' + origin.repo + '.git';
79
80
 
@@ -58,10 +58,10 @@ export default class Runtime extends _Runtime {
58
58
  const parseDomains = domains => _arrFrom(domains).reduce((arr, str) => arr.concat(str.split(',')), []).map(str => str.trim()).filter(str => str);
59
59
  const selectDomains = (serverDefs, matchingPort = null) => serverDefs.reduce((doms, def) => doms.length ? doms : (((!matchingPort || def.port === matchingPort) && parseDomains(def.domains || def.hostnames)) || []), []);
60
60
  // ---------------
61
- this.vhosts = new Map;
62
- if (this.cx.config.deployment.Virtualization) {
63
- const vhosts = await (new this.cx.config.deployment.Virtualization(this.cx)).read();
64
- await Promise.all((vhosts.entries || []).map(async vhost => {
61
+ this.proxied = new Map;
62
+ if (this.cx.config.deployment.Proxy) {
63
+ const proxied = await (new this.cx.config.deployment.Proxy(this.cx)).read();
64
+ await Promise.all((proxied.entries || []).map(async vhost => {
65
65
  let cx, hostnames = parseDomains(vhost.hostnames), port = vhost.port, proto = vhost.proto;
66
66
  if (vhost.path) {
67
67
  cx = this.cx.constructor.create(this.cx, Path.join(this.cx.CWD, vhost.path));
@@ -77,7 +77,7 @@ export default class Runtime extends _Runtime {
77
77
  proto || (proto = port === cx.server.https.port ? 'https' : 'http');
78
78
  }
79
79
  hostnames.length || (hostnames = ['*']);
80
- this.vhosts.set(hostnames.sort().join('|'), { cx, hostnames, port, proto });
80
+ this.proxied.set(hostnames.sort().join('|'), { cx, hostnames, port, proto });
81
81
  }));
82
82
  }
83
83
  // ---------------
@@ -118,7 +118,7 @@ export default class Runtime extends _Runtime {
118
118
  });
119
119
  // -------
120
120
  addSSLContext(this.cx.server, domains);
121
- for (const [ /*id*/, vhost ] of this.vhosts) {
121
+ for (const [ /*id*/, vhost ] of this.proxied) {
122
122
  vhost.cx && addSSLContext(vhost.cx.server, vhost.hostnames);
123
123
  }
124
124
  }
@@ -170,9 +170,9 @@ export default class Runtime extends _Runtime {
170
170
  } else {
171
171
  this.cx.logger.info(`> Server not running! No port specified.`);
172
172
  }
173
- if (this.vhosts.size) {
173
+ if (this.proxied.size) {
174
174
  this.cx.logger.info(`> Reverse proxy active.`);
175
- for (let [ id, def ] of this.vhosts) {
175
+ for (let [ id, def ] of this.proxied) {
176
176
  this.cx.logger.info(`> ${ id } >>> ${ def.port }`);
177
177
  }
178
178
  }
@@ -234,7 +234,7 @@ export default class Runtime extends _Runtime {
234
234
  const hosts = [];
235
235
  this.servers.forEach(server => hosts.push(...server.domains));
236
236
  // ------------
237
- for (const [ /*id*/, vhost ] of this.vhosts) {
237
+ for (const [ /*id*/, vhost ] of this.proxied) {
238
238
  if (vhost.hostnames.includes(url.hostname) || (vhost.hostnames.includes('*') && !hosts.includes('*'))) {
239
239
  return this.proxyGo(vhost, url, init);
240
240
  }