Skip to content

Commit c4fb655

Browse files
authored
Add stage to Signed API (#156)
* Add stage to Signed API * Add version field to signed API * Fix tests
1 parent b1e8d27 commit c4fb655

File tree

10 files changed

+42
-14
lines changed

10 files changed

+42
-14
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@ RUN addgroup -S deployed-api && \
6868
USER deployed-api
6969

7070
COPY --chown=deployed-api:deployed-api --from=deployed-api /app/deployed-api .
71-
ENTRYPOINT ["node", "dist/index.js"]
71+
ENTRYPOINT ["node", "dist/src/index.js"]

packages/airnode-feed/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,7 @@ lowercase alphanumeric characters and hyphens.
347347
## Versioning and release
348348

349349
Airnode feed uses [semantic versioning](https://semver.org/). The version is specified in the `package.json` file. The
350-
package is not published to NPM, but instead dockerized and published to Docker Hub. The image is called
351-
[api3/airnode-feed](https://hub.docker.com/r/api3/airnode-feed).
350+
package is not published to NPM, but instead dockerized and published to Docker Hub.
352351

353352
To release a new version:
354353

packages/airnode-feed/src/validation/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import dotenv from 'dotenv';
88
import { configSchema } from './schema';
99
import { interpolateSecrets, parseSecrets } from './utils';
1010

11-
// When Airnode feed is built the "/dist" file contains "src" folder and "package.json" and the config is expected to be
12-
// located next to the "/dist" folder. When run in development, the config is expected to be located next to the "src"
13-
// folder (one less import level). We resolve the config by CWD as a workaround. Since the Airnode feed is dockerized,
14-
// this is hidden from the user.
11+
// When Airnode feed is built, the "/dist" file contains "src" folder and "package.json" and the config is expected to
12+
// be located next to the "/dist" folder. When run in development, the config is expected to be located next to the
13+
// "src" folder (one less import level). We resolve the config by CWD as a workaround. Since the Airnode feed is
14+
// dockerized, this is hidden from the user.
1515
const getConfigPath = () => join(cwd(), './config');
1616

1717
export const loadRawConfig = () => JSON.parse(fs.readFileSync(join(getConfigPath(), 'airnode-feed.json'), 'utf8'));

packages/api/README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,16 @@ or
207207
"allowedAirnodes": ["0xB47E3D8734780430ee6EfeF3c5407090601Dcd15"]
208208
```
209209

210+
##### `stage`
211+
212+
An identifier of the deployment stage. This is used to distinguish between different deployments of Signed API, for
213+
example `dev`, `staging` or `production`. The stage value can have 256 characters at maximum and can only include
214+
lowercase alphanumeric characters and hyphens.
215+
216+
##### `version`
217+
218+
The version specified in the config must match the version of the Signed API at deployment time.
219+
210220
## API
211221

212222
The API provides the following endpoints:
@@ -224,8 +234,7 @@ The API provides the following endpoints:
224234
## Versioning and release
225235

226236
Signed API uses [semantic versioning](https://semver.org/). The version is specified in the `package.json` file. The
227-
package is not published to NPM, but instead dockerized and published to Docker Hub. The image is called
228-
[api3/signed-api](https://hub.docker.com/r/api3/signed-api).
237+
package is not published to NPM, but instead dockerized and published to Docker Hub.
229238

230239
To release a new version:
231240

packages/api/config/signed-api.example.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
"delaySeconds": 15
1010
}
1111
],
12-
"allowedAirnodes": ["0xbF3137b0a7574563a23a8fC8badC6537F98197CC"]
12+
"allowedAirnodes": ["0xbF3137b0a7574563a23a8fC8badC6537F98197CC"],
13+
"stage": "local",
14+
"version": "0.1.0"
1315
}

packages/api/deployment/cloudformation-template.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"EntryPoint": [
4545
"/bin/sh",
4646
"-c",
47-
"wget -O - <SIGNED_API_CONFIGURATION_URL> >> ./config/signed-api.json && node dist/index.js"
47+
"wget -O - <SIGNED_API_CONFIGURATION_URL> >> ./config/signed-api.json && node dist/src/index.js"
4848
],
4949
"PortMappings": [
5050
{

packages/api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "api",
3-
"version": "1.0.0",
3+
"version": "0.1.0",
44
"engines": {
55
"node": "^18.18.2",
66
"pnpm": "^8.11.0"

packages/api/src/config.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { readFileSync } from 'node:fs';
22
import { join } from 'node:path';
3+
import { cwd } from 'node:process';
34

45
import { go } from '@api3/promise-utils';
56
import { S3 } from '@aws-sdk/client-s3';
@@ -22,12 +23,21 @@ export const fetchAndCacheConfig = async (): Promise<Config> => {
2223
return config;
2324
};
2425

26+
// When Signed API is built, the "/dist" file contains "src" folder and "package.json" and the config is expected to be
27+
// located next to the "/dist" folder. When run in development, the config is expected to be located next to the "src"
28+
// folder (one less import level). We resolve the config by CWD as a workaround. Since the Signed API is dockerized,
29+
// this is hidden from the user.
30+
const getConfigPath = () => join(cwd(), './config');
31+
32+
export const loadConfigFromFilesystem = () =>
33+
JSON.parse(readFileSync(join(getConfigPath(), 'signed-api.json'), 'utf8'));
34+
2535
const fetchConfig = async (): Promise<any> => {
2636
const env = loadEnv();
2737
const source = env.CONFIG_SOURCE;
2838
switch (source) {
2939
case 'local': {
30-
return JSON.parse(readFileSync(join(__dirname, '../config/signed-api.json'), 'utf8'));
40+
return loadConfigFromFilesystem();
3141
}
3242
case 'aws-s3': {
3343
return fetchConfigFromS3();

packages/api/src/schema.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { type LogFormat, logFormatOptions, logLevelOptions, type LogLevel } from
22
import { uniqBy } from 'lodash';
33
import { z } from 'zod';
44

5+
import packageJson from '../package.json';
6+
57
export const evmAddressSchema = z.string().regex(/^0x[\dA-Fa-f]{40}$/, 'Must be a valid EVM address');
68

79
export const evmIdSchema = z.string().regex(/^0x[\dA-Fa-f]{64}$/, 'Must be a valid EVM ID');
@@ -35,6 +37,10 @@ export const configSchema = z.strictObject({
3537
endpoints: endpointsSchema,
3638
cache: cacheSchema.optional(),
3739
allowedAirnodes: allowedAirnodesSchema,
40+
stage: z
41+
.string()
42+
.regex(/^[\da-z-]{1,256}$/, 'Only lowercase letters, numbers and hyphens are allowed (max 256 characters)'),
43+
version: z.string().refine((version) => version === packageJson.version, 'Invalid Signed API version'),
3844
});
3945

4046
export type Config = z.infer<typeof configSchema>;

packages/e2e/src/signed-api/signed-api.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
"delaySeconds": 10
1010
}
1111
],
12-
"allowedAirnodes": ["0xbF3137b0a7574563a23a8fC8badC6537F98197CC"]
12+
"allowedAirnodes": ["0xbF3137b0a7574563a23a8fC8badC6537F98197CC"],
13+
"stage": "e2e-test",
14+
"version": "0.1.0"
1315
}

0 commit comments

Comments
 (0)