Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-monorepo into extend-expiry-method
  • Loading branch information
pedrouid committed Feb 3, 2022
2 parents 9d9e300 + e5aef1f commit 8a3ba9d
Show file tree
Hide file tree
Showing 45 changed files with 6,089 additions and 22,530 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: docker-practice/actions-setup-docker@master
- uses: cachix/install-nix-action@v13
- uses: cachix/install-nix-action@v16
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |
sandbox = false
- uses: cachix/cachix-action@v10
with:
name: walletconnect
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ logs
*.log
npm-debug.log*
lerna-debug.log
*.lerna_backup

# Runtime data
pids
Expand All @@ -29,5 +30,5 @@ zip
tsconfig.tsbuildinfo
test.db
setup
result
result*
ops/grafana/grafana.ini
55 changes: 8 additions & 47 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ dockerLoad=docker load -i build/$@ \
| awk '{print $$NF}' \
| tee build/$@-img
copyResult=cp -r -f -L result build/$@ && rm -rf result
buildRelayDeps=nix-build --attr relayDeps
buildRelayApp=nix-build --attr relayApp
buildRelay=nix-build --attr relay --argstr githash $(GITHASH) && $(copyResult)
caddyVersion=v2.4.3
caddySrc=https://github.com/WalletConnect-Labs/nix-caddy/archive/$(caddyVersion).tar.gz
buildCaddy=nix-build $(caddySrc) --attr docker && $(copyResult)
buildRelay=nix-build --attr relay.docker --argstr githash $(GITHASH) && $(copyResult)
WAKU_VERSION_TAG ?= v0.5.1
WAKU_SHA256 ?= 0k55hw1wqcyrpf9cxchhxdb92p75mmskkpvfn1paivl1r38pyb4a
buildWakuCommand:=nix-build ./ops/waku-docker.nix --argstr wakuVersionTag $(WAKU_VERSION_TAG) --argstr nixNimRepoSha256 $(WAKU_SHA256)
Expand Down Expand Up @@ -60,7 +55,7 @@ setup: ## configures domain and certbot email
$(log_end)

bootstrap-lerna: ## setups lerna for the monorepo management
npm i --dev
npm i --include=dev
npm run bootstrap
touch $(flags)/$@
$(log_end)
Expand Down Expand Up @@ -93,23 +88,7 @@ ifneq (, $(shell which nix))
endif
$(log_end)

build-relay-deps: dirs
ifeq (, $(shell which nix))
$(dockerizedNix) "$(buildRelayDeps)"
else
$(buildRelayDeps)
endif
$(log_end)

build-relay-app: dirs
ifeq (, $(shell which nix))
$(dockerizedNix) "$(buildRelayApp)"
else
$(buildRelayApp)
endif
$(log_end)

build-img-relay: dirs nix-volume build-relay-deps build-relay-app ## builds relay docker image inside of docker
build-img-relay: dirs nix-volume ## builds relay docker image inside of docker
ifeq (, $(shell which nix))
$(dockerizedNix) "$(buildRelay)"
else
Expand All @@ -118,16 +97,7 @@ endif
$(dockerLoad)
$(log_end)

build-img-caddy: dirs nix-volume ## builds caddy docker image inside of docker
ifeq (, $(shell which nix))
$(dockerizedNix) "$(buildCaddy)"
else
$(buildCaddy)
endif
$(dockerLoad)
$(log_end)

build-img-waku: dirs nix-volume ## builds caddy docker image inside of docker
build-img-waku: dirs nix-volume ## builds waky docker image inside of docker
ifeq (, $(shell which nix))
$(dockerizedNix) "$(buildWaku)"
else
Expand All @@ -136,7 +106,7 @@ endif
$(dockerLoad)
$(log_end)

build-images: build-img-relay build-img-caddy build-img-waku
build-images: build-img-relay build-img-waku

