Commit b46222f7 authored by nanahira's avatar nanahira

first

parents
node_modules
*.js
*.js.map
.vs*
.dockerignore
.git*
Dockerfile
node_modules
*.js
*.js.map
.vs*
stages:
- build
- deploy
variables:
GIT_DEPTH: "1"
CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
build:
stage: build
tags:
- docker
script:
- docker build --pull -t $CONTAINER_TEST_IMAGE .
- docker push $CONTAINER_TEST_IMAGE
deploy_latest:
stage: deploy
tags:
- docker
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE
- docker push $CONTAINER_RELEASE_IMAGE
only:
- master
deploy_tag:
stage: deploy
tags:
- docker
variables:
CONTAINER_TAG_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_TAG_IMAGE
- docker push $CONTAINER_TAG_IMAGE
only:
- tags
FROM node:buster-slim
RUN apt update && \
apt -y install build-essential python3 && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm ci
COPY . ./
RUN npm run build
CMD ["npm", "run", "start"]
This diff is collapsed.
{
"name": "idrac-xml-replacer",
"version": "1.0.0",
"description": "Replace iDRAC address",
"main": "server.js",
"dependencies": {
"@types/express": "^4.17.6",
"@types/express-http-proxy": "^1.6.1",
"@types/iconv-lite": "0.0.1",
"@types/node": "^14.0.14",
"@types/xml2js": "^0.4.5",
"express": "^4.17.1",
"express-http-proxy": "^1.6.0",
"iconv-lite": "^0.6.1",
"typescript": "^3.9.5",
"xml2js": "^0.4.23"
},
"devDependencies": {},
"scripts": {
"build": "./node_modules/.bin/tsc",
"start": "node server.js"
},
"author": "Nanahira",
"license": "ISC"
}
import express from "express";
import proxy from "express-http-proxy";
import zlib from "zlib";
import util from "util";
import iconv from "iconv-lite";
import xml from "xml2js";
const gzip: (b: Buffer) => Promise<Buffer> = util.promisify(zlib.gzip);
const gunzip: (b: Buffer) => Promise<Buffer> = util.promisify(zlib.gunzip);
const xmlParser = new xml.Parser();
const xmlBuilder = new xml.Builder();
const baseLocation: string = process.env.BASE_LOCATION;
const baseLocationAccessProtocols: string = process.env.PROTOCOL || "HTTP";
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use('/', proxy("https://downloads.dell.com,", {
userResDecorator: async (proxyRes, proxyResData, userReq, userRes) => {
if (userReq.url.startsWith("/catalog/catalog.xml.gz")) {
const content = iconv.decode(await gunzip(proxyResData), "utf16");
const xmlObject: any = await xmlParser.parseStringPromise(content);
xmlObject.Manifest.$.baseLocation = baseLocation;
xmlObject.Manifest.$.baseLocationAccessProtocols = baseLocationAccessProtocols;
const replaceContent = xmlBuilder.buildObject(xmlObject);
return await gzip(iconv.encode(replaceContent, "utf16"));
}
return proxyResData;
}
}));
app.listen(80);
{
"compilerOptions": {
"module": "commonjs",
"target": "esnext",
"esModuleInterop": true,
"resolveJsonModule": true,
"sourceMap": true
},
"compileOnSave": true,
"allowJs": true,
"include": [
"*.ts"
]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment