Skip to content

Commit 03b1b94

Browse files
committed
feat: ✨ GitOps feature, preparation for the next release v0.3.2
1 parent cca887a commit 03b1b94

File tree

11 files changed

+147
-14
lines changed

11 files changed

+147
-14
lines changed

.env.example

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,30 @@ HLAMBDA_SWAGGER_UI_TOKEN_EXPIRES_IN_SECONDS="86400"
122122
# Expires in value in seconds, time before JWT token expires and cookie is deleted on the client.
123123
HLAMBDA_VSCODE_UI_TOKEN_EXPIRES_IN_SECONDS="86400"
124124

125+
# Constant reference in code: ENV_ENABLE_HLAMBDA_GIT_SYNC | Default value: false
126+
# Turns on the GIT SYNC option, where the server will be able to sync metadata with remote repository. (Default: false)
127+
ENABLE_HLAMBDA_GIT_SYNC="false"
128+
129+
# Constant reference in code: ENV_HLAMBDA_GIT_SYNC_URL | Default value:
130+
# Sync repository url.
131+
HLAMBDA_GIT_SYNC_URL=""
132+
133+
# Constant reference in code: ENV_HLAMBDA_GIT_SYNC_USERNAME | Default value:
134+
# Sync repository username.
135+
HLAMBDA_GIT_SYNC_USERNAME=""
136+
137+
# Constant reference in code: ENV_HLAMBDA_GIT_SYNC_PASSWORD | Default value:
138+
# Sync repository password.
139+
HLAMBDA_GIT_SYNC_PASSWORD=""
140+
141+
# Constant reference in code: ENV_HLAMBDA_GIT_SYNC_BRANCH | Default value: master
142+
# Sync default branch. (Default: master) If falsey value, the current HEAD branch will be used.
143+
HLAMBDA_GIT_SYNC_BRANCH="master"
144+
145+
# Constant reference in code: ENV_HLAMBDA_GIT_SYNC_INTERVAL_SECONDS | Default value: 240
146+
# When sync is enabled, system will automatically try to sync with the current branch, it will work only if there is no conflicts, to not destroy live work. (Default: 240 (4m). If set to 0, disables pooling)
147+
HLAMBDA_GIT_SYNC_INTERVAL_SECONDS="240"
148+
125149
# Constant reference in code: ENV_HLAMBDA_CONFIGURATION_LOADER_PREFIX | Default value: hlambda-config.yaml
126150
# Sets the value for the name of the configuration file that will be loaded.
127151
HLAMBDA_CONFIGURATION_LOADER_PREFIX="hlambda-config.yaml"

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# Release 0.3.2
2+
3+
- Fixes the version bump issue.
4+
- Updated README.md
5+
- GitOps, remote repository sync.
6+
- Tab complete in Hlambda Pseudo Terminal
7+
8+
# Release 0.3.1
9+
10+
- Fix the CORS issue with the vscode when requesting external data from vscode-unpkg CDN.
11+
- Fix the issue with Webpack miss-configuration that was wrapping dist and src folder instead of only dist.
12+
113
# Release 0.3.0
214

315
- Added zero downtime reload.

Dockerfile

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ WORKDIR /usr/src/app
2020
# where available (npm@5+)
2121
COPY package*.json ./
2222

23-
# RUN echo "`date`" > ./image-build-time.txt
23+
RUN echo "`date +\"%Y-%m-%dT%H:%M:%S%z\"`" > ./image-build-time.txt
2424
RUN echo "`date +%s`" > ./image-build-timestamp.txt
2525

