Skip to content

Commit

Permalink
feat: use latest microfleet, enable health action, pnpm, node 16 (#114)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: uses updated configuration for microfleet, underlaying modules had breaking changes, validation error formats have slightly changed (must instead of should, slashes instead of dots). generally no end changes except non-standard configuration for startup needs to be changed. API remains stable
  • Loading branch information
AVVS authored Mar 29, 2022
1 parent b006dfe commit d779fce
Show file tree
Hide file tree
Showing 45 changed files with 8,341 additions and 9,837 deletions.
11 changes: 0 additions & 11 deletions .babelrc

This file was deleted.

4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"extends": "makeomatic",
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 2022
},
"plugins": [
"json"
]
Expand Down
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

"`$(npm bin)/mdep bin commitlint`" --edit $1
8 changes: 8 additions & 0 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

case "$2,$3" in
merge,)
ex "+%s/Merge branch '\([^']\+\)'/chore(merge): \1/i" -scwq $1 ;;
*) ;;
esac
13 changes: 4 additions & 9 deletions .mdeprc → .mdeprc.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
{
"node": "12.16.1",
module.exports = {
"node": "16",
"auto_compose": true,
"with_local_compose": true,
"nycCoverage": false,
"nycReport": false,
"services": [
"redisCluster",
"rabbitmq",
"postgres"
],
"extras": {
"tester": {
"volumes": [
"${PWD}:/src:cached"
]
}
}
}
6 changes: 6 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"require": ["./test/configs/config.js"],
"bail": true,
"timeout": 75000,
"report": "spec"
}
37 changes: 0 additions & 37 deletions .npmignore

This file was deleted.

17 changes: 17 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"include": [
"src/**/*.js"
],
"exclude": [
"src/**/*.spec.js"
],
"sourceMap": false,
"instrument": false,
"cache": true,
"clean": false,
"reporter": [
"lcov",
"json",
"text-summary"
]
}
6 changes: 3 additions & 3 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"branch": "master",
"branches": ["main"],
"verifyConditions": [
"@semantic-release/changelog",
"@semantic-release/git",
"@semantic-release/github",
"@semantic-release/npm"
],
"prepare": [
{ "path": "@semantic-release/exec", "cmd": "yarn doc" },
{ "path": "@semantic-release/exec", "cmd": "pnpm run doc" },
"@semantic-release/changelog",
"@semantic-release/npm",
{ "path": "@semantic-release/exec", "cmd": "yarn docker-release --tag_latest" },
{ "path": "@semantic-release/exec", "cmd": "pnpm run -- docker-release --tl" },
"@semantic-release/git"
],
"publish": [
Expand Down
54 changes: 54 additions & 0 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
version: v1.0
name: makeomatic/mservice-social
agent:
machine:
type: e1-standard-2
os_image: ubuntu2004

fail_fast:
stop:
when: "branch != 'main'"

auto_cancel:
running:
when: "branch != 'main'"

global_job_config:
prologue:
commands:
- set -e
- sem-version node 16
- curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm@6
- checkout
- cache restore node-$(checksum pnpm-lock.yaml)
- pnpm i --frozen-lockfile --prefer-offline --ignore-scripts
- cache store node-$(checksum pnpm-lock.yaml) ~/.pnpm-store

blocks:
- name: tests
dependencies: []
task:
secrets:
- name: twitter-keys
jobs:
- name: test project
commands:
- cp ~/.env.twitter .env
- pnpm test

- name: release
dependencies: ["tests"]
skip:
when: "branch != 'main'"
task:
secrets:
- name: semantic-release
- name: docker-hub
jobs:
- name: release
commands:
- sudo chmod -R 0777 /etc/docker
- echo '{"experimental":true}' > /etc/docker/daemon.json
- sudo service docker restart
- echo $DOCKER_PASSWORD | docker login --username $DOCKER_USERNAME --password-stdin
- pnpm run semantic-release
25 changes: 12 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,28 @@ ENV NCONF_NAMESPACE=MS_SOCIAL \

WORKDIR /src

COPY package.json yarn.lock ./
# pnpm fetch does require only lockfile
COPY --chown=node:node package.json pnpm-lock.yaml ./
RUN \
apk --update add --virtual .buildDeps \
build-base \
python \
apk --update upgrade \
&& apk add git ca-certificates openssl g++ make python3 linux-headers \
&& chown node:node /src \
&& su -l node -c "cd /src && pnpm install --prod --frozen-lockfile" \
&& apk del \
g++ \
make \
git \
curl \
&& apk add openssl ca-certificates \
&& update-ca-certificates \
&& yarn --production --frozen-lockfile \
&& yarn cache clean \
&& apk del \
.buildDeps \
wget \
python3 \
linux-headers \
&& rm -rf \
/tmp/* \
/root/.node-gyp \
/root/.npm \
/etc/apk/cache/* \
/var/cache/apk/*

COPY . /src
RUN chown -R node /src
COPY --chown=node:node . /src
USER node

EXPOSE 3000
8 changes: 6 additions & 2 deletions bin/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ const name = process.argv[2];

assert(name, 'Migration name must be specified');

return knex.migrate
knex.migrate
.make(name)
.then((info) => {
service.log.info('Create migration:', info);
service.log.info({ info }, 'Create migration');
return process.exit();
})
.catch((err) => {
service.log.info({ err }, 'migration failed');
process.exit(128);
});
21 changes: 12 additions & 9 deletions bin/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// accepts conf through .env file
// suitable for configuring this in the docker env
const conf = require('ms-conf').get('/');
const AMQPTransport = require('@microfleet/transport-amqp');
const { connect } = require('@microfleet/transport-amqp');
const yargs = require('yargs');
const debug = require('debug')('mservice:social:register');

Expand All @@ -16,9 +16,9 @@ const { argv } = yargs
.coerce({
account: JSON.parse,
})
.required('internal', 'supply owner username')
.required('network', 'supply network, <twitter>')
.required('account', 'supply account, stringified JSON');
.demandOption('internal', 'supply owner username')
.demandOption('network', 'supply network, <twitter>')
.demandOption('account', 'supply account, stringified JSON');

if (!argv.account) throw new Error('must supply twitter account');

Expand All @@ -32,8 +32,11 @@ const message = {
debug('sending to %s, message %j', route, message);
debug('amqp configuration: %j', config.amqp.transport);

return AMQPTransport
.connect(Object.assign(config.amqp.transport, { debug: true }))
.then((amqp) => (
amqp.publish(route, message).finally(() => amqp.close())
));
(async () => {
const amqp = await connect(Object.assign(config.amqp.transport, { debug: true }));
try {
await amqp.publish(route, message);
} finally {
await amqp?.close();
}
})();
Loading

0 comments on commit d779fce

Please sign in to comment.