这是 nexhome
用于 jenkins(CI/CD)
and gitlab-ci
打包的工具库
yarn add nexhome-web-devops-util -D
# or
npm i nexhome-web-devops-util -D
{
"include": ["./**/*.ts"],
"compilerOptions": {
"resolveJsonModule": true,
"target": "es5",
"module": "commonjs",
"lib": [
"DOM"
],
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true ,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
①. devops-dev.ts
const config = {}
runLocally(config)
②. package.json
{
"scripts":{
"build-for-dev": "yarn && npx ts-node --dir ${scripts-path} devops-dev.ts || exit -1",
}
}
③. set jenkins config
yarn build-for-dev
①. devops-test.ts
import { bootstrap, BuildConfig } from 'nexhome-web-devops-util'
import {
dockerAccountInfo,
qiniuAccountInfo,
dockerHubPrefix
} from './constants'
import pkg from '../package.json'
const run = async () => {
const { name, version } = pkg
const config: BuildConfig = {
env: 'test',
appName: name,
version,
buildCommand: 'yarn build',
dockerfile: 'Dockerfile.test',
dockerAccountInfo,
qiniuAccountInfo,
deployedPort: 8080,
dockerHubPrefix,
cicdType: 'jenkins' // or 'gitlab-ci'
}
bootstrap(config)
}
run()
②. package.json
{
"scripts":{
"build-for-test": "yarn && npx ts-node --dir ${scripts-path} devops-test.ts || exit -1",
}
}
③. set jenkins config
yarn build-for-test
④. server shell script
# 1. login to docker service
docker login -u ${u} -p ${p} registry.cn-shanghai.aliyuncs.com || exit -1
# 2. stop previous service
docker-compose stop
# 3. set some vars to download latest docker-compose.yml
dockerComposeUrl='https://some-where.com/docker-compose.yml'
_hash=`date "+%s"`
curl $dockerComposeUrl?_hash=$_hash -o docker-compose.yml || exit -1
# 4. start service
docker-compose up -d --remove-orphans
# All done :)