Skip to content

Commit 796373b

Browse files
Merge pull request #4074 from RedisInsight/feature/RI-6281_enhance_Github_Actions
#RI-6281 - enhance GitHub actions
2 parents f3dfb21 + 512b433 commit 796373b

35 files changed

+2862
-2047
lines changed

.circleci/config.yml

Lines changed: 7 additions & 1829 deletions
Large diffs are not rendered by default.

.circleci/config.yml.backup

Lines changed: 1847 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Get current date
2+
3+
outputs:
4+
date:
5+
description: Current date
6+
value: ${{ steps.date.outputs.date }}
7+
8+
runs:
9+
using: 'composite'
10+
steps:
11+
- name: Get current date
12+
id: date
13+
shell: bash
14+
run: |
15+
DATE=$(date +'%Y-%m-%d')
16+
echo "date=$DATE" >> $GITHUB_OUTPUT
17+

.github/build/build.Dockerfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
FROM node:20.14-alpine
2+
3+
# runtime args and environment variables
4+
ARG DIST=Redis-Insight.tar.gz
5+
ARG NODE_ENV=production
6+
ARG RI_SEGMENT_WRITE_KEY
7+
ENV RI_SEGMENT_WRITE_KEY=${RI_SEGMENT_WRITE_KEY}
8+
ENV NODE_ENV=${NODE_ENV}
9+
ENV RI_SERVE_STATICS=true
10+
ENV RI_BUILD_TYPE='DOCKER_ON_PREMISE'
11+
ENV RI_APP_FOLDER_ABSOLUTE_PATH='/data'
12+
13+
# this resolves CVE-2023-5363
14+
# TODO: remove this line once we update to base image that doesn't have this vulnerability
15+
RUN apk update && apk upgrade --no-cache libcrypto3 libssl3
16+
17+
# set workdir
18+
WORKDIR /usr/src/app
19+
20+
# copy artifacts built in previous stage to this one
21+
ADD $DIST /usr/src/app/redisinsight
22+
RUN ls -la /usr/src/app/redisinsight
23+
24+
# folder to store local database, plugins, logs and all other files
25+
RUN mkdir -p /data && chown -R node:node /data
26+
27+
# copy the docker entry point script and make it executable
28+
COPY --chown=node:node ./docker-entry.sh ./
29+
RUN chmod +x docker-entry.sh
30+
31+
# since RI is hard-code to port 5000, expose it from the container
32+
EXPOSE 5000
33+
34+
# don't run the node process as root
35+
USER node
36+
37+
# serve the application 🚀
38+
ENTRYPOINT ["./docker-entry.sh", "node", "redisinsight/api/dist/src/main"]

.github/build/build.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# install deps
5+
yarn
6+
yarn --cwd redisinsight/api
7+
8+
# build
9+
10+
yarn build:statics
11+
yarn build:ui
12+
yarn --cwd ./redisinsight/api build:prod

.github/build/build_modules.sh

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/bin/bash
2+
set -e
3+
4+
PLATFORM=${PLATFORM:-'linux'}
5+
ARCH=${ARCH:-'x64'}
6+
LIBC=${LIBC:-''}
7+
#FILENAME="Redis-Insight-$PLATFORM.$VERSION.$ARCH.zip"
8+
FILENAME="Redis-Insight-web-$PLATFORM"
9+
if [ ! -z $LIBC ]
10+
then
11+
FILENAME="$FILENAME-$LIBC.$ARCH.tar.gz"
12+
export npm_config_target_libc="$LIBC"
13+
else
14+
FILENAME="$FILENAME.$ARCH.tar.gz"
15+
fi
16+
17+
echo "Building node modules..."
18+
echo "Platform: $PLATFORM"
19+
echo "Arch: $ARCH"
20+
echo "Libc: $LIBC"
21+
echo "npm target libc: $npm_config_target_libc"
22+
echo "Filname: $FILENAME"
23+
24+
rm -rf redisinsight/api/node_modules
25+
26+
npm_config_arch="$ARCH" \
27+
npm_config_target_arch="$ARCH" \
28+
npm_config_platform="$PLATFORM" \
29+
npm_config_target_platform="$PLATFORM" \
30+
yarn --cwd ./redisinsight/api install --production
31+
32+
cp redisinsight/api/.yarnclean.prod redisinsight/api/.yarnclean
33+
yarn --cwd ./redisinsight/api autoclean --force
34+
35+
rm -rf redisinsight/build.zip
36+
37+
cp LICENSE ./redisinsight
38+
39+
cd redisinsight && tar -czf build.tar.gz \
40+
--exclude="api/node_modules/**/build/node_gyp_bins/python3" \
41+
api/node_modules \
42+
api/dist \
43+
ui/dist \
44+
LICENSE \
45+
&& cd ..
46+
47+
mkdir -p release/web
48+
cp redisinsight/build.tar.gz release/web/"$FILENAME"
49+
50+
# Minify build via esbuild
51+
echo "Start minifing workflow"
52+
npm_config_arch="$ARCH" \
53+
npm_config_target_arch="$ARCH" \
54+
npm_config_platform="$PLATFORM" \
55+
npm_config_target_platform="$PLATFORM" \
56+
yarn --cwd ./redisinsight/api install
57+
yarn --cwd ./redisinsight/api minify:prod
58+
59+
60+
PACKAGE_JSON_PATH="./redisinsight/api/package.json"
61+
APP_PACKAGE_JSON_PATH="./redisinsight/package.json"
62+
63+
# Extract dependencies from the app package.json
64+
BINARY_PACKAGES=$(jq -r '.dependencies | keys[]' "$APP_PACKAGE_JSON_PATH" | jq -R -s -c 'split("\n")[:-1]')
65+
66+
echo "Binary packages to exclude during minify: $BINARY_PACKAGES"
67+
68+
# Modify the package.json
69+
jq --argjson keep "$BINARY_PACKAGES" \
70+
'del(.devDependencies) | .dependencies |= with_entries(select(.key as $k | $keep | index($k)))' \
71+
"$PACKAGE_JSON_PATH" > temp.json && mv temp.json "$PACKAGE_JSON_PATH"
72+
73+
npm_config_arch="$ARCH" \
74+
npm_config_target_arch="$ARCH" \
75+
npm_config_platform="$PLATFORM" \
76+
npm_config_target_platform="$PLATFORM" \
77+
yarn --cwd ./redisinsight/api install --production
78+
yarn --cwd ./redisinsight/api autoclean --force
79+
80+
# Compress minified build
81+
cd redisinsight && tar -czf build-mini.tar.gz \
82+
--exclude="api/node_modules/**/build/node_gyp_bins/python3" \
83+
api/node_modules \
84+
api/dist-minified \
85+
ui/dist \
86+
LICENSE \
87+
&& cd ..
88+
89+
mkdir -p release/web-mini
90+
cp redisinsight/build-mini.tar.gz release/web-mini/"$FILENAME"
91+
92+
# Restore the original package.json and yarn.lock
93+
git restore redisinsight/api/yarn.lock redisinsight/api/package.json
94+

