Skip to content

Commit e7804fa

Browse files
ci: update deployment scripts to use simplified environment variables
1 parent 3fed424 commit e7804fa

File tree

5 files changed

+45
-285
lines changed

5 files changed

+45
-285
lines changed

deployment-dapp/src/configureEnsNameScript.ts

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,19 @@
1-
import {
2-
DEPLOY_TARGET_CONFIGURE_ENS_DEV,
3-
DEPLOY_TARGET_CONFIGURE_ENS_PROD,
4-
DEPLOY_TARGET_DEV,
5-
DEPLOY_TARGET_PROD,
6-
WEB3_TELEGRAM_ENS_NAME_DEV,
7-
WEB3_TELEGRAM_ENS_NAME_PROD,
8-
} from './config/config.js';
9-
import { getIExec, loadAppAddress } from './utils/utils.js';
101
import { configureEnsName } from './singleFunction/configureEnsName.js';
2+
import { getIExec, loadAppAddress } from './utils/utils.js';
113

124
const main = async () => {
13-
// get env variables from GitHub Actions
14-
const {
15-
DEPLOY_ENVIRONMENT,
16-
WALLET_PRIVATE_KEY_DEV,
17-
WALLET_PRIVATE_KEY_PROD,
18-
DEPLOYED_APP_ADDRESS, // if already deployed in a previous step and want to configure ENS promoting configure-ens pipeline
19-
ENS_NAME,
20-
} = process.env;
21-
22-
const deployTarget = DEPLOY_ENVIRONMENT;
23-
24-
if (
25-
!deployTarget ||
26-
(deployTarget !== DEPLOY_TARGET_DEV &&
27-
deployTarget !== DEPLOY_TARGET_PROD &&
28-
deployTarget !== DEPLOY_TARGET_CONFIGURE_ENS_DEV &&
29-
deployTarget !== DEPLOY_TARGET_CONFIGURE_ENS_PROD)
30-
)
31-
throw Error(`Invalid promote target ${deployTarget}`);
32-
33-
const appAddress = DEPLOYED_APP_ADDRESS ?? (await loadAppAddress()); // use ALREADY_DEPLOYED_APP_ADDRESS when promoting configure-ens pipeline
34-
let privateKey;
35-
let ensName;
36-
if (
37-
deployTarget === DEPLOY_TARGET_DEV ||
38-
deployTarget === DEPLOY_TARGET_CONFIGURE_ENS_DEV
39-
) {
40-
privateKey = WALLET_PRIVATE_KEY_DEV;
41-
ensName = ENS_NAME ?? WEB3_TELEGRAM_ENS_NAME_DEV;
42-
} else if (
43-
deployTarget === DEPLOY_TARGET_PROD ||
44-
deployTarget === DEPLOY_TARGET_CONFIGURE_ENS_PROD
45-
) {
46-
privateKey = WALLET_PRIVATE_KEY_PROD;
47-
ensName = ENS_NAME ?? WEB3_TELEGRAM_ENS_NAME_PROD;
48-
}
5+
const { RPC_URL, WALLET_PRIVATE_KEY, DAPP_ENS_NAME } = process.env;
496

50-
if (!privateKey)
51-
throw Error(`Failed to get privateKey for target ${deployTarget}`);
7+
const appAddress = await loadAppAddress();
528

53-
if (!ensName)
54-
throw Error(`Failed to get ens name for target ${deployTarget}`);
9+
if (!WALLET_PRIVATE_KEY)
10+
throw Error(`Failed to get privateKey from environment variables`);
5511

56-
const iexec = getIExec(privateKey);
12+
if (!DAPP_ENS_NAME)
13+
throw Error(`Failed to get DAPP_ENS_NAME from environment variables`);
5714

58-
await configureEnsName(iexec, appAddress, ensName);
15+
const iexec = getIExec(WALLET_PRIVATE_KEY, RPC_URL);
16+
await configureEnsName(iexec, appAddress, DAPP_ENS_NAME);
5917
};
6018

