mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 19:33:59 +00:00
docker pipeline refactor
This commit is contained in:
@@ -36,9 +36,11 @@ function processJsonStep(json, args) {
|
|||||||
return _.cloneDeepWith(json, value => {
|
return _.cloneDeepWith(json, value => {
|
||||||
if (_.isArray(value)) {
|
if (_.isArray(value)) {
|
||||||
const res = [];
|
const res = [];
|
||||||
|
let arrayModified = false;
|
||||||
for (const item of value) {
|
for (const item of value) {
|
||||||
if (item._if) {
|
if (item._if) {
|
||||||
modified = true;
|
modified = true;
|
||||||
|
arrayModified = true;
|
||||||
if (conditionMatch(item._if, args)) {
|
if (conditionMatch(item._if, args)) {
|
||||||
res.push(_.omit(item, ['_if']));
|
res.push(_.omit(item, ['_if']));
|
||||||
}
|
}
|
||||||
@@ -46,6 +48,7 @@ function processJsonStep(json, args) {
|
|||||||
const replaceWith = item._replace ? args.replace?.[item._replace] : includes[item._include];
|
const replaceWith = item._replace ? args.replace?.[item._replace] : includes[item._include];
|
||||||
if (replaceWith) {
|
if (replaceWith) {
|
||||||
modified = true;
|
modified = true;
|
||||||
|
arrayModified = true;
|
||||||
if (_.isArray(replaceWith)) {
|
if (_.isArray(replaceWith)) {
|
||||||
res.push(...replaceWith);
|
res.push(...replaceWith);
|
||||||
} else {
|
} else {
|
||||||
@@ -58,7 +61,10 @@ function processJsonStep(json, args) {
|
|||||||
res.push(item);
|
res.push(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
if (arrayModified) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (value?.run && _.isArray(value.run)) {
|
// if (value?.run && _.isArray(value.run)) {
|
||||||
@@ -90,11 +96,28 @@ function processJsonStep(json, args) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_.isString(value)) {
|
||||||
|
let stringModified = false;
|
||||||
|
for (const key of Object.keys(args.stringReplace ?? {})) {
|
||||||
|
if (value.includes(key)) {
|
||||||
|
modified = true;
|
||||||
|
stringModified = true;
|
||||||
|
value = value.replaceAll(key, args.stringReplace[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (stringModified) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
if (value?._include) {
|
if (value?._include) {
|
||||||
|
modified = true;
|
||||||
return includes[value?._include];
|
return includes[value?._include];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value?._replace) {
|
if (value?._replace) {
|
||||||
|
modified = true;
|
||||||
return args?.replace[value?._replace];
|
return args?.replace[value?._replace];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -113,6 +136,9 @@ function processJson(json, args = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function processFiles() {
|
function processFiles() {
|
||||||
|
const dumpOptions = {
|
||||||
|
lineWidth: -1,
|
||||||
|
};
|
||||||
for (const file of fs.readdirSync(indir)) {
|
for (const file of fs.readdirSync(indir)) {
|
||||||
const text = fs.readFileSync(path.join(indir, file), { encoding: 'utf-8' });
|
const text = fs.readFileSync(path.join(indir, file), { encoding: 'utf-8' });
|
||||||
const json = yaml.load(text);
|
const json = yaml.load(text);
|
||||||
@@ -126,15 +152,16 @@ function processFiles() {
|
|||||||
const allNames = Object.keys(json._templates);
|
const allNames = Object.keys(json._templates);
|
||||||
const args = {
|
const args = {
|
||||||
key,
|
key,
|
||||||
run: json._templates[key],
|
replace: json._templates[key]?.replace,
|
||||||
|
stringReplace: json._templates[key]?.['string-replace'],
|
||||||
allNames,
|
allNames,
|
||||||
};
|
};
|
||||||
const converted = processJson(_.omit(json, ['_templates']), args);
|
const converted = processJson(_.omit(json, ['_templates']), args);
|
||||||
const out = path.join(outdir, json._templates[key].file);
|
const out = path.join(outdir, json._templates[key].file);
|
||||||
fs.writeFileSync(out, yaml.dump(converted));
|
fs.writeFileSync(out, yaml.dump(converted, dumpOptions));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fs.writeFileSync(path.join(outdir, file), yaml.dump(processJson(json)));
|
fs.writeFileSync(path.join(outdir, file), yaml.dump(processJson(json), dumpOptions));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
_templates:
|
_templates:
|
||||||
_community:
|
_community:
|
||||||
file: build-docker.yaml
|
file: build-docker.yaml
|
||||||
replace:
|
string-replace:
|
||||||
_cd_merged:
|
"<<cd_merged>>": ''
|
||||||
- cd ..
|
"<<name>>": community
|
||||||
- cd dbgate-merged
|
|
||||||
_premium:
|
_premium:
|
||||||
file: build-docker-pro.yaml
|
file: build-docker-pro.yaml
|
||||||
replace:
|
string-replace:
|
||||||
_cd_merged:
|
"<<cd_merged>>": |
|
||||||
- cd ..
|
cd ..
|
||||||
- cd dbgate-merged
|
cd dbgate-merged
|
||||||
|
"<<name>>": premium
|
||||||
|
|
||||||
name:
|
name:
|
||||||
_community: Docker image Community
|
_community: Docker image Community
|
||||||
_premium: Docker image Premium
|
_premium: Docker image PREMIUM
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -75,33 +75,35 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
node-version: 18.x
|
node-version: 18.x
|
||||||
|
|
||||||
- _include: checkout-dbgate-pro
|
- _include: checkout-and-merge-pro
|
||||||
_if: _premium
|
|
||||||
|
|
||||||
- _include: merge-dbgate-pro
|
|
||||||
_if: _premium
|
_if: _premium
|
||||||
|
|
||||||
- name: adjustPackageJson
|
- name: adjustPackageJson
|
||||||
run: |
|
run: |
|
||||||
node adjustPackageJson --community
|
<<cd_merged>>
|
||||||
|
node adjustPackageJson --<<name>>
|
||||||
|
|
||||||
- name: yarn install
|
- name: yarn install
|
||||||
run: |
|
run: |
|
||||||
|
<<cd_merged>>
|
||||||
# yarn --version
|
# yarn --version
|
||||||
# yarn config set network-timeout 300000
|
# yarn config set network-timeout 300000
|
||||||
yarn install
|
yarn install
|
||||||
|
|
||||||
- name: setCurrentVersion
|
- name: setCurrentVersion
|
||||||
run: |
|
run: |
|
||||||
|
<<cd_merged>>
|
||||||
yarn setCurrentVersion
|
yarn setCurrentVersion
|
||||||
|
|
||||||
- name: printSecrets
|
- name: printSecrets
|
||||||
run: |
|
run: |
|
||||||
yarn printSecrets
|
<<cd_merged>>
|
||||||
|
yarn printSecrets
|
||||||
env:
|
env:
|
||||||
GIST_UPLOAD_SECRET : ${{secrets.GIST_UPLOAD_SECRET}}
|
GIST_UPLOAD_SECRET : ${{secrets.GIST_UPLOAD_SECRET}}
|
||||||
- name: Prepare docker image
|
- name: Prepare docker image
|
||||||
run: |
|
run: |
|
||||||
|
<<cd_merged>>
|
||||||
yarn run prepare:docker
|
yarn run prepare:docker
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
@@ -116,12 +118,17 @@ jobs:
|
|||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
push: true
|
push: true
|
||||||
context: ./docker
|
context:
|
||||||
|
_community: ./docker
|
||||||
|
_premium: ../dbgate-merged/docker
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
platforms:
|
||||||
|
_community: linux/amd64,linux/arm64,linux/arm/v7
|
||||||
|
_premium: linux/amd64,linux/arm64
|
||||||
|
|
||||||
- name: Build and push alpine
|
- name: Build and push alpine
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v3
|
||||||
|
_if: _community
|
||||||
with:
|
with:
|
||||||
push: true
|
push: true
|
||||||
context: ./docker
|
context: ./docker
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
_module: true
|
_module: true
|
||||||
|
|
||||||
checkout-dbgate-pro:
|
checkout-and-merge-pro:
|
||||||
- name: Checkout dbgate/dbgate-pro
|
- name: Checkout dbgate/dbgate-pro
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
repository: dbgate/dbgate-pro
|
repository: dbgate/dbgate-pro
|
||||||
token: ${{ secrets.GH_TOKEN }}
|
token: ${{ secrets.GH_TOKEN }}
|
||||||
path: dbgate-pro
|
path: dbgate-pro
|
||||||
|
|
||||||
merge-dbgate-pro:
|
|
||||||
- name: Merge dbgate/dbgate-pro
|
- name: Merge dbgate/dbgate-pro
|
||||||
run: |
|
run: |
|
||||||
mkdir ../dbgate-pro
|
mkdir ../dbgate-pro
|
||||||
|
|||||||
Reference in New Issue
Block a user