Skip to content

Commit

Permalink
fix realise to release
Browse files Browse the repository at this point in the history
  • Loading branch information
wirwolf committed Apr 24, 2023
1 parent 95ea4ed commit f1c1548
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 25 deletions.
17 changes: 17 additions & 0 deletions .docker/node14-base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ RUN apk update && \
apk upgrade && \
apk add bash

###
### Envs
###
ENV MY_USER="app" \
MY_GROUP="app" \
MY_UID="1000" \
MY_GID="1000"

####
#### User/Group
####
RUN set -eux \
&& addgroup -g ${MY_GID} ${MY_GROUP} \
&& adduser -u ${MY_UID} -G ${MY_GROUP} -s /bin/bash -D ${MY_USER} \
&& true


# Must set this value for the bash shell to source
# the '/etc/bashrc' file.
# See: https://stackoverflow.com/q/29021704
Expand Down
8 changes: 4 additions & 4 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ HELM_ASSISTANT_DEBUG_LEVEL=1
HELM_ASSISTANT_UPGRADE_PIPE_LOGS=false
HELM_ASSISTANT_UPGRADE_PIPE_LOGS_TAIL_LINES=10
HELM_ASSISTANT_UPGRADE_JOB_STRICT=false
HELM_ASSISTANT_REALISE_LOCK_ENABLED=false
HELM_ASSISTANT_REALISE_LOCK_MAX_RETRIES=600
HELM_ASSISTANT_REALISE_LOCK_DRIVER=fs
#HELM_ASSISTANT_REALISE_LOCK_FS_DIR_PATH=/root/.resource_lock
HELM_ASSISTANT_RELEASE_LOCK_ENABLED=false
HELM_ASSISTANT_RELEASE_LOCK_MAX_RETRIES=600
HELM_ASSISTANT_RELEASE_LOCK_DRIVER=fs
#HELM_ASSISTANT_RELEASE_LOCK_FS_DIR_PATH=/root/.resource_lock
1 change: 1 addition & 0 deletions .github/workflows/npm-build-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
with:
node-version: '16.x'
- run: yarn
- run: yarn run lint
- run: yarn run build
- name: Archive binary
uses: actions/upload-artifact@v3
Expand Down
1 change: 0 additions & 1 deletion src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {VersionModule} from './Modules/VersionModule';
import * as console from 'console';
import {hideBin} from 'yargs/helpers';
import * as yargs from 'yargs';
import Logger from './Components/Logger';

loadEnvVariablesFromFile();

