Commit ce88313d authored by nanahira's avatar nanahira

unfinished

parent a797a9ab
Pipeline #285 passed with stages
in 3 minutes and 4 seconds
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
/build
/output
.git*
.dockerignore
Dockerfile
.gitlab-ci.yml
/config.yaml
/docker-compose.yml
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
/build
/output
/config.yaml
/docker-compose.yml
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 python3 ca-certificates gnupg2 && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /usr/src/app
COPY ./package*.json ./
RUN npm ci && npm cache clean --force
COPY . ./
RUN npm run build
ENV NODE_TLS_REJECT_UNAUTHORIZED 0
This diff is collapsed.
url: https://vc.example.com
username: administrator@vc.example.com
password: password_here
plans:
- host: host.example.com
folder: runners
datastore: datastore1
template: runner-template-debian
import { Config } from "./src/config";
import { getIP, createVM } from "./src/actions";
async function main() {
const config = new Config();
console.error(`Logining into vCenter...`);
await config.load();
const vmName = process.argv[3];
switch (process.argv[2]) {
case "ip": {
console.error(`Fetching IP address of ${vmName}.`)
const ip = await getIP(config.vc, {
names: vmName
});
console.log(ip);
break;
}
case "create": {
const plan = config.plans[Math.floor(Math.random() * config.plans.length)];
console.error(`Creating VM with name ${vmName} info ${JSON.stringify(plan)}`);
await createVM(config.vc, vmName, plan);
console.error(`Done.`);
break;
}
}
}
main();
This diff is collapsed.
{
"name": "gitlab-runner-vcenter-executor",
"version": "1.0.0",
"description": "GitLab runner custom executor for ESXi",
"main": "build/index.js",
"scripts": {
"build": "./node_modules/.bin/tsc",
"test": "node build/test/create-vm.js"
},
"repository": {
"type": "git",
"url": "git@git.mycard.moe:nanahira/gitlab-runner-vcenter-executor.git"
},
"keywords": [
"ESXi",
"VCenter",
"GitLab"
],
"author": "Nanahira",
"license": "GPL-3.0",
"dependencies": {
"@types/node": "^14.0.18",
"@types/underscore": "^1.10.4",
"@types/yaml": "^1.9.7",
"q": "^1.5.1",
"ts-vcenter": "^0.3.11",
"typescript": "^3.9.6",
"underscore": "^1.10.2",
"yaml": "^1.10.0"
}
}
import { Config, Plan } from "./config";
import { vCenter } from "ts-vcenter";
export async function getIP(vcsa: vCenter, filter: any) {
const [vm] = await vcsa.getVMs(filter);
const vmInfo = await vcsa.getGuestInfo(vm.vm);
return vmInfo.ip_address;
}
export async function createVM(vcsa: vCenter, name: string, plan: Plan) {
const [Libraries] = await Promise.all([vcsa.getContentLibrarys()]);
const template = Libraries.find(({ items }) => items.find(({ name }) => name === plan.template)).items.find(
({ name }) => name === plan.template,
);
const [hosts, Datastores, Folders] = await Promise.all([
vcsa.getHosts(),
vcsa.getDataStores(),
vcsa.getFolders(),
]);
//console.error(`Fetching templates..`);
//const Template = await vcsa.getVMTemplate(_template.id);
const {host} = hosts.find(({ name }) => name === plan.host);
const {folder} = Folders.find(({ type, name }) => type === 'VIRTUAL_MACHINE' && name === plan.folder);
const { datastore } = Datastores.find(({ name }) => name === plan.datastore);
console.error(`VM would be deployed to ${JSON.stringify({host, folder, datastore, template: template.id})}`);
await vcsa.depoyVMTemplate(template.id, {
placement: { host, folder },
name,
powered_on: true,
disk_storage: { datastore },
vm_home_storage: { datastore },
});
}
/* async function main() {
const config = new Config();
await config.load();
const ip = await getIP(config.vc, {
names: process.argv[2],
power: "POWERED_ON"
});
console.log(ip);
}
main();
*/
import { loginVCSA, vCenter } from "ts-vcenter";
import yaml from "yaml";
import fs from "fs";
export interface Plan {
host: string;
folder: string;
datastore: string;
template: string;
}
export class Config {
username: string;
url: string;
password: string;
plans: Plan[];
vc: vCenter;
async load() {
const config = yaml.parse(await fs.promises.readFile("./config.yaml", "utf-8"));
for (let field of ["username", "password", "url", "plans"]) {
this[field] = config[field];
}
const token = await loginVCSA(this);
this.vc = new vCenter({
url: this.url,
token
});
}
}
{
"compilerOptions": {
"outDir": "build",
"module": "commonjs",
"target": "esnext",
"esModuleInterop": true,
"sourceMap": true
},
"compileOnSave": true,
"allowJs": true,
"include": [
"*.ts",
"src/*.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