2626
RUN ["npm", "install"]
@@ -40,9 +40,4 @@ RUN cp -r ./metadata/* ./data/metadata-examples
4040
RUN npm install pm2 -g
4141

4242
# CMD ["npm", "run", "start"]
43-
4443
CMD [ "pm2-runtime", "start", "ecosystem.config.cjs" ]
45-
46-
# This is not ready, there are known bugs with cluster mode (state management between nodes, like path in remote shell etc...)
47-
#CMD ["npm", "run", "cluster-runtime"]
48-

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ In production deployments, you can bake metadata and disable the UI console.
4848
You can check ["Getting started"](https://www.hlambda.io/getting-started/) on how to get started with Hlambda. In short, it goes like this:
4949

5050
- Install latest hlambda CLI. (Hint: `npm i -g hlambda-cli`)
51-
- Spin up the Docker instance of the Hlambda server. (Hint: Use `hl snip d` to get docker snippet)
51+
- Spin up the Docker instance of the Hlambda server. (Hint: Use `hl snip d` to get the docker snippet)
5252
- Use CLI to generate a new Hlambda app. (Hint: `hl init my-app`)
5353
- (Optional) Configure multiple environments. (Hint: `hl env add staging`)
5454
- Deploy metadata (Hint: `hl m a`)
@@ -74,10 +74,14 @@ Any contributions are greatly appreciated.
7474

7575
## Authors
7676

77-
Gordan Nekić <gordan@neki.ch>
77+
- Gordan Nekić <gordan@neki.ch>
78+
79+
<a href="https://github.com/sponsors/gnekich" title="Sponsor Gordan Nekić"><img src="https://img.shields.io/github/sponsors/gnekich?style=plastic" alt="Github Sponsors button" /></a>
7880

7981
## How to support the project
8082

81-
I've recently created Patreon that will enable me to work more on the Hlambda services.
83+
I've recently created Patreon which will enable me to work more on the Hlambda services.
8284

8385
<span class="badge-patreon"><a href="https://www.patreon.com/bePatron?u=70751523" title="Donate to this project using Patreon"><img src="https://img.shields.io/badge/patreon-donate-green.svg" alt="Patreon donate button" /></a></span>
86+
87+
You can also sponsor the developers directly through the GitHub Sponsors program.

ecosystem.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = {
44
name: 'Backend Microservice',
55
script: 'src/index.js',
66
// script: 'npm', // Do not use this, express port binding will be problematic with npm start
7-
// args: 'run start', // Look abowe
7+
// args: 'run start', // Look above
88

99
exec_mode: 'cluster',
1010

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
env:
2+
HLAMBDA_GIT_SYNC_URL: 'https://github.com/hlambda/example-metadata-sync'
3+
HLAMBDA_GIT_SYNC_USERNAME: ''
4+
HLAMBDA_GIT_SYNC_PASSWORD: ''
5+
ENABLE_HLAMBDA_GIT_SYNC: false
6+
HLAMBDA_GIT_SYNC_INTERVAL_SECONDS: '240'

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hlambda-core",
3-
"version": "0.3.0",
3+
"version": "0.3.2",
44
"description": "Hlambda core",
55
"type": "module",
66
"main": "src/index.js",
@@ -61,4 +61,4 @@
6161
"eslint-plugin-prettier": "^4.0.0",
6262
"nodemon": "^2.0.15"
6363
}
64-
}
64+
}

src/constants/index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,40 @@ export const constants = {
195195
description: 'Expires in value in seconds, time before JWT token expires and cookie is deleted on the client.',
196196
},
197197

198+
// GitOps
199+
ENV_ENABLE_HLAMBDA_GIT_SYNC: {
200+
name: 'ENABLE_HLAMBDA_GIT_SYNC',
201+
default: 'false',
202+
description:
203+
'Turns on the GIT SYNC option, where the server will be able to sync metadata with remote repository. (Default: false)',
204+
},
205+
ENV_HLAMBDA_GIT_SYNC_URL: {
206+
name: 'HLAMBDA_GIT_SYNC_URL',
207+
default: '',
208+
description: 'Sync repository url.',
209+
},
210+
ENV_HLAMBDA_GIT_SYNC_USERNAME: {
211+
name: 'HLAMBDA_GIT_SYNC_USERNAME',
212+
default: '',
213+
description: 'Sync repository username.',
214+
},
215+
ENV_HLAMBDA_GIT_SYNC_PASSWORD: {
216+
name: 'HLAMBDA_GIT_SYNC_PASSWORD',
217+
default: '',
218+
description: 'Sync repository password.',
219+
},
220+
ENV_HLAMBDA_GIT_SYNC_BRANCH: {
221+
name: 'HLAMBDA_GIT_SYNC_BRANCH',
222+
default: 'master',
223+
description: 'Sync default branch. (Default: master) If falsey value, the current HEAD branch will be used.',
224+
},
225+
ENV_HLAMBDA_GIT_SYNC_INTERVAL_SECONDS: {
226+
name: 'HLAMBDA_GIT_SYNC_INTERVAL_SECONDS',
227+
default: '240',
228+
description:
229+
'When sync is enabled, system will automatically try to sync with the current branch, it will work only if there is no conflicts, to not destroy live work. (Default: 240 (4m). If set to 0, disables pooling)',
230+
},
231+
198232
// Loader configurations
199233
ENV_HLAMBDA_CONFIGURATION_LOADER_PREFIX: {
200234
name: 'HLAMBDA_CONFIGURATION_LOADER_PREFIX',

src/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ import execScriptCommand from './utils/execScriptCommand.js';
4747
// Create Hlambda event emmitter
4848
import hlambdaEventEmitter from './emitter/index.js';
4949

50+
// Import git sync
51+
import { startGitSync } from './utils/gitSync.js';
52+
5053
// Customized npm packages
5154
import swaggerUi from './custom/swagger-ui-express/index.js';
5255
// --------------------------------------------------------------------------------
@@ -434,6 +437,14 @@ const spinServer = async () => {
434437
console.log(`${Array(80 + 1).join('#').yellow}`);
435438
});
436439
// --------------------------------------------------------------------------------
440+
if (isEnvTrue(constants.ENV_ENABLE_HLAMBDA_GIT_SYNC)) {
441+
// console.log('Git sync is starting...'.green);
442+
await startGitSync();
443+
} else {
444+
console.log('Git sync is disabled.'.red);
445+
}
446+
console.log(`${Array(80 + 1).join('-').yellow}`);
447+
// --------------------------------------------------------------------------------
437448
// For some packages like socket.io we need reference to the server instance to attach
438449
global.HLAMBDA_SERVER_INSTANCE = server; // Legacy
439450
hlambdaEventEmitter.emit('server-ready', server);

0 commit comments

Comments
 (0)