Compare commits

...

12 Commits

Author SHA1 Message Date
Jonatan Nilsson 8f3faed11f package: Release new version
continuous-integration/appveyor/branch AppVeyor build succeeded Details
2022-04-01 10:05:49 +00:00
Jonatan Nilsson 95e94b38cc server: Change log level from debug to info on normal requests
continuous-integration/appveyor/branch AppVeyor build succeeded Details
2022-04-01 10:04:59 +00:00
Jonatan Nilsson 562ade9763 Trigger new version
continuous-integration/appveyor/branch AppVeyor build succeeded Details
2022-03-30 22:05:28 +00:00
Jonatan Nilsson 5b6b1b0a58 appveyor: Add auto deploy to production
continuous-integration/appveyor/branch AppVeyor build succeeded Details
2022-03-30 09:08:03 +00:00
Jonatan Nilsson fa38c2928b server: Fix accidental crashing bug xD
continuous-integration/appveyor/branch AppVeyor build succeeded Details
2022-03-29 10:07:06 +00:00
Jonatan Nilsson 4560d20b04 server: Log incoming requests on finish
continuous-integration/appveyor/branch AppVeyor build succeeded Details
2022-03-29 10:03:35 +00:00
Jonatan Nilsson fbf2f5958c server: Don't overwrite host, use service-core defaults
continuous-integration/appveyor/branch AppVeyor build succeeded Details
package: Increment version
2022-03-12 22:45:05 +00:00
Jonatan Nilsson 1c85867278 package.json: Increment version
continuous-integration/appveyor/branch AppVeyor build succeeded Details
2022-03-12 22:34:34 +00:00
Jonatan Nilsson 4dab6ea05d server: Read local package.json as opposed to the one in the runner folder
continuous-integration/appveyor/branch AppVeyor build succeeded Details
2022-03-12 22:33:28 +00:00
Jonatan Nilsson 2a18df18ba appveyor: Fix path to 7zip
continuous-integration/appveyor/branch AppVeyor build succeeded Details
2022-03-10 15:23:46 +00:00
Jonatan Nilsson d1c2be3d1e appveyor: Fix build process
continuous-integration/appveyor/branch AppVeyor build failed Details
2022-03-10 15:21:56 +00:00
Jonatan Nilsson 9a07149c86 appveyor: Add auto build script support
continuous-integration/appveyor/branch AppVeyor build failed Details
service-core: Update to version 3
2022-03-10 15:19:22 +00:00
9 changed files with 126 additions and 79 deletions

View File

@ -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

Binary file not shown.

View File

@ -1,13 +1,41 @@
import path from 'path'
import { readFileSync } from 'fs'
import { fileURLToPath } from 'url'
import { Util } from 'service-core'
export function run(config, db, log, core, http, orgPort) {
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const staticPackage = path.join(__dirname,'../package.json')
let packageInfo = JSON.parse(readFileSync(staticPackage))
export function run(http, orgPort, ctx) {
let localUtil = new Util(import.meta.url)
let packagePath = localUtil.getPathFromRoot('../package.json')
let packageInfo = JSON.parse(readFileSync(packagePath))
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.write(JSON.stringify(packageInfo, null, ' '))
res.end()
@ -15,13 +43,9 @@ export function run(config, db, log, core, http, orgPort) {
let port = orgPort || 4000
server.listen(port, '0.0.0.0', function(err) {
if (err) {
log.fatal(err)
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}`)
return server.listenAsync(port)
.then(function() {
ctx.log.event.info(`Server is listening on ${port} serving package ${packagePath}`)
ctx.log.info(`Server is listening on ${port} serving package ${packagePath}`)
})
}

70
appveyor.yml Normal file
View 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

View File

@ -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
View 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()
})

View File

@ -1,5 +1,5 @@
export function start(config, db, log, core, http, port) {
return import('./api/server.mjs').then(function(module) {
return module.run(config, db, log, core, http, port)
})
}
import { run } from "./api/server.mjs"
export function start(http, port, ctx) {
return run(http, port, ctx)
}

View File

@ -1,10 +1,10 @@
{
"name": "sc-helloworld",
"version": "1.0.2",
"version": "2.0.6",
"description": "Hello World app for service core",
"main": "index.js",
"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"
},
"repository": {
@ -17,11 +17,7 @@
"url": "https://github.com/TheThing/sc-helloworld/issues"
},
"homepage": "https://github.com/TheThing/sc-helloworld#readme",
"dependencies": {
"node-static": "^0.7.11"
},
"devDependencies": {
"bunyan-lite": "^1.0.1",
"nodemon": "^2.0.4"
"service-core": "^3.0.0-beta.8"
}
}

View File

@ -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')
})