Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
CMCDragonkai committed Jul 2, 2022
1 parent d8d9f89 commit b853b8c
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 9 deletions.
48 changes: 42 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,43 @@
DEBUG=
# Set the TMPDIR to be used
TMPDIR="$TMPDIR"

# Accessing AWS for testnet.polykey.io and mainnet.polykey.io deployment
AWS_DEFAULT_REGION='ap-southeast-2'
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=

# Container registry domain
CONTAINER_REGISTRY='015248367786.dkr.ecr.ap-southeast-2.amazonaws.com'

# Container repository
CONTAINER_REPOSITORY="$CONTAINER_REGISTRY/polykey"

# Accessing ECR for testnet.polykey.io and mainnet.polykey.io
# Path to container registry authentication file used by `skopeo`
# The file has the same contents as `DOCKER_AUTH_CONFIG`
# Use this command to acquire the auth file at `./tmp/auth.json`:
# ```
# aws ecr get-login-password --region ap-southeast-2 \
# | \
# skopeo login \
# --username AWS \
# --password-stdin \
# $CONTAINER_REPOSITORY \
# --authfile=./tmp/auth.json
# ```
# REGISTRY_AUTH_FILE=

# Unused atm (jest sets this to `test`)
NODE_ENV=development
TMPDIR=$TMPDIR
#To allow testing different executables in the bin tests
#PK_TEST_DOCKER_IMAGE=$image #Specify the docker image that the `docker-run.sh` uses
#PK_TEST_COMMAND=scripts/docker-run.sh #Specify the executable we want to test against
#PK_TEST_COMMAND_DOCKER=DOCKER #Specify if the test is for docker for filtering relevant tests

# Debug node modules - https://nodejs.org/api/cli.html#node_debugmodule
# NODE_DEBUG=

# Debug node native modules - https://nodejs.org/api/cli.html#node_debug_nativemodule
# NODE_DEBUG_NATIVE=

# Path to PK executable to override tests/bin target
# PK_TEST_COMMAND=

# If set, indicates that `PK_TEST_COMMAND` is targetting docker
# PK_TEST_COMMAND_DOCKER=
22 changes: 22 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ variables:
GH_PROJECT_PATH: "MatrixAI/${CI_PROJECT_NAME}"
GH_PROJECT_URL: "https://${GITHUB_TOKEN}@github.com/${GH_PROJECT_PATH}.git"
GIT_SUBMODULE_STRATEGY: recursive
# Container service
CONTAINER_REGISTRY: "015248367786.dkr.ecr.ap-southeast-2.amazonaws.com"
CONTAINER_REPOSITORY: "$CONTAINER_REGISTRY/polykey"
# Cache .npm
NPM_CONFIG_CACHE: "${CI_PROJECT_DIR}/tmp/npm"
# Prefer offline node module installation
Expand Down Expand Up @@ -287,8 +290,19 @@ integration:deployment:
interruptible: false
# Requires mutual exclusion
resource_group: integration:deployment
environment:
name: 'testnet'
deployment_tier: 'staging'
url: pk://testnet.polykey.io
script:
- echo 'Perform service deployment for integration testing'
- >
nix-shell --run '
image=(./builds/*-docker-*);
npm run deploy-image "${image[0]}";
'
- echo 'Updating ECS task definition'
- echo 'Updating ECS service'
rules:
# Runs on staging commits and ignores version commits
- if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
Expand Down Expand Up @@ -498,6 +512,10 @@ release:deployment:branch:
interruptible: false
# Requires mutual exclusion (also with release:deployment:tag)
resource_group: release:deployment
environment:
name: 'mainnet'
deployment_tier: 'production'
url: pk://mainnet.polykey.io
script:
- echo 'Perform service deployment for production'
rules:
Expand All @@ -514,6 +532,10 @@ release:deployment:tag:
interruptible: false
# Requires mutual exclusion (also with release:deployment:branch)
resource_group: release:deployment
environment:
name: 'mainnet'
deployment_tier: 'production'
url: pk://mainnet.polykey.io
script:
- echo 'Perform service deployment for production'
rules:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"scripts": {
"prepare": "tsc -p ./tsconfig.build.json",
"build": "shx rm -rf ./dist && tsc -p ./tsconfig.build.json",
"postbuild": "shx cp -fR src/proto dist && shx cp src/notifications/*.json dist/notifications/ && shx cp src/claims/*.json dist/claims/ && shx cp src/status/*.json dist/status/",
"postbuild": "shx cp -fR src/proto dist && shx cp -f src/notifications/*.json dist/notifications/ && shx cp -f src/claims/*.json dist/claims/ && shx cp -f src/status/*.json dist/status/",
"postversion": "npm install --package-lock-only --ignore-scripts --silent",
"ts-node": "ts-node --require tsconfig-paths/register",
"test": "jest",
Expand All @@ -72,6 +72,7 @@
"bench": "shx rm -rf ./benches/results && ts-node --require tsconfig-paths/register --compiler typescript-cached-transpile --transpile-only ./benches",
"proto-generate": "scripts/proto-generate.sh",
"pkg": "./scripts/pkg.js --no-dict=leveldown.js",
"deploy-image": "./scripts/deploy-image.sh",
"polykey": "ts-node --require tsconfig-paths/register --compiler typescript-cached-transpile --transpile-only src/bin/polykey.ts"
},
"dependencies": {
Expand Down
28 changes: 28 additions & 0 deletions scripts/deploy-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

# Push container image to $CONTAINER_REPOSITORY
# Pass the path to the container image archive
# For example `deploy-image.sh $(nix-build ./release.nix -A docker`

if [ -z "$CONTAINER_REPOSITORY" ]; then
printf '%s\n' 'Missing $CONTAINER_REPOSITORY environment variable' >&2
exit 1
fi

image="$1"

if [ -z "$image" ]; then
printf '%s\n' 'Missing path to container image archive' >&2
exit 1
fi

container_tag="$(skopeo list-tags "docker-archive:$image" \
| jq -r '.Tags[0] | split(":")[1]')";

skopeo --insecure-policy copy \
"docker-archive:$image" \
"docker://$CONTAINER_REPOSITORY:$container_tag";

skopeo --insecure-policy copy \
"docker://$CONTAINER_REPOSITORY:$container_tag" \
"docker://$CONTAINER_REPOSITORY:latest";
3 changes: 3 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ in
utils.node2nix
grpc-tools
grpcurl
awscli
skopeo
jq
];
PKG_CACHE_PATH = utils.pkgCachePath;
PKG_IGNORE_TAG = 1;
Expand Down
4 changes: 2 additions & 2 deletions tests/bin/bootstrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ describe('bootstrap', () => {
});
});
await new Promise((res) => {
bootstrapProcess1.once('exit', () => res(null))
})
bootstrapProcess1.once('exit', () => res(null));
});
// Attempting to bootstrap should fail with existing state
const bootstrapProcess2 = await testBinUtils.pkStdio(
[
Expand Down

0 comments on commit b853b8c

Please sign in to comment.