diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 83959c3..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -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 diff --git a/7zas b/7zas new file mode 100644 index 0000000..bb1af1d Binary files /dev/null and b/7zas differ diff --git a/api/server.mjs b/api/server.mjs index eb4da68..b3e2123 100644 --- a/api/server.mjs +++ b/api/server.mjs @@ -2,10 +2,9 @@ import path from 'path' import { readFileSync } from 'fs' import { fileURLToPath } from 'url' -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 packagePath = ctx.util.getPathFromRoot('./package.json') + let packageInfo = JSON.parse(readFileSync(packagePath)) const server = http.createServer(function (req, res) { res.writeHead(200); @@ -15,13 +14,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, '0.0.0.0') + .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}`) }) } \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..3b220f4 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,65 @@ +# 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: | + 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 + ./test/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 + fi + +# on build failure +on_failure: + - sh: echo on_failure diff --git a/config.json b/config.json deleted file mode 100644 index 46afd09..0000000 --- a/config.json +++ /dev/null @@ -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 -} diff --git a/dev.mjs b/dev.mjs new file mode 100644 index 0000000..7266b6c --- /dev/null +++ b/dev.mjs @@ -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() +}) \ No newline at end of file diff --git a/index.mjs b/index.mjs index ac92217..c8155c4 100644 --- a/index.mjs +++ b/index.mjs @@ -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) - }) -} \ No newline at end of file +import { run } from "./api/server.mjs" + +export function start(http, port, ctx) { + return run(http, port, ctx) +} diff --git a/package.json b/package.json index 243d8e1..98e1a34 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "sc-helloworld", - "version": "1.0.2", + "version": "2.0.0", "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" } } diff --git a/runner.mjs b/runner.mjs deleted file mode 100644 index 3899831..0000000 --- a/runner.mjs +++ /dev/null @@ -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') - })