.github/build/sum_sha256.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
set -e
3+
4+
find ./release -type f -name '*.tar.gz' -execdir sh -c 'sha256sum "$1" > "$1.sha256"' _ {} \;

.github/deps-audit-report.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
const fs = require('fs');
2+
const { exec } = require("child_process");
3+
4+
const FILENAME = process.env.FILENAME;
5+
const DEPS = process.env.DEPS || '';
6+
const file = `${FILENAME}`;
7+
const outputFile = `slack.${FILENAME}`;
8+
9+
function generateSlackMessage (summary) {
10+
const message = {
11+
text: `DEPS AUDIT: *${DEPS}* result (Branch: *${process.env.GITHUB_REF_NAME}*)` +
12+
`\nScanned ${summary.totalDependencies} dependencies` +
13+
`\n<https://github.com/RedisInsight/RedisInsight/actions/runs/${process.env.GITHUB_RUN_ID}|View on Github Actions>`,
14+
attachments: [],
15+
};
16+
17+
if (summary.totalVulnerabilities) {
18+
if (summary.vulnerabilities.critical) {
19+
message.attachments.push({
20+
title: 'Critical',
21+
color: '#641E16',
22+
text: `${summary.vulnerabilities.critical}`,
23+
});
24+
}
25+
if (summary.vulnerabilities.high) {
26+
message.attachments.push({
27+
title: 'High',
28+
color: '#C0392B',
29+
text: `${summary.vulnerabilities.high}`,
30+
});
31+
}
32+
if (summary.vulnerabilities.moderate) {
33+
message.attachments.push({
34+
title: 'Moderate',
35+
color: '#F5B041',
36+
text: `${summary.vulnerabilities.moderate}`,
37+
});
38+
}
39+
if (summary.vulnerabilities.low) {
40+
message.attachments.push({
41+
title: 'Low',
42+
color: '#F9E79F',
43+
text: `${summary.vulnerabilities.low}`,
44+
});
45+
}
46+
if (summary.vulnerabilities.info) {
47+
message.attachments.push({
48+
title: 'Info',
49+
text: `${summary.vulnerabilities.info}`,
50+
});
51+
}
52+
} else {
53+
message.attachments.push(
54+
{
55+
title: 'No vulnerabilities found',
56+
color: 'good'
57+
}
58+
);
59+
}
60+
61+
return message;
62+
}
63+
64+
async function main() {
65+
const lastAuditLine = await new Promise((resolve, reject) => {
66+
exec(`tail -n 1 ${file}`, (error, stdout, stderr) => {
67+
if (error) {
68+
return reject(error);
69+
}
70+
resolve(stdout);
71+
})
72+
})
73+
74+
const { data: summary } = JSON.parse(`${lastAuditLine}`);
75+
const vulnerabilities = summary?.vulnerabilities || {};
76+
summary.totalVulnerabilities = Object.values(vulnerabilities).reduce((totalVulnerabilities, val) => totalVulnerabilities + val)
77+
fs.writeFileSync(outputFile, JSON.stringify({
78+
channel: process.env.SLACK_AUDIT_REPORT_CHANNEL,
79+
...generateSlackMessage(summary),
80+
}));
81+
}
82+
83+
main();

0 commit comments

Comments
 (0)