Compare commits
12 commits
Author | SHA1 | Date | |
---|---|---|---|
8f3faed11f | |||
95e94b38cc | |||
562ade9763 | |||
5b6b1b0a58 | |||
fa38c2928b | |||
4560d20b04 | |||
fbf2f5958c | |||
1c85867278 | |||
4dab6ea05d | |||
2a18df18ba | |||
d1c2be3d1e | |||
9a07149c86 |
9 changed files with 126 additions and 79 deletions
|
@ -1,34 +0,0 @@
|
||||||
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
Normal file
BIN
7zas
Normal file
Binary file not shown.
|
@ -1,13 +1,41 @@
|
||||||
import path from 'path'
|
|
||||||
import { readFileSync } from 'fs'
|
import { readFileSync } from 'fs'
|
||||||
import { fileURLToPath } from 'url'
|
import { Util } from 'service-core'
|
||||||
|
|
||||||
export function run(config, db, log, core, http, orgPort) {
|
export function run(http, orgPort, ctx) {
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
let localUtil = new Util(import.meta.url)
|
||||||
const staticPackage = path.join(__dirname,'../package.json')
|
let packagePath = localUtil.getPathFromRoot('../package.json')
|
||||||
let packageInfo = JSON.parse(readFileSync(staticPackage))
|
let packageInfo = JSON.parse(readFileSync(packagePath))
|
||||||
|
|
||||||
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()
|
||||||
|
@ -15,13 +43,9 @@ export function run(config, db, log, core, http, orgPort) {
|
||||||
|
|
||||||
let port = orgPort || 4000
|
let port = orgPort || 4000
|
||||||
|
|
||||||
server.listen(port, '0.0.0.0', function(err) {
|
return server.listenAsync(port)
|
||||||
if (err) {
|
.then(function() {
|
||||||
log.fatal(err)
|
ctx.log.event.info(`Server is listening on ${port} serving package ${packagePath}`)
|
||||||
log.event.error('Error starting server: ' + err.message)
|
ctx.log.info(`Server is listening on ${port} serving package ${packagePath}`)
|
||||||
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
Normal file
70
appveyor.yml
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
# 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
|
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"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
Normal file
10
dev.mjs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
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 @@
|
||||||
export function start(config, db, log, core, http, port) {
|
import { run } from "./api/server.mjs"
|
||||||
return import('./api/server.mjs').then(function(module) {
|
|
||||||
return module.run(config, db, log, core, http, port)
|
export function start(http, port, ctx) {
|
||||||
})
|
return run(http, port, ctx)
|
||||||
}
|
}
|
10
package.json
10
package.json
|
@ -1,10 +1,10 @@
|
||||||
{
|
{
|
||||||
"name": "sc-helloworld",
|
"name": "sc-helloworld",
|
||||||
"version": "1.0.2",
|
"version": "2.0.6",
|
||||||
"description": "Hello World app for service core",
|
"description": "Hello World app for service core",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "nodemon --watch api --watch runner.mjs --watch index.mjs runner.mjs | bunyan",
|
"start": "node dev.mjs | bunyan",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -17,11 +17,7 @@
|
||||||
"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": {
|
||||||
"bunyan-lite": "^1.0.1",
|
"service-core": "^3.0.0-beta.8"
|
||||||
"nodemon": "^2.0.4"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
runner.mjs
10
runner.mjs
|
@ -1,10 +0,0 @@
|
||||||
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