Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hub onboarding image #69

Merged
merged 7 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,29 @@ jobs:
paths:
- ./docker-image.tar

build-onboard-hub-accounts:
executor: default-machine
steps:
- checkout
- run:
name: Build Docker onboard-hub-accounts $CIRCLE_TAG image
command: >
echo "Building Docker image: onboard-hub-accounts $CIRCLE_TAG"

docker build
--build-arg CREATED="$(date -u --iso-8601=seconds)"
--build-arg VERSION="$RELEASE_TAG"
--build-arg SOURCE="$CIRCLE_REPOSITORY_URL"
--build-arg REVISION="$CIRCLE_SHA1"
-t $DOCKER_ORG/onboard-hub-accounts:$CIRCLE_TAG ./init/onboard-hub-accounts/
- run:
name: Save docker image to workspace
command: docker save -o /tmp/docker-onboard-hub-accounts.tar $DOCKER_ORG/onboard-hub-accounts:$CIRCLE_TAG
- persist_to_workspace:
root: /tmp
paths:
- ./docker-onboard-hub-accounts.tar

build-onboard-central-ledger:
executor: default-machine
steps:
Expand Down Expand Up @@ -284,6 +307,29 @@ jobs:
paths:
- ./docker-image.tar

build-local-onboard-hub-accounts:
executor: default-machine
steps:
- checkout
- run:
name: Build Docker onboard-hub-accounts local image for testing
command: >
echo "Building Docker image: onboard-hub-accounts local"

docker build
--build-arg CREATED="$(date -u --iso-8601=seconds)"
--build-arg VERSION="local"
--build-arg SOURCE="$CIRCLE_REPOSITORY_URL"
--build-arg REVISION="$CIRCLE_SHA1"
-t mojaloop/onboard-hub-accounts:local ./init/onboard-hub-accounts/
- run:
name: Save docker image to workspace
command: docker save -o /tmp/docker-onboard-hub-accounts.tar mojaloop/onboard-hub-accounts:local
- persist_to_workspace:
root: /tmp
paths:
- ./docker-onboard-hub-accounts.tar

build-local-onboard-central-ledger:
executor: default-machine
steps:
Expand Down Expand Up @@ -430,6 +476,39 @@ jobs:
-H 'cache-control: no-cache' \
-d "{\"text\": \"*${CIRCLE_PROJECT_REPONAME}* - Release \`${CIRCLE_TAG}\`: https://github.com/mojaloop/${CIRCLE_PROJECT_REPONAME}/releases/tag/${CIRCLE_TAG}\"}"

publish-onboard-hub-accounts:
executor: default-machine
steps:
- checkout
- attach_workspace:
at: /tmp
- run:
name: Load the pre-built docker image for onboard-hub-accounts from workspace
command: docker load -i /tmp/docker-onboard-hub-accounts.tar
- run:
name: Login to Docker Hub
command: docker login -u $DOCKER_USER -p $DOCKER_PASS
- run:
name: Setup environment vars for release/snapshot
command: ./.circleci/_set_up_deploy_envs.sh
- run:
name: Re-tag pre built image
command: |
docker tag $DOCKER_ORG/onboard-hub-accounts:$CIRCLE_TAG $DOCKER_ORG/onboard-hub-accounts:$RELEASE_TAG
- run:
name: Publish Docker image $CIRCLE_TAG & Latest tag to Docker Hub for onboard-hub-accounts
command: |
echo "Publishing $DOCKER_ORG/onboard-hub-accounts:$CIRCLE_TAG"
docker push $DOCKER_ORG/onboard-hub-accounts:$CIRCLE_TAG
- run:
name: Slack announcement for tag releases
command: |
curl -X POST \
$SLACK_WEBHOOK_ANNOUNCEMENT \
-H 'Content-type: application/json' \
-H 'cache-control: no-cache' \
-d "{\"text\": \"*onboard-hub-accounts* - Release \`${CIRCLE_TAG}\`: https://github.com/mojaloop/${CIRCLE_PROJECT_REPONAME}/releases/tag/${CIRCLE_TAG}\"}"

publish-onboard-central-ledger:
executor: default-machine
steps:
Expand Down Expand Up @@ -574,6 +653,16 @@ workflows:
- /feature*/
- /bugfix*/
- /hotfix*/
- build-local-onboard-hub-accounts:
context: org-global
requires:
- setup
filters:
branches:
ignore:
- /feature*/
- /bugfix*/
- /hotfix*/
- build-local-onboard-central-ledger:
context: org-global
requires:
Expand Down Expand Up @@ -624,6 +713,16 @@ workflows:
branches:
ignore:
- /.*/
- build-onboard-hub-accounts:
context: org-global
requires:
- setup
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*(\-snapshot)?(\-hotfix(\.[0-9]+))?/
branches:
ignore:
- /.*/
- build-onboard-central-ledger:
context: org-global
requires:
Expand Down Expand Up @@ -656,12 +755,26 @@ workflows:
branches:
ignore:
- /.*/
- publish-onboard-hub-accounts:
context: org-global
requires:
- build
- build-onboard-central-ledger
- build-onboard-msisdn-oracle
- build-onboard-hub-accounts
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*(\-snapshot)?(\-hotfix(\.[0-9]+))?/
branches:
ignore:
- /.*/
- publish-onboard-central-ledger:
context: org-global
requires:
- build
- build-onboard-central-ledger
- build-onboard-msisdn-oracle
- build-onboard-hub-accounts
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*(\-snapshot)?(\-hotfix(\.[0-9]+))?/
Expand All @@ -674,6 +787,7 @@ workflows:
- build
- build-onboard-central-ledger
- build-onboard-msisdn-oracle
- build-onboard-hub-accounts
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*(\-snapshot)?(\-hotfix(\.[0-9]+))?/
Expand All @@ -686,6 +800,7 @@ workflows:
- publish
- publish-onboard-central-ledger
- publish-onboard-msisdn-oracle
- publish-onboard-hub-accounts
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*(\-snapshot)?/
Expand Down
28 changes: 28 additions & 0 deletions init/onboard-hub-accounts/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM node:12.18.2-alpine as builder

ARG CREATED
ARG SOURCE
ARG REVISION
ARG VERSION

# See https://github.com/opencontainers/image-spec/blob/master/annotations.md#pre-defined-annotation-keys and https://github.com/opencontainers/image-spec/blob/master/spec.md for info
LABEL org.opencontainers.image.created=${CREATED}
LABEL org.opencontainers.image.url="https://mojaloop.io/"
LABEL org.opencontainers.image.source=${SOURCE}
LABEL org.opencontainers.image.version=${VERSION}
LABEL org.opencontainers.image.revision=${REVISION}
LABEL org.opencontainers.image.title="onboard-central-ledger"
LABEL org.opencontainers.image.authors="matt.kingston@modusbox.com"
LABEL org.opencontainers.image.licenses="Apache-2.0"

WORKDIR /opt/onboard-central-ledger
COPY package* *.js /opt/onboard-central-ledger/

RUN ["npm", "ci", "--production"]

FROM node:12.18.2-alpine
WORKDIR /opt/onboard-central-ledger

COPY --from=builder /opt/onboard-central-ledger .

CMD ["node", "onboard-hub.js"]
64 changes: 64 additions & 0 deletions init/onboard-hub-accounts/onboard-hub-accounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const uuid = require('uuid');
const {
onboarding: {
createHubAccount,
sendRequest,
},
} = require('@mojaloop/finance-portal-lib');

function log(message) {
const timestamp = (new Date()).toISOString();
// eslint-disable-next-line no-console
console.log(`[${timestamp}] ${message}`);
}

console.log('ENV:');
console.table({
ACCOUNTS: process.env.ACCOUNTS,
AUTH_BEARER_TOKEN: process.env.AUTH_BEARER_TOKEN,
HOST_CENTRAL_LEDGER: process.env.HOST_CENTRAL_LEDGER,
HUB_OPERATOR_NAME: process.env.HUB_OPERATOR_NAME,
});

const accounts = JSON.parse(process.env.ACCOUNTS);
const authToken = process.env.AUTH_BEARER_TOKEN;
const hostCentralLedger = process.env.HOST_CENTRAL_LEDGER;
const fspiopSource = process.env.HUB_OPERATOR_NAME;

async function onboardHubAccounts() {
try {
log('EXE: INIT: sendRequest->createHubAccounts');
// Deliberately sequential to be more predictable and make debugging a little easier
await accounts.reduce((promise, acc) => promise.then(async () => {
const response = await sendRequest(createHubAccount({
authToken,
fspiopSource,
hostCentralLedger,
...acc
}));
if (response.ok) {
log('EXE: SUCC: sendRequest->createHubAccounts');
} else {
const error = await response.json();
// Allow re-registering of the same hub account
if (
response.status === 400 &&
error.errorInformation.errorCode === '3003' &&
/already/.test(error.errorInformation.errorDescription)
) {
log(`EXE: FAIL: sendRequest->createHubAccounts:\n${JSON.stringify(error)}`);
log('EXE: INFO: Allowed failure. Continuing.');
} else {
throw new Error(`Response not OK/2XX: ${JSON.stringify(error)}`);
}
}
}) , Promise.resolve());

} catch ({ message }) {
log(`EXE: FAIL: sendRequest->createHubAccounts:\t${message}`);
process.exitCode = 1;
return;
}
}

onboardHubAccounts();
Loading