6119
main().catch((e) => {

deployment-dapp/src/deployScript.ts

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,30 @@
11
import { deployApp } from './singleFunction/deployApp.js';
2-
import {
3-
DOCKER_IMAGE_DEV_TAG,
4-
DOCKER_IMAGE_PROD_TAG,
5-
DEPLOY_TARGET_DEV,
6-
DEPLOY_TARGET_PROD,
7-
} from './config/config.js';
82
import { getIExec, saveAppAddress } from './utils/utils.js';
93

104
const main = async () => {
115
// get env variables from GitHub Actions
126
const {
13-
DEPLOY_ENVIRONMENT,
14-
WALLET_PRIVATE_KEY_DEV,
15-
WALLET_PRIVATE_KEY_PROD,
16-
DOCKER_IMAGE_CHECKSUM_DEV,
17-
DOCKER_IMAGE_CHECKSUM_PROD,
7+
RPC_URL,
8+
WALLET_PRIVATE_KEY,
9+
DOCKER_IMAGE_TAG,
10+
CHECKSUM,
11+
FINGERPRINT,
1812
} = process.env;
1913

20-
const deployTarget = DEPLOY_ENVIRONMENT;
14+
if (!WALLET_PRIVATE_KEY)
15+
throw Error(`Missing WALLET_PRIVATE_KEY environment variable`);
2116

22-
if (
23-
!deployTarget ||
24-
(deployTarget !== DEPLOY_TARGET_DEV && deployTarget !== DEPLOY_TARGET_PROD)
25-
)
26-
throw Error(`Invalid promote target ${deployTarget}`);
17+
const iexec = getIExec(WALLET_PRIVATE_KEY, RPC_URL);
2718

28-
let privateKey;
29-
let checksum;
30-
if (deployTarget === DEPLOY_TARGET_DEV) {
31-
privateKey = WALLET_PRIVATE_KEY_DEV;
32-
checksum = DOCKER_IMAGE_CHECKSUM_DEV;
33-
} else if (deployTarget === DEPLOY_TARGET_PROD) {
34-
privateKey = WALLET_PRIVATE_KEY_PROD;
35-
checksum = DOCKER_IMAGE_CHECKSUM_PROD;
19+
if (!DOCKER_IMAGE_TAG) {
20+
throw Error(`Missing DOCKER_IMAGE_TAG environment variable.`);
3621
}
3722

38-
if (!privateKey)
39-
throw Error(`Failed to get privateKey for target ${deployTarget}`);
40-
41-
const iexec = getIExec(privateKey);
42-
43-
let dockerImageTag;
44-
if (deployTarget === DEPLOY_TARGET_DEV) {
45-
dockerImageTag = DOCKER_IMAGE_DEV_TAG;
46-
} else if (deployTarget === DEPLOY_TARGET_PROD) {
47-
dockerImageTag = DOCKER_IMAGE_PROD_TAG;
48-
}
49-
50-
console.log(`Deploying with environment: ${deployTarget}`);
51-
console.log(`Using image tag: ${dockerImageTag}`);
52-
if (checksum) {
53-
console.log(`Using pre-computed checksum: ${checksum}`);
54-
} else {
55-
console.log('Fetching checksum from Docker Hub...');
56-
}
57-
58-
//deploy app
5923
const address = await deployApp({
6024
iexec,
61-
dockerTag: dockerImageTag,
62-
checksum,
25+
dockerTag: DOCKER_IMAGE_TAG,
26+
checksum: CHECKSUM,
27+
fingerprint: FINGERPRINT,
6328
});
6429
await saveAppAddress(address);
6530
};

deployment-dapp/src/publishSellOrderScript.ts

Lines changed: 7 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,26 @@
1-
import { getIExec, loadAppAddress } from './utils/utils.js';
21
import { publishSellOrder } from './singleFunction/publishSellOrder.js';
3-
import { resolveName } from './singleFunction/resolveName.js';
4-
import {
5-
DEPLOY_TARGET_SELL_ORDER_DEV,
6-
DEPLOY_TARGET_SELL_ORDER_PROD,
7-
DEPLOY_TARGET_DEV,
8-
DEPLOY_TARGET_PROD,
9-
DEFAULT_APP_PRICE,
10-
DEFAULT_APP_VOLUME,
11-
WEB3_TELEGRAM_ENS_NAME_DEV,
12-
WEB3_TELEGRAM_ENS_NAME_PROD,
13-
} from './config/config.js';
2+
import { getIExec, loadAppAddress } from './utils/utils.js';
143
import {
15-
positiveStrictIntegerSchema,
164
positiveNumberSchema,
5+
positiveStrictIntegerSchema,
176
} from './utils/validator.js';
187

198
const main = async () => {
20-
// get env variables from GitHub Actions
21-
const {
22-
DEPLOY_ENVIRONMENT,
23-
WALLET_PRIVATE_KEY_DEV,
24-
WALLET_PRIVATE_KEY_PROD,
25-
PRICE,
26-
VOLUME,
27-
} = process.env;
28-
29-
const deployTarget = DEPLOY_ENVIRONMENT;
30-
31-
if (
32-
!deployTarget ||
33-
![
34-
DEPLOY_TARGET_DEV,
35-
DEPLOY_TARGET_SELL_ORDER_DEV,
36-
DEPLOY_TARGET_PROD,
37-
DEPLOY_TARGET_SELL_ORDER_PROD,
38-
].includes(deployTarget)
39-
)
40-
throw Error(`Invalid promote target ${deployTarget}`);
41-
42-
let privateKey;
43-
if (
44-
[DEPLOY_TARGET_DEV, DEPLOY_TARGET_SELL_ORDER_DEV].includes(deployTarget)
45-
) {
46-
privateKey = WALLET_PRIVATE_KEY_DEV;
47-
} else if (
48-
[DEPLOY_TARGET_PROD, DEPLOY_TARGET_SELL_ORDER_PROD].includes(deployTarget)
49-
) {
50-
privateKey = WALLET_PRIVATE_KEY_PROD;
51-
}
52-
53-
if (!privateKey) {
54-
throw Error(`Failed to get privateKey for target ${deployTarget}`);
55-
}
9+
const { RPC_URL, WALLET_PRIVATE_KEY, PRICE, VOLUME } = process.env;
5610

57-
const iexec = getIExec(privateKey);
11+
const iexec = getIExec(WALLET_PRIVATE_KEY, RPC_URL);
5812

59-
const appAddress = await loadAppAddress().catch(() => {
60-
console.log('No app address found falling back to ENS');
61-
let ensName;
62-
if (deployTarget === DEPLOY_TARGET_SELL_ORDER_DEV) {
63-
ensName = WEB3_TELEGRAM_ENS_NAME_DEV;
64-
} else if (deployTarget === DEPLOY_TARGET_SELL_ORDER_PROD) {
65-
ensName = WEB3_TELEGRAM_ENS_NAME_PROD;
66-
}
67-
if (!ensName)
68-
throw Error(`Failed to get ens name for target ${deployTarget}`);
69-
return resolveName(iexec, ensName);
70-
});
13+
const appAddress = await loadAppAddress();
7114

7215
if (!appAddress) throw Error('Failed to get app address'); // If the app was not deployed, do not continue
7316

7417
// validate params
7518
const price = await positiveNumberSchema()
76-
.default(DEFAULT_APP_PRICE)
19+
.required()
7720
.label('PRICE')
7821
.validate(PRICE);
7922
const volume = await positiveStrictIntegerSchema()
80-
.default(DEFAULT_APP_VOLUME)
23+
.required()
8124
.label('VOLUME')
8225
.validate(VOLUME);
8326

deployment-dapp/src/pushSecretScript.ts

Lines changed: 10 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,26 @@
1-
import {
2-
DEPLOY_TARGET_DEV,
3-
DEPLOY_TARGET_PROD,
4-
DEPLOY_TARGET_PUSH_SECRET_DEV,
5-
DEPLOY_TARGET_PUSH_SECRET_PROD,
6-
WEB3_TELEGRAM_ENS_NAME_DEV,
7-
WEB3_TELEGRAM_ENS_NAME_PROD,
8-
} from './config/config.js';
91
import { pushSecret } from './singleFunction/pushSecret.js';
10-
import { resolveName } from './singleFunction/resolveName.js';
112
import { getIExec, loadAppAddress } from './utils/utils.js';
123

134
const main = async () => {
14-
// get env variables from GitHub Actions
15-
const {
16-
DEPLOY_ENVIRONMENT,
17-
WALLET_PRIVATE_KEY_DEV,
18-
WALLET_PRIVATE_KEY_PROD,
19-
TELEGRAM_BOT_TOKEN_DEV,
20-
TELEGRAM_BOT_TOKEN_PROD,
21-
} = process.env;
5+
const { RPC_URL, WALLET_PRIVATE_KEY, TELEGRAM_BOT_TOKEN } = process.env;
226

23-
const deployTarget = DEPLOY_ENVIRONMENT;
7+
if (!WALLET_PRIVATE_KEY)
8+
throw Error(`Missing WALLET_PRIVATE_KEY environment variable`);
9+
if (!TELEGRAM_BOT_TOKEN) throw Error('Missing env TELEGRAM_BOT_TOKEN');
2410

25-
if (
26-
!deployTarget ||
27-
![
28-
DEPLOY_TARGET_DEV,
29-
DEPLOY_TARGET_PROD,
30-
DEPLOY_TARGET_PUSH_SECRET_DEV,
31-
DEPLOY_TARGET_PUSH_SECRET_PROD,
32-
].includes(deployTarget)
33-
)
34-
throw Error(`Invalid promote target ${deployTarget}`);
11+
if (!WALLET_PRIVATE_KEY)
12+
throw Error(`Missing WALLET_PRIVATE_KEY environment variable`);
3513

36-
let telegramBotToken;
37-
let privateKey;
38-
if (
39-
deployTarget === DEPLOY_TARGET_DEV ||
40-
deployTarget === DEPLOY_TARGET_PUSH_SECRET_DEV
41-
) {
42-
telegramBotToken = TELEGRAM_BOT_TOKEN_DEV;
43-
privateKey = WALLET_PRIVATE_KEY_DEV;
44-
} else if (
45-
deployTarget === DEPLOY_TARGET_PROD ||
46-
deployTarget === DEPLOY_TARGET_PUSH_SECRET_PROD
47-
) {
48-
telegramBotToken = TELEGRAM_BOT_TOKEN_PROD;
49-
privateKey = WALLET_PRIVATE_KEY_PROD;
50-
}
51-
if (!telegramBotToken) throw Error('Missing env TELEGRAM_BOT_TOKEN');
52-
if (!privateKey)
53-
throw Error(`Failed to get privateKey for target ${deployTarget}`);
14+
const iexec = getIExec(WALLET_PRIVATE_KEY, RPC_URL);
5415

55-
const iexec = getIExec(privateKey);
56-
57-
const appAddress = await loadAppAddress().catch(() => {
58-
console.log('No app address found falling back to ENS');
59-
let ensName;
60-
if (deployTarget === DEPLOY_TARGET_PUSH_SECRET_DEV) {
61-
ensName = WEB3_TELEGRAM_ENS_NAME_DEV;
62-
} else if (deployTarget === DEPLOY_TARGET_PUSH_SECRET_PROD) {
63-
ensName = WEB3_TELEGRAM_ENS_NAME_PROD;
64-
}
65-
if (!ensName)
66-
throw Error(`Failed to get ens name for target ${deployTarget}`);
67-
return resolveName(iexec, ensName);
68-
});
16+
const appAddress = await loadAppAddress();
6917

7018
if (!appAddress) throw Error('Failed to get app address'); // If the app was not deployed, do not continue
7119

72-
//push app secret to the secret management
7320
const jsonSecret = JSON.stringify({
74-
TELEGRAM_BOT_TOKEN: telegramBotToken,
21+
TELEGRAM_BOT_TOKEN,
7522
});
23+
7624
await pushSecret(iexec, appAddress, jsonSecret);
7725
};
7826

0 commit comments

Comments
 (0)