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

Updating CI integration testing #94

Merged
merged 7 commits into from
Jan 17, 2024
Merged
40 changes: 34 additions & 6 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,10 @@ integration:deployment:
image=(./builds/*-docker-*);
./scripts/deploy-image.sh "${image[0]}" \'testnet\' "$CI_REGISTRY_IMAGE";
'
- echo 'Deploying ECS service to testnet'
- >
nix-shell --run $'
./scripts/deploy-service.sh \'polykey-testnet\';
'
- echo 'Waiting for seed nodes to update'
- >
nix-shell --arg ci true --run $'
./scripts/wait-for-deploy.js;
./scripts/wait-for-deploy.js testnet;
'
after_script:
- rm -f "$REGISTRY_AUTH_FILE"
Expand Down Expand Up @@ -343,6 +338,7 @@ integration:docker:
DOCKER_TLS_CERTDIR: "/certs"
FF_NETWORK_PER_BUILD: "true"
PK_TEST_TMPDIR: "${CI_PROJECT_DIR}/tmp/test"
PK_NETWORK: "testnet"
script:
- docker info
- mkdir $PK_TEST_TMPDIR
Expand Down Expand Up @@ -598,12 +594,43 @@ release:deployment:tag:
./scripts/deploy-image.sh "${image[0]}" \'mainnet\' "$CI_REGISTRY_IMAGE";
echo \'Deploying ECS service to mainnet\';
'
- echo 'Waiting for seed nodes to update'
- >
nix-shell --arg ci true --run $'
./scripts/wait-for-deploy.js mainnet;
'
after_script:
- rm -f "$REGISTRY_AUTH_FILE"
rules:
# Runs on tag pipeline where the tag is a release version
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/

release:integration:docker:
stage: release
needs:
- integration:builds
- job: release:deployment:tag
optional: true
services:
- docker:20.10.16-dind
variables:
DOCKER_TLS_CERTDIR: "/certs"
FF_NETWORK_PER_BUILD: "true"
PK_TEST_TMPDIR: "${CI_PROJECT_DIR}/tmp/test"
PK_NETWORK: "mainnet"
script:
- docker info
- mkdir $PK_TEST_TMPDIR
- >
nix-shell --arg ci true --run $'
image_and_tag="$(docker load --input ./builds/*docker* | cut -d\' \' -f3)";
docker tag "$image_and_tag" "polykey-cli:testtarget";
npm run test tests/integration/docker;
'
rules:
# Runs on tag pipeline where the tag is a release version
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/

release:distribution:
stage: release
needs:
Expand All @@ -612,6 +639,7 @@ release:distribution:
- integration:builds
- integration:merge
- release:deployment:tag
- release:integration:docker
# Don't interrupt publishing job
interruptible: false
# Requires mutual exclusion
Expand Down
46 changes: 0 additions & 46 deletions scripts/deploy-service.sh

This file was deleted.

30 changes: 25 additions & 5 deletions scripts/wait-for-deploy.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
#!/usr/bin/env node
const process = require('process');
const childProcess = require('child_process');
const { default: config } = require('polykey/dist/config');
const version = config.version;
async function main() {
// Dummy for now, only checking that all listed nodes are live
const versionTarget = config.version;
async function main(argv = process.argv) {
// Test getting the hash
const cliAgentCommitHashCurrentTarget =
process.env.CI_COMMIT_SHA ??
childProcess.execSync('git rev-parse HEAD').toString();
const network = argv[2];
if (network !== 'testnet' && network !== 'mainnet') {
throw Error('network must be "testnet" or "mainnet"');
}
const poll = async () => {
const result = await fetch(
'http://testnet.polykey.com/api/seednodes/status',
`https://${network}.polykey.com/api/seednodes/status`,
);
const statuses = await result.json();

let total = 0;
let updated = 0;
for (const [, status] of Object.entries(statuses)) {
const versionCurrent = status.version;
const cliAgentCommitHashCurrent =
status.versionMetadata.cliAgentCommitHash;
total++;
if (status.version != null && status.version === version) updated++;
// If the Polykey lib version and CLI commit hash match then it is updated
if (
versionCurrent != null &&
versionCurrent === versionTarget &&
cliAgentCommitHashCurrent != null &&
cliAgentCommitHashCurrent === cliAgentCommitHashCurrentTarget
) {
updated++;
}
}
process.stdout.write(`polled ${updated}/${total} updated\n`);
return updated === total;
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/docker/docker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import * as testUtils from '../../utils';
describe('docker integration tests', () => {
const commandFactory = (cwd: string) => {
const dockerOptions = testUtils.generateDockerArgs(cwd).join(' ');
// Return undefined
return `docker run ${dockerOptions} polykey-cli:testtarget`;
};

const logger = new Logger('start test', LogLevel.WARN, [new StreamHandler()]);
const password = 'abc123';
// Get the network from the env, otherwise default to testnet
const network = process.env.PK_NETWORK ?? 'testnet';
let dataDir: string;
let cleanup: Array<() => Promise<void>>;

Expand Down Expand Up @@ -113,7 +114,7 @@ describe('docker integration tests', () => {
// We can't test for hole punching on the same network, but we can see that all the nodes connect.
// I'm also simplifying this for now, there seems to be an issue with making CLI client calls to agents in the DIND
// docker CI job that needs to be looked into.
test('connect to testnet', async () => {
test('connect to network', async () => {
const password = 'abc123';
const polykeyPath = path.join(dataDir, 'polykey');
await fs.promises.mkdir(polykeyPath);
Expand All @@ -125,8 +126,6 @@ describe('docker integration tests', () => {
path.join(dataDir, 'polykey'),
'--workers',
'none',
'--network',
'testnet',
'--verbose',
'--format',
'json',
Expand All @@ -137,6 +136,7 @@ describe('docker integration tests', () => {
PK_PASSWORD: password,
PK_PASSWORD_OPS_LIMIT: 'min',
PK_PASSWORD_MEM_LIMIT: 'min',
PK_NETWORK: network,
},
cwd: dataDir,
command: commandFactory(dataDir),
Expand Down