build: dirs build-images bootstrap-lerna build-relay build-react-app build-react-wallet ## builds all the packages and the containers for the relay
$(log_end)
Expand Down Expand Up @@ -169,15 +139,10 @@ dev: predeploy ## runs relay on watch mode and shows logs
ci: ## runs tests in github actions
printf "export RELAY_URL=localhost\nexport [email protected]\nexport CLOUDFLARE_TOKEN=\n" > setup
$(MAKE) dev
#nix show-derivation /nix/store/*-relay-conf.json.drv
#nix show-derivation /nix/store/*-stream-relay.drv
#nix show-derivation /nix/store/*-relay.tar.gz.drv
#nix show-derivation /nix/store/*-relay-base.json.drv
sleep 15
docker service logs --tail 100 $(project)_caddy
docker service logs --tail 100 $(project)_relay
TEST_RELAY_URL=wss://localhost $(MAKE) test-client
TEST_RELAY_URL=wss://localhost $(MAKE) test-relay
TEST_RELAY_URL=ws://localhost:5000 $(MAKE) test-client
TEST_RELAY_URL=ws://localhost:5000 $(MAKE) test-relay

deploy: setup predeploy ## Deploys the docker swarm for the relay
bash ops/deploy.sh
Expand All @@ -188,18 +153,14 @@ deploy-no-monitoring: setup predeploy ## same as deploy but without the monitori
$(log_end)

redeploy: setup clean predeploy ## redeploys the prodution containers and rebuilds them
docker service update --force --image $(caddyImage) $(project)_caddy
docker service update --force --image $(relayImage) $(project)_relay

relay-logs: ## follows the relay container logs.
docker service logs -f --raw --tail 100 $(project)_relay

cachix: clean dirs ## pushes docker images to cachix
cachix push walletconnect $(shell $(buildRelayDeps))
cachix push walletconnect $(shell $(buildRelayApp))
cachix push walletconnect $(shell $(buildRelay))
cachix push walletconnect $(shell $(buildWaku))
cachix push walletconnect $(shell $(buildCaddy))

rm-redis: ## stops the redis container
docker stop $(standAloneRedis) || true
Expand All @@ -218,5 +179,5 @@ reset: ## removes all build artifacts
$(log_end)

