Compare commits
No commits in common. "master" and "v1.0.2.8" have entirely different histories.
9 changed files with 79 additions and 126 deletions
34
.circleci/config.yml
Normal file
34
.circleci/config.yml
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
version: 2
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
docker:
|
||||||
|
- image: circleci/node:latest
|
||||||
|
working_directory: ~/app
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run:
|
||||||
|
name: Install npm deployment app
|
||||||
|
command: sudo npm install -g github-release-cli
|
||||||
|
- deploy:
|
||||||
|
name: Create a release
|
||||||
|
command: |
|
||||||
|
PACKAGE_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[", ]//g')
|
||||||
|
echo "Packaging to ${CIRCLE_PROJECT_REPONAME}_build-sc.zip"
|
||||||
|
zip "${CIRCLE_PROJECT_REPONAME}_build-sc.zip" index.mjs package.json api/**
|
||||||
|
echo "Creating release '${PACKAGE_VERSION}.${CIRCLE_BUILD_NUM}'"
|
||||||
|
github-release upload \
|
||||||
|
--commitish $CIRCLE_SHA1 \
|
||||||
|
--token $GITHUB_TOKEN \
|
||||||
|
--owner $CIRCLE_PROJECT_USERNAME \
|
||||||
|
--repo $CIRCLE_PROJECT_REPONAME \
|
||||||
|
--tag "v${PACKAGE_VERSION}.${CIRCLE_BUILD_NUM}" \
|
||||||
|
--name "v${PACKAGE_VERSION}.${CIRCLE_BUILD_NUM}" \
|
||||||
|
--body "Automatic CircleCI Build of v${PACKAGE_VERSION}.${CIRCLE_BUILD_NUM} from ${CIRCLE_SHA1}" \
|
||||||
|
sc-helloworld_build-sc.zip
|
||||||
|
|
||||||
|
workflows:
|
||||||
|
version: 2
|
||||||
|
build_deploy:
|
||||||
|
jobs:
|
||||||
|
- build:
|
||||||
|
context: github-thething
|
BIN
7zas
BIN
7zas
Binary file not shown.
|
@ -1,41 +1,13 @@
|
||||||
|
import path from 'path'
|
||||||
import { readFileSync } from 'fs'
|
import { readFileSync } from 'fs'
|
||||||
import { Util } from 'service-core'
|
import { fileURLToPath } from 'url'
|
||||||
|
|
||||||
export function run(http, orgPort, ctx) {
|
export function run(config, db, log, core, http, orgPort) {
|
||||||
let localUtil = new Util(import.meta.url)
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||||
let packagePath = localUtil.getPathFromRoot('../package.json')
|
const staticPackage = path.join(__dirname,'../package.json')
|
||||||
let packageInfo = JSON.parse(readFileSync(packagePath))
|
let packageInfo = JSON.parse(readFileSync(staticPackage))
|
||||||
|
|
||||||
const server = http.createServer(function (req, res) {
|
const server = http.createServer(function (req, res) {
|
||||||
const d1 = new Date().getTime()
|
|
||||||
let finishedRequest = false
|
|
||||||
var done = function () {
|
|
||||||
if (finishedRequest) return
|
|
||||||
finishedRequest = true
|
|
||||||
var requestTime = new Date().getTime() - d1
|
|
||||||
|
|
||||||
let level = 'info'
|
|
||||||
if (res.statusCode >= 400) {
|
|
||||||
level = 'warn'
|
|
||||||
}
|
|
||||||
if (res.statusCode >= 500) {
|
|
||||||
level = 'error'
|
|
||||||
}
|
|
||||||
|
|
||||||
let status = ''
|
|
||||||
if (res.statusCode >= 400) {
|
|
||||||
status = res.statusCode + ' '
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.log[level]({
|
|
||||||
duration: requestTime,
|
|
||||||
status: res.statusCode,
|
|
||||||
}, `<-- ${status}${req.method} ${req.url}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
res.addListener('finish', done);
|
|
||||||
res.addListener('close', done);
|
|
||||||
|
|
||||||
res.writeHead(200);
|
res.writeHead(200);
|
||||||
res.write(JSON.stringify(packageInfo, null, ' '))
|
res.write(JSON.stringify(packageInfo, null, ' '))
|
||||||
res.end()
|
res.end()
|
||||||
|
@ -43,9 +15,13 @@ export function run(http, orgPort, ctx) {
|
||||||
|
|
||||||
let port = orgPort || 4000
|
let port = orgPort || 4000
|
||||||
|
|
||||||
return server.listenAsync(port)
|
server.listen(port, '0.0.0.0', function(err) {
|
||||||
.then(function() {
|
if (err) {
|
||||||
ctx.log.event.info(`Server is listening on ${port} serving package ${packagePath}`)
|
log.fatal(err)
|
||||||
ctx.log.info(`Server is listening on ${port} serving package ${packagePath}`)
|
log.event.error('Error starting server: ' + err.message)
|
||||||
|
return process.exit(2)
|
||||||
|
}
|
||||||
|
log.event.info(`Server is listening on ${port} serving package ${staticPackage}`)
|
||||||
|
log.info(`Server is listening on ${port} serving package ${staticPackage}`)
|
||||||
})
|
})
|
||||||
}
|
}
|
70
appveyor.yml
70
appveyor.yml
|
@ -1,70 +0,0 @@
|
||||||
# version format
|
|
||||||
version: '{build}'
|
|
||||||
deploy: on
|
|
||||||
|
|
||||||
# branches to build
|
|
||||||
branches:
|
|
||||||
# whitelist
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
|
|
||||||
# Do not build on tags (GitHub, Bitbucket, GitLab, Gitea)
|
|
||||||
skip_tags: true
|
|
||||||
|
|
||||||
# Maximum number of concurrent jobs for the project
|
|
||||||
max_jobs: 1
|
|
||||||
clone_depth: 1
|
|
||||||
|
|
||||||
# Build worker image (VM template)
|
|
||||||
build_cloud: Docker
|
|
||||||
|
|
||||||
environment:
|
|
||||||
APPVEYOR_SSH_KEY: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBRMxhawMlUlQ8l4pOaeHsZl8XDO54WQngkYM1U/XB4m samsyn\jonatan@JonatanAMD
|
|
||||||
docker_image: node:16-alpine
|
|
||||||
npm_config_cache: /appveyor/projects/cache
|
|
||||||
|
|
||||||
test_script:
|
|
||||||
- sh: |
|
|
||||||
ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
|
|
||||||
chmod -R 777 /appveyor/projects
|
|
||||||
echo "no tests"
|
|
||||||
|
|
||||||
# on successful build
|
|
||||||
on_success:
|
|
||||||
- sh: |
|
|
||||||
apk add curl jq
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
echo "Finished installling curl and jq"
|
|
||||||
else
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
CURR_VER=$(cat package.json | jq -r .version)
|
|
||||||
echo "Checking https://git.nfp.is/api/v1/repos/$APPVEYOR_REPO_NAME/releases for version v${CURR_VER}"
|
|
||||||
curl -s -X GET -H "Authorization: token $deploytoken" https://git.nfp.is/api/v1/repos/$APPVEYOR_REPO_NAME/releases | grep -o "\"name\"\:\"v${CURR_VER}\"" > /dev/null
|
|
||||||
|
|
||||||
if [ $? -eq 0 ] ; then
|
|
||||||
echo "Release already exists, nothing to do.";
|
|
||||||
else
|
|
||||||
./7zas a -mx9 "${CURR_VER}_build-sc.7z" package.json index.mjs api
|
|
||||||
echo "Creating release on gitea"
|
|
||||||
RELEASE_RESULT=$(curl \
|
|
||||||
-X POST \
|
|
||||||
-H "Authorization: token $deploytoken" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
https://git.nfp.is/api/v1/repos/$APPVEYOR_REPO_NAME/releases \
|
|
||||||
-d "{\"tag_name\":\"v${CURR_VER}\",\"name\":\"v${CURR_VER}\",\"body\":\"Automatic release from Appveyor from ${APPVEYOR_REPO_COMMIT} :\n\n${APPVEYOR_REPO_COMMIT_MESSAGE}\"}")
|
|
||||||
RELEASE_ID=$(echo $RELEASE_RESULT | jq -r .id)
|
|
||||||
echo "Adding ${CURR_VER}_build-sc.7z to release ${RELEASE_ID}"
|
|
||||||
curl \
|
|
||||||
-X POST \
|
|
||||||
-H "Authorization: token $deploytoken" \
|
|
||||||
-F "attachment=@${CURR_VER}_build-sc.7z" \
|
|
||||||
https://git.nfp.is/api/v1/repos/$APPVEYOR_REPO_NAME/releases/$RELEASE_ID/assets
|
|
||||||
|
|
||||||
echo "Deplying to production"
|
|
||||||
curl -X POST http://192.168.93.51:8881/update/helloworld
|
|
||||||
fi
|
|
||||||
|
|
||||||
# on build failure
|
|
||||||
on_failure:
|
|
||||||
- sh: echo on_failure
|
|
9
config.json
Normal file
9
config.json
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "service-core-helloworld",
|
||||||
|
"serviceName": "Service-Core HelloWorld App",
|
||||||
|
"description": "Simple Hello world app for service core",
|
||||||
|
"port": 4270,
|
||||||
|
"managePort": 4269,
|
||||||
|
"appRepository": null,
|
||||||
|
"manageRepository": null
|
||||||
|
}
|
10
dev.mjs
10
dev.mjs
|
@ -1,10 +0,0 @@
|
||||||
import { ServiceCore } from 'service-core'
|
|
||||||
import * as index from './index.mjs'
|
|
||||||
|
|
||||||
var core = new ServiceCore('sc-helloworld', import.meta.url)
|
|
||||||
core.setConfig({
|
|
||||||
port: 4270,
|
|
||||||
})
|
|
||||||
core.init(index).then(function() {
|
|
||||||
return core.run()
|
|
||||||
})
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { run } from "./api/server.mjs"
|
export function start(config, db, log, core, http, port) {
|
||||||
|
return import('./api/server.mjs').then(function(module) {
|
||||||
export function start(http, port, ctx) {
|
return module.run(config, db, log, core, http, port)
|
||||||
return run(http, port, ctx)
|
})
|
||||||
}
|
}
|
10
package.json
10
package.json
|
@ -1,10 +1,10 @@
|
||||||
{
|
{
|
||||||
"name": "sc-helloworld",
|
"name": "sc-helloworld",
|
||||||
"version": "2.0.6",
|
"version": "1.0.2",
|
||||||
"description": "Hello World app for service core",
|
"description": "Hello World app for service core",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node dev.mjs | bunyan",
|
"dev": "nodemon --watch api --watch runner.mjs --watch index.mjs runner.mjs | bunyan",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -17,7 +17,11 @@
|
||||||
"url": "https://github.com/TheThing/sc-helloworld/issues"
|
"url": "https://github.com/TheThing/sc-helloworld/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/TheThing/sc-helloworld#readme",
|
"homepage": "https://github.com/TheThing/sc-helloworld#readme",
|
||||||
|
"dependencies": {
|
||||||
|
"node-static": "^0.7.11"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"service-core": "^3.0.0-beta.8"
|
"bunyan-lite": "^1.0.1",
|
||||||
|
"nodemon": "^2.0.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
runner.mjs
Normal file
10
runner.mjs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import ServiceCore from 'service-core'
|
||||||
|
import * as server from './index.mjs'
|
||||||
|
|
||||||
|
const serviceCore = new ServiceCore('sc-manager', import.meta.url)
|
||||||
|
|
||||||
|
serviceCore.init(server)
|
||||||
|
.then(function() {})
|
||||||
|
.catch(function(err) {
|
||||||
|
serviceCore.log.error(err, 'Unknown error starting server')
|
||||||
|
})
|
Loading…
Reference in a new issue