Expand Down
10 changes: 6 additions & 4 deletions src/Components/ProcessLocker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export default class ProcessLocker {

public constructor() {
this.options = {
maxRetries: ConfigFactory.getCore().HELM_ASSISTANT_REALISE_LOCK_MAX_RETRIES,
driver: ConfigFactory.getCore().HELM_ASSISTANT_REALISE_LOCK_DRIVER,
fsDirPath: ConfigFactory.getCore().HELM_ASSISTANT_REALISE_LOCK_FS_DIR_PATH
maxRetries: ConfigFactory.getCore().HELM_ASSISTANT_RELEASE_LOCK_MAX_RETRIES,
driver: ConfigFactory.getCore().HELM_ASSISTANT_RELEASE_LOCK_DRIVER,
fsDirPath: ConfigFactory.getCore().HELM_ASSISTANT_RELEASE_LOCK_FS_DIR_PATH
};
}
public async getLock(resource: string): Promise<boolean> {
Expand All @@ -36,7 +36,9 @@ export default class ProcessLocker {
}
}.bind(this));
} else {
process.stderr.write('[realise-locker] DEBUG: lock file not found' + '\n');
if (ConfigFactory.getCore().HELM_ASSISTANT_DEBUG_LEVEL >= 1) {
process.stderr.write('[realise-locker] DEBUG: lock file not found' + '\n');
}
resolve(true);
}
}.bind(this));
Expand Down
16 changes: 8 additions & 8 deletions src/Config/app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class ConfigFactory {

public static getCore(): CoreConfigInterface {
return {
HELM_ASSISTANT_REALISE_LOCK_DRIVER: '',
HELM_ASSISTANT_RELEASE_LOCK_DRIVER: '',
HELM_BIN_PATH: env('HELM_BIN_PATH', 'helm'),
HELM_CMD_ARGS: env('HELM_CMD_ARGS', ''),
KUBECTL_BIN_PATH: env('KUBECTL_BIN_PATH', 'kubectl'),
Expand All @@ -27,9 +27,9 @@ export class ConfigFactory {
HELM_ASSISTANT_UPGRADE_PIPE_LOGS: envBoolean('HELM_ASSISTANT_UPGRADE_PIPE_LOGS', false),
HELM_ASSISTANT_UPGRADE_PIPE_LOGS_TAIL_LINES: envNumber('HELM_ASSISTANT_UPGRADE_PIPE_LOGS_TAIL_LINES', 10, 0),
HELM_ASSISTANT_UPGRADE_JOB_STRICT: envBoolean('HELM_ASSISTANT_UPGRADE_JOB_STRICT', false),
HELM_ASSISTANT_REALISE_LOCK_ENABLED: envBoolean('HELM_ASSISTANT_REALISE_LOCK_ENABLED', false),
HELM_ASSISTANT_REALISE_LOCK_MAX_RETRIES: envNumber('HELM_ASSISTANT_REALISE_LOCK_MAX_RETRIES', 600, 0),
HELM_ASSISTANT_REALISE_LOCK_FS_DIR_PATH: env('HELM_ASSISTANT_REALISE_LOCK_FS_DIR_PATH', os.homedir() + '/.resource_lock')
HELM_ASSISTANT_RELEASE_LOCK_ENABLED: envBoolean('HELM_ASSISTANT_RELEASE_LOCK_ENABLED', false),
HELM_ASSISTANT_RELEASE_LOCK_MAX_RETRIES: envNumber('HELM_ASSISTANT_RELEASE_LOCK_MAX_RETRIES', 600, 0),
HELM_ASSISTANT_RELEASE_LOCK_FS_DIR_PATH: env('HELM_ASSISTANT_RELEASE_LOCK_FS_DIR_PATH', os.homedir() + '/.resource_lock')
};
}
}
Expand All @@ -53,8 +53,8 @@ interface CoreConfigInterface {
HELM_ASSISTANT_UPGRADE_PIPE_LOGS: boolean;
HELM_ASSISTANT_UPGRADE_PIPE_LOGS_TAIL_LINES: number;
HELM_ASSISTANT_UPGRADE_JOB_STRICT: boolean;
HELM_ASSISTANT_REALISE_LOCK_ENABLED: boolean;
HELM_ASSISTANT_REALISE_LOCK_MAX_RETRIES: number;
HELM_ASSISTANT_REALISE_LOCK_DRIVER: string;
HELM_ASSISTANT_REALISE_LOCK_FS_DIR_PATH: string;
HELM_ASSISTANT_RELEASE_LOCK_ENABLED: boolean;
HELM_ASSISTANT_RELEASE_LOCK_MAX_RETRIES: number;
HELM_ASSISTANT_RELEASE_LOCK_DRIVER: string;
HELM_ASSISTANT_RELEASE_LOCK_FS_DIR_PATH: string;
}
16 changes: 8 additions & 8 deletions src/Modules/UpgradeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const cliColor = require('cli-color');
export class UpgradeModule {
private isExit: boolean = false;
private subProcesses: { [n: string]: ChildProcessWithoutNullStreams } = {};
private realiseName: string = '';
private releaseName: string = '';
private namespace: string = '';
private timeouts: NodeJS.Timeout[] = [];
private intervals: any[] = [];
Expand All @@ -33,10 +33,10 @@ export class UpgradeModule {
// }
// }, 500);
// }
this.realiseName = cliArgs._[1];
this.releaseName = cliArgs._[1];
this.namespace = cliArgs.namespace;
if (ConfigFactory.getCore().HELM_ASSISTANT_REALISE_LOCK_ENABLED === true) {
await this.lockComponent.getLock(this.namespace + '-' + this.realiseName);
if (ConfigFactory.getCore().HELM_ASSISTANT_RELEASE_LOCK_ENABLED === true) {
await this.lockComponent.getLock(this.namespace + '-' + this.releaseName);
}

if (ConfigFactory.getCore().HELM_ASSISTANT_UPGRADE_PIPE_LOGS === true) {
Expand All @@ -57,7 +57,7 @@ export class UpgradeModule {
this.intervals.forEach((item) => {
clearInterval(item);
});
await this.lockComponent.clearLock(this.namespace + '-' + this.realiseName);
await this.lockComponent.clearLock(this.namespace + '-' + this.releaseName);

Logger.trace('UpgradeModule:stop', 'Stop all subprocess', {count: Object.entries(this.subProcesses).length});
let promises = Object.entries(this.subProcesses).map((entry) => {
Expand Down Expand Up @@ -93,7 +93,7 @@ export class UpgradeModule {
'get', 'pods',
'--watch',
'--namespace', ConfigFactory.getCore().KUBE_NAMESPACE,
'--selector', 'app.kubernetes.io/instance=' + this.realiseName
'--selector', 'app.kubernetes.io/instance=' + this.releaseName
];
await this.createChildProcess(ConfigFactory.getCore().KUBECTL_BIN_PATH, args, false, false, true, 'pods', 'magenta');

Expand All @@ -106,7 +106,7 @@ export class UpgradeModule {
...ConfigFactory.getCore().KUBECTL_CMD_ARGS.split(' '),
'get', 'pods',
'--namespace', ConfigFactory.getCore().KUBE_NAMESPACE,
'--selector', 'app.kubernetes.io/instance=' + this.realiseName,
'--selector', 'app.kubernetes.io/instance=' + this.releaseName,
'-o', 'json'
];
const pods = await this.createChildProcess(ConfigFactory.getCore().KUBECTL_BIN_PATH, newProcessArgs, true, true);
Expand Down Expand Up @@ -167,7 +167,7 @@ export class UpgradeModule {
[
...ConfigFactory.getCore().KUBECTL_CMD_ARGS.split(' '),
'get', 'job',
this.realiseName,
this.releaseName,
'-o', 'json',
'--namespace', ConfigFactory.getCore().KUBE_NAMESPACE,
];
Expand Down

0 comments on commit f1c1548

Please sign in to comment.