clean: ## removes all build outputs
rm -rf .makeFlags build
rm -rf .makeFlags build result*
$(log_end)
116 changes: 52 additions & 64 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,80 +1,68 @@
{ pkgs ? import (import ./ops/nix/sources.nix).nixpkgs {}, githash ? ""}:
with pkgs; let
myNodejs = pkgs.nodejs-14_x;
nodeEnv = callPackage ./ops/node-env.nix {
nodejs = myNodejs;
inherit pkgs stdenv lib python2 runCommand writeTextFile;
libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null;
{ sources ? import ./ops/nix/sources.nix, githash ? "" }:
let
organization = "walletconnect";
pkgs = import sources.nixpkgs {
overlays = [
(self: super: {
npmlock2nix = pkgs.callPackage sources.npmlock2nix { };
})
];
};

nodeAppDerivation = { path, pkgjson, nodeDependencies }: pkgs.stdenv.mkDerivation {
buildNodeApp =
{ src
, node_modules
, pkgjson ? builtins.fromJSON (builtins.readFile (src + "/package.json"))
}: pkgs.stdenv.mkDerivation {
inherit src;
pname = builtins.replaceStrings [ "@" "/" ] [ "_at_" "_slash_" ] pkgjson.name;
version = "v${pkgjson.version}";
src = pkgs.nix-gitignore.gitignoreSourcePure [
"**/test"
"Makefile"
"result"
"dist"
"node_modules"
"ops"
".git"
./.gitignore
] path;
buildInputs = [ myNodejs ];
buildInputs = [ node_modules.nodejs ];
buildPhase = ''
export HOME=$TMP
mkdir -p $out
ln -s ${nodeDependencies}/lib/node_modules ./node_modules
ln -s ${node_modules}/node_modules ./node_modules
${node_modules.nodejs}/bin/npm run compile
'';
installPhase = ''
${myNodejs}/bin/npm run compile
ln -s ${nodeDependencies}/lib/node_modules $out/node_modules
mkdir -p $out
ln -s ${node_modules}/node_modules $out/node_modules
cp -r dist/ $out/
cp -r package.json $out/
export PATH=${myNodejs}/bin:$PATH
'';
};

relayApp = nodeAppDerivation {
pkgjson = builtins.fromJSON (builtins.readFile ./servers/relay/package.json);
nodeDependencies = (callPackage ./servers/relay/node-packages.nix {
inherit nodeEnv;
}).nodeDependencies;
path = ./servers/relay;
};

healthApp = nodeAppDerivation {
pkgjson = builtins.fromJSON (builtins.readFile ./servers/health/package.json);
nodeDependencies = (callPackage ./servers/health/node-packages.nix {
inherit nodeEnv;
}).nodeDependencies;
path = ./servers/health;
};

in {
relayDeps = (callPackage ./servers/relay/node-packages.nix {
inherit nodeEnv;
}).nodeDependencies;
relayApp = relayApp;
relay = pkgs.dockerTools.buildLayeredImage {
name = "walletconnect/${
pkgs.lib.lists.last (builtins.split "_slash_" relayApp.pname)
}";
tag = "${relayApp.version}";
buildDockerImage = { app, nodejs, githash }: pkgs.dockerTools.buildLayeredImage {
name = "${organization}/${pkgs.lib.lists.last (builtins.split "_slash_" app.pname)}";
tag = "${app.version}";
config = {
Cmd = [ "${myNodejs}/bin/node" "${relayApp}/dist" ];
Env = [
"GITHASH=${githash}"
];
Cmd = [ "${nodejs}/bin/node" "${app}/dist" ];
Env = [ "GITHASH=${githash}" ];
};
};
health = pkgs.dockerTools.buildLayeredImage {
name = "walletconnect/${
pkgs.lib.lists.last (builtins.split "_slash_" healthApp.pname)
}";
tag = "${healthApp.version}";
config = {
Cmd = [ "${myNodejs}/bin/node" "${healthApp}/dist" ];
build = { src, nodejs }: rec {
app = buildNodeApp {
inherit src;
# remember that node_modules {} accepts mkDerivation attributes
node_modules = pkgs.npmlock2nix.node_modules {
inherit src nodejs;
buildPhase = ''npm ci'';
};
};
docker = buildDockerImage { inherit app githash nodejs; };
};
in
{
relay = build {
nodejs = pkgs.nodejs-16_x;
src = pkgs.nix-gitignore.gitignoreSourcePure [
"dist"
"test"
./.gitignore
] ./servers/relay;
};
health = build {
nodejs = pkgs.nodejs-16_x;
src = pkgs.nix-gitignore.gitignoreSourcePure [
"dist"
"test"
./.gitignore
] ./servers/health;
};
}
54 changes: 0 additions & 54 deletions ops/Caddyfile

This file was deleted.

2 changes: 2 additions & 0 deletions ops/docker-compose.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ services:
relay:
environment:
WAKU_URL: ""
ports:
- "5000:5000"
15 changes: 0 additions & 15 deletions ops/docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
version: '3.9'

volumes:
caddy_data:
caddy_conf:

services:
caddy:
environment:
DOMAIN: ${RELAY_URL:-localhost}
EMAIL: ${CERTBOT_EMAIL}
CLOUDFLARE_TOKEN: ${CLOUDFLARE_TOKEN}
UPSTREAM_NAME: ${UPSTREAM_NAME:-relay}
UPSTREAM_PORT: ${UPSTREAM_PORT:-5000}
LOG_LEVEL: ${LOG_LEVEL:-ERROR}
deploy:
replicas: ${REPLICAS:-1}

relay:
environment:
LOG_LEVEL: ${LOG_LEVEL:-INFO}
Expand Down
25 changes: 0 additions & 25 deletions ops/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,8 @@ volumes:
name: 'redis-{{.Task.Slot}}'
waku:
name: 'waku-{{.Task.Slot}}'
caddy_data:
caddy_conf:

configs:
caddyfile:
file: ./Caddyfile

services:
caddy:
image: ${CADDY_IMAGE}
deploy:
mode: replicated
# Port mode must be mode: host to allow access to the external ip
configs:
- source: caddyfile
target: /config/Caddyfile
ports:
- target: 80
published: 80
mode: ingress
- target: 443
published: 443
mode: ingress
volumes:
- caddy_data:/data
- caddy_conf:/config

redis:
image: 'redis:6-alpine'
hostname: "redis.{{.Task.Slot}}"
Expand Down
Loading

0 comments on commit 8a3ba9d

Please sign in to comment.