Skip to content

Commit

Permalink
Add config validation for local Airnode invocation including airnode-…
Browse files Browse the repository at this point in the history
…client container
  • Loading branch information
amarthadan committed May 19, 2022
1 parent dd140e3 commit 49d7bc5
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/warm-knives-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@api3/airnode-examples': minor
'@api3/airnode-node': minor
---

Add config validation for local Airnode invocation including airnode-client container
10 changes: 9 additions & 1 deletion packages/airnode-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ yarn run-airnode-locally api3/airnode-client-dev:bb9b8118940ec852c4223b13eba5a6e

### 11. Deploy a requester

At this point, you have an RRP contract deployed. You will also either have Airnode running as a Docker container
At this point, you have an RRP contract deployed. You will also either have Airnode running as a Docker container
locally or deployed to a cloud provider. Airnode is now listening for events (requests to be made) from the RRP
contract. Requests via the RRP contract originate from requester contracts and therefore a requester contract will need
to be deployed in order to make an on-chain request to your Airnode instance.
Expand Down Expand Up @@ -283,6 +283,14 @@ yarn remove-airnode

This will use the deployer to remove the Airnode functions from the cloud provider.

### 17. (Only if running Airnode locally) Stop the Airnode container

If you wish to stop the Airnode container running locally run:

```sh
yarn stop-local-airnode
```

## For developers

When pulling or creating a new integration you need to run `yarn build` to create the necessary contract artifacts.
Expand Down
1 change: 1 addition & 0 deletions packages/airnode-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"remove-airnode": "ts-node scripts/remove-airnode.ts",
"run-airnode-locally": "ts-node scripts/run-airnode-locally.ts",
"sponsor-requester": "ts-node scripts/sponsor-requester.ts",
"stop-local-airnode": "ts-node scripts/stop-local-airnode.ts",
"test:coingecko-aws": "ts-node scripts/aws-test/coingecko-aws-test.ts",
"test": "jest --selectProjects unit",
"test:e2e": "jest --selectProjects e2e"
Expand Down
13 changes: 13 additions & 0 deletions packages/airnode-examples/scripts/stop-local-airnode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { cliPrint, readIntegrationInfo, runAndHandleErrors, runShellCommand } from '../src';

const main = async () => {
const integrationInfo = readIntegrationInfo();
if (integrationInfo.airnodeType !== 'local') {
cliPrint.error('You only need to run this script if you want to stop Airnode running locally!');
return;
}

runShellCommand(`docker stop airnode`);
};

runAndHandleErrors(main);
9 changes: 6 additions & 3 deletions packages/airnode-node/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ COPY --from=api3/airnode-artifacts /dependencies/airnode-node ${appDir}/node_mod
COPY --from=api3/airnode-artifacts /packages ${appDir}/node_modules/@api3/
COPY --from=api3/airnode-artifacts /build/packages/airnode-node/dist ${appDir}/
COPY packages/airnode-node/docker/airnode-crontab ${cronjob}
COPY packages/airnode-node/docker/entrypoint.sh /entrypoint.sh

# Install Tini to pass signals correctly
RUN apk add --update --no-cache tini && \
RUN apk add --update --no-cache tini dos2unix && \
# Create Airnode user
adduser -h ${appDir} -s /bin/false -S -D -H ${name} && \
# Enable Airnode cronjob
chmod +x ${cronjob} && \
crontab -u ${name} ${cronjob}
crontab -u ${name} ${cronjob} && \
# Git swaps out LF with CRLF on Windows but only in the working directory
dos2unix /entrypoint.sh

# We need to run the cron daemon as root but the Airnode itself is run under the airnode user
ENTRYPOINT ["tini", "--", "crond", "-f"]
ENTRYPOINT ["tini", "--", "/entrypoint.sh"]
3 changes: 3 additions & 0 deletions packages/airnode-node/docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

node /app/src/cli/validate-config.js && crond -f
3 changes: 2 additions & 1 deletion packages/airnode-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"build": "yarn run clean && yarn run compile",
"clean": "rimraf -rf *.tsbuildinfo ./dist *.tgz",
"compile": "tsc --build tsconfig.build.json",
"dev:invoke": "ts-node src/cli/invoke.ts",
"dev:invoke": "ts-node src/cli/validate-config.ts && ts-node src/cli/invoke.ts",
"dev:testApi": "ts-node src/cli/test-api.ts",
"pack": "yarn pack",
"test:e2e": "SILENCE_LOGGER=true jest --selectProjects e2e",
Expand All @@ -28,6 +28,7 @@
"@api3/airnode-protocol": "^0.6.0",
"@api3/airnode-utilities": "^0.6.0",
"@api3/airnode-validator": "^0.6.0",
"@api3/promise-utils": "^0.3.0",
"aws-sdk": "^2.992.0",
"dotenv": "^16.0.0",
"ethers": "^5.4.5",
Expand Down
7 changes: 7 additions & 0 deletions packages/airnode-node/src/cli/validate-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as path from 'path';
import dotenv from 'dotenv';
import { loadConfig } from '../config';

dotenv.config({ path: path.resolve(`${__dirname}/../../config/secrets.env`) });
// We don't care about the config itself, we just need it to be validated during the loading
loadConfig(path.resolve(`${__dirname}/../../config/config.json`), process.env);

0 comments on commit 49d7bc5

Please sign in to comment.