Skip to content
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
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ FROM node:14 AS builder

COPY package.json /app/

RUN cd /app && npm install --production
RUN cd /app && npm install

COPY . /app/

RUN cd /app && npm run build

FROM node:14-alpine3.13 AS builder
FROM node:14-alpine3.13

COPY --from=builder /app/dist/ /app/
COPY --from=builder /app/node_modules /app/node_modules
COPY --from=builder /app/package.json /app/

RUN cd /app && npm install --production

CMD node /app/index.js
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: docker-push
docker-push:
bash scripts/build-and-push-docker.sh
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ You need nodejs installed on your enviroment, we are using the latest Active LTS
Example:

```
STAGE=local
NETWORK=testnet
MAX_ADDRESS_GAP=20
SERVICE_NAME=hathor-wallet-service
WALLET_SERVICE_NAME=hathor-wallet-service
WALLET_SERVICE_STAGE=local
DEFAULT_SERVER=http://fullnode_url/v1a/
```

`STAGE` - Wallet-Service's deployment stage, e.g. `local`, `production`, `staging`
`NETWORK` - The current hathor network we want to connect to
`MAX_ADDRESS_GAP` - The full-node configured GAP between addresses
`SERVICE_NAME` - The Wallet-Service's service name as it was registered on AWS
`WALLET_SERVICE_NAME` - The Wallet-Service's service name as it was registered on AWS
`WALLET_SERVICE_STAGE` - Wallet-Service's deployment stage, e.g. `local`, `production`, `staging`
`DEFAULT_SERVER` - The full-node API url

If the wallet-service is not running locally, you also need to specify the AWS-SDK env variables:
Expand Down Expand Up @@ -55,7 +55,7 @@ The recommended way to deploy this service is to use docker.
#### Running:

```
docker run -d -e STAGE="production" \
docker run -d -e WALLET_SERVICE_STAGE="production" \
-e NODE_ENV="production" \
-e AWS_REGION="us-east-1" \
-e AWS_DEFAULT_REGION="us-east-1" \
Expand All @@ -64,7 +64,7 @@ docker run -d -e STAGE="production" \
-e NETWORK="testnet" \
-e MAX_ADDRESS_GAP=20 \
-e NETWORK="testnet" \
-e SERVICE_NAME="hathor-wallet-service" \
-e WALLET_SERVICE_NAME="hathor-wallet-service" \
-e DEFAULT_SERVER="http://fullnode:8082/v1a/" \
-ti localhost/hathor/sync-daemon
```
Expand Down
21 changes: 21 additions & 0 deletions scripts/build-and-push-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
set -e
set -o pipefail

if [ -z "$AWS_ACCOUNT_ID" ]; then
echo "Please export a AWS_ACCOUNT_ID env var before running this";
exit 1;
fi

if [ -z "$DOCKER_IMAGE_TAG" ]; then
commit=`git rev-parse HEAD`;
timestamp=`date +%s`;
export DOCKER_IMAGE_TAG="dev-$commit-$timestamp";
fi;

echo $DOCKER_IMAGE_TAG;

aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.eu-central-1.amazonaws.com;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we exit in case one of these commands fail? We can use something like this:

{ cmd } || { echo "error"; exit -1; }}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

I've added this to the script, to assure that:

set -e
set -o pipefail

Do you think it's enough?


docker build -t $AWS_ACCOUNT_ID.dkr.ecr.eu-central-1.amazonaws.com/hathor-wallet-service-sync-daemon:$DOCKER_IMAGE_TAG .;

docker push $AWS_ACCOUNT_ID.dkr.ecr.eu-central-1.amazonaws.com/hathor-wallet-service-sync-daemon:$DOCKER_IMAGE_TAG;
6 changes: 3 additions & 3 deletions src/api/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '../types';

AWS.config.update({
region: 'us-east-1',
region: process.env.AWS_REGION,
});

/**
Expand All @@ -26,13 +26,13 @@ AWS.config.update({
export const lambdaCall = (fnName: string, payload: any): Promise<any> => new Promise((resolve, reject) => {
const lambda = new AWS.Lambda({
apiVersion: '2015-03-31',
endpoint: process.env.STAGE === 'local'
endpoint: process.env.WALLET_SERVICE_STAGE === 'local'
? process.env.WALLET_SERVICE_LOCAL_URL || 'http://localhost:3002'
: `https://lambda.${process.env.AWS_REGION}.amazonaws.com`,
});

const params = {
FunctionName: `${process.env.SERVICE_NAME}-${process.env.STAGE}-${fnName}`,
FunctionName: `${process.env.WALLET_SERVICE_NAME}-${process.env.WALLET_SERVICE_STAGE}-${fnName}`,
Payload: JSON.stringify({
body: payload,
}),
Expand Down