docker pipeline refactor

This commit is contained in:
Jan Prochazka
2024-12-29 09:57:18 +01:00
parent 2858bba8b2
commit 70873e83bd
3 changed files with 56 additions and 24 deletions

View File

@@ -36,9 +36,11 @@ function processJsonStep(json, args) {
return _.cloneDeepWith(json, value => {
if (_.isArray(value)) {
const res = [];
let arrayModified = false;
for (const item of value) {
if (item._if) {
modified = true;
arrayModified = true;
if (conditionMatch(item._if, args)) {
res.push(_.omit(item, ['_if']));
}
@@ -46,6 +48,7 @@ function processJsonStep(json, args) {
const replaceWith = item._replace ? args.replace?.[item._replace] : includes[item._include];
if (replaceWith) {
modified = true;
arrayModified = true;
if (_.isArray(replaceWith)) {
res.push(...replaceWith);
} else {
@@ -58,7 +61,10 @@ function processJsonStep(json, args) {
res.push(item);
}
}
return res;
if (arrayModified) {
return res;
}
return undefined;
}
// 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) {
modified = true;
return includes[value?._include];
}
if (value?._replace) {
modified = true;
return args?.replace[value?._replace];
}
});
@@ -113,6 +136,9 @@ function processJson(json, args = {}) {
}
function processFiles() {
const dumpOptions = {
lineWidth: -1,
};
for (const file of fs.readdirSync(indir)) {
const text = fs.readFileSync(path.join(indir, file), { encoding: 'utf-8' });
const json = yaml.load(text);
@@ -126,15 +152,16 @@ function processFiles() {
const allNames = Object.keys(json._templates);
const args = {
key,
run: json._templates[key],
replace: json._templates[key]?.replace,
stringReplace: json._templates[key]?.['string-replace'],
allNames,
};
const converted = processJson(_.omit(json, ['_templates']), args);
const out = path.join(outdir, json._templates[key].file);
fs.writeFileSync(out, yaml.dump(converted));
fs.writeFileSync(out, yaml.dump(converted, dumpOptions));
}
} else {
fs.writeFileSync(path.join(outdir, file), yaml.dump(processJson(json)));
fs.writeFileSync(path.join(outdir, file), yaml.dump(processJson(json), dumpOptions));
}
}
}

View File

@@ -1,20 +1,20 @@
_templates:
_community:
file: build-docker.yaml
replace:
_cd_merged:
- cd ..
- cd dbgate-merged
string-replace:
"<<cd_merged>>": ''
"<<name>>": community
_premium:
file: build-docker-pro.yaml
replace:
_cd_merged:
- cd ..
- cd dbgate-merged
string-replace:
"<<cd_merged>>": |
cd ..
cd dbgate-merged
"<<name>>": premium
name:
_community: Docker image Community
_premium: Docker image Premium
_premium: Docker image PREMIUM
on:
push:
@@ -75,33 +75,35 @@ jobs:
with:
node-version: 18.x
- _include: checkout-dbgate-pro
_if: _premium
- _include: merge-dbgate-pro
- _include: checkout-and-merge-pro
_if: _premium
- name: adjustPackageJson
run: |
node adjustPackageJson --community
<<cd_merged>>
node adjustPackageJson --<<name>>
- name: yarn install
run: |
<<cd_merged>>
# yarn --version
# yarn config set network-timeout 300000
yarn install
- name: setCurrentVersion
run: |
<<cd_merged>>
yarn setCurrentVersion
- name: printSecrets
run: |
yarn printSecrets
<<cd_merged>>
yarn printSecrets
env:
GIST_UPLOAD_SECRET : ${{secrets.GIST_UPLOAD_SECRET}}
- name: Prepare docker image
run: |
<<cd_merged>>
yarn run prepare:docker
- name: Set up Docker Buildx
@@ -116,12 +118,17 @@ jobs:
uses: docker/build-push-action@v3
with:
push: true
context: ./docker
context:
_community: ./docker
_premium: ../dbgate-merged/docker
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
uses: docker/build-push-action@v3
_if: _community
with:
push: true
context: ./docker

View File

@@ -1,14 +1,12 @@
_module: true
checkout-dbgate-pro:
checkout-and-merge-pro:
- name: Checkout dbgate/dbgate-pro
uses: actions/checkout@v2
with:
repository: dbgate/dbgate-pro
token: ${{ secrets.GH_TOKEN }}
path: dbgate-pro
merge-dbgate-pro:
- name: Merge dbgate/dbgate-pro
run: |
mkdir ../dbgate-pro