Skip to content

Commit e5b5430

Browse files
committed
feat: BE docker deployment
1 parent cb0cd5c commit e5b5430

File tree

7 files changed

+186
-30
lines changed

7 files changed

+186
-30
lines changed

Dockerfile.web

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
FROM node:16
22

3-
RUN git clone https://github.com/input-output-hk/dapps-certification.git
4-
RUN mv dapps-certification app
53
WORKDIR /app/
6-
RUN git checkout develop
7-
WORKDIR /app/react-web
4+
COPY react-web /app
85
COPY ./docker-files/.env.local .
96
RUN npm install
107

@@ -13,5 +10,9 @@ RUN sed -i 's/https:\/\/input-output-hk.github.io\/dapps-certification/http:\/\/
1310
#"proxy": "https://testing.dapps.iog.io/"
1411
RUN sed -i 's/https:\/\/testing.dapps.iog.io/http:\/\/localhost:3000/g' package.json
1512

16-
#ENTRYPOINT [ "/bin/sh" ]
13+
COPY ./docker-files/start_web.sh .
14+
RUN chmod +x ./start_web.sh
15+
16+
ENTRYPOINT [ "./start_web.sh" ]
17+
#ENTRYPOINT [ "/bin/sh","-c","./start_web.sh"]
1718
CMD [ "npm","start" ]

Dockerfile.ws

Lines changed: 0 additions & 17 deletions
This file was deleted.

dapps-certification-helpers/src/IOHK/Certification/Actions.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ logHandleText :: (MonadUnliftIO m)
214214
logHandleText backend addLogEntry h = go
215215
where
216216
go = do
217+
liftIO $ hSetEncoding h utf8
217218
acqEv <- acquireEvent backend ReadingHandleLog
218219
join $ with acqEv \ev -> do
219220
chunk <- liftIO $ hGetChunk h

docker-compose.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
version: "3.9"
22
services:
3-
plutus-certification-ws:
4-
build:
5-
context: .
6-
dockerfile: Dockerfile.ws
7-
extra_hosts:
8-
- "host.docker.internal:host-gateway"
9-
ports:
10-
- "9671:9671"
113
plutus-certification-web:
124
build:
135
context: .
146
dockerfile: Dockerfile.web
7+
environment:
8+
- REACT_APP_BASE_URL=https://google.com:8080
159
ports:
1610
- "3000:3000"

docker-files/run.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
WALLET_ADDRESS=addr_test1qphgqts20fhx0yx7ug42xehcnryukchy5k7hpaksgxax2fzt5w2gu33s8wrw3c9tjs97dr5pulsvf39e56v7c9ar39asptcrtp \
2+
WALLET_ID=73857344a0cf884fe044abfe85660cc9a81f6366 \
3+
WALLET_PASSPHRASE=test123456 \
4+
WALLET_URL="http://192.168.2.128:8090" \
5+
WALLET_CERTIFICATION_PRICE=1000000 \
6+
JWT_SECRET2=secret \
7+
PORT=80 \
8+
nix run .#runDockerImage

docker-files/start_web.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
#REACT_APP_BASE_URL="http://localhost:9671"
3+
echo $REACT_APP_BASE_URL
4+
npm start
5+
6+

flake.nix

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,99 @@
1212
in flake-utils.lib.eachSystem supportedSystems (system: let
1313
overlays = [ haskellNix.overlay ];
1414

15+
#***************************************************************************************
16+
# Docker image
17+
1518
pkgs = import nixpkgs { inherit system overlays; inherit (haskellNix) config; };
19+
pkgsLinux = pkgs // { system = "x86_64-linux"; };
20+
21+
imgAttributes = {
22+
name = "plutus-certification";
23+
tag = "8";
24+
};
25+
nixConfig = ''
26+
trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= iohk.cachix.org-1:DpRUyj7h7V830dp/i6Nti+NEO2/nhblbov/8MW7Rqoo= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
27+
substituters = https://hydra.iohk.io https://cache.nixos.org/ https://cache.iog.io
28+
build-users-group = nixbld
29+
sandbox = false
30+
experimental-features = nix-command flakes
31+
allow-import-from-derivation = true
32+
filter-syscalls = false
33+
'';
34+
entryPoint =
35+
let addParameter = paramName: varName: ''
36+
if [ -n "${"$"}${varName}" ]; then
37+
args="$args --${paramName} ${"$"}${varName}"
38+
fi
39+
'';
40+
in (pkgs.writeShellScript "entryPoint" ''
41+
set -eEo pipefail
42+
args="--local "
43+
${addParameter "wallet-id" "WALLET_ID"} \
44+
${addParameter "wallet-address" "WALLET_ADDRESS"} \
45+
${addParameter "wallet-passphrase" "WALLET_PASSPHRASE"}
46+
${addParameter "wallet-url" "WALLET_URL"}
47+
${addParameter "wallet-certification-price" "WALLET_CERTIFICATION_PRICE"}
48+
${addParameter "gh-access-token" "GH_ACCESS_TOKEN"}
49+
${addParameter "signature-timeout" "SIGNATURE_TIMEOUT"}
50+
${addParameter "use-whitelist" "USE_WHITELIST"}
51+
${addParameter "unsafe-plain-address-auth" "UNSAFE_PLAIN_ADDRESS_AUTH"}
52+
${addParameter "port" "PORT"}
53+
if [ -n "$JWT_SECRET" ];
54+
then
55+
args="$args --jwt-secret $JWT_SECRET"
56+
${addParameter "jwt-expiration-seconds" "JWT_EXPIRATION"}
57+
else
58+
args="$args --unsafe-plain-address-auth"
59+
fi
60+
61+
# create a temporary directory for executing flakes
62+
mkdir -p /tmp
63+
64+
# copy the certificate bundle to the right place
65+
mkdir -p /etc/ssl/certs
66+
script="cp ${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt /etc/ssl/certs/ca-certificates.crt"
67+
68+
#TODO: change this --unsafe-bypass-subscription-validation
69+
args="$args --unsafe-bypass-subscription-validation"
70+
71+
echo $script >&2
72+
eval "$script"
73+
74+
script="${flake.packages."plutus-certification:exe:plutus-certification"}/bin/plutus-certification $args"
75+
echo $script >&2
76+
eval "$script"
77+
'').outPath;
78+
79+
nixImage = pkgs.dockerTools.pullImage {
80+
imageName = "nixos/nix";
81+
imageDigest = "sha256:31b808456afccc2a419507ea112e152cf27e9bd2527517b0b6ca8639cc423501";
82+
sha256 = "0bbw3r0civlcm3inj23fq8f25aw63rnaay09qjbrvfjd7pcfbyqn";
83+
finalImageName = "nixos/nix";
84+
finalImageTag = "2.15.0";
85+
};
86+
genFlake = flake.packages."dapps-certification-helpers:exe:generate-flake";
87+
buildFlake = flake.packages."dapps-certification-helpers:exe:build-flake";
88+
89+
image = pkgs.dockerTools.buildImage (imgAttributes // {
90+
fromImage = nixImage;
91+
diskSize = 5120;
92+
#contents = [ pkgs.hello ];
93+
copyToRoot = pkgs.buildEnv {
94+
name = "image-root";
95+
paths = [ pkgs.curl pkgs.zsh pkgs.coreutils pkgs.nmon pkgs.cacert genFlake buildFlake ];
96+
pathsToLink = [ "/bin" ];
97+
};
98+
runAsRoot = ''
99+
rm -rf /etc/nix/nix.conf
100+
echo "${nixConfig}" > /etc/nix/nix.conf
101+
'';
102+
103+
config = {
104+
Cmd = ["${entryPoint}"];
105+
User = "root";
106+
};
107+
});
16108

17109
materializedPath = ./. + "/nix/materialized/${system}";
18110

@@ -29,12 +121,83 @@
29121
};
30122

31123
flake = project.flake {};
124+
loadDockerImage = {
125+
type= "app";
126+
program = (pkgs.writeShellScript "loadDockerImage" ''
127+
set -eEuo pipefail
128+
echo "Loading docker image ${image}" >&2
129+
${pkgs.docker}/bin/docker load -i ${image}
130+
'').outPath;
131+
};
132+
runDockerImage =
133+
let addEnvVar = varName: ''
134+
if [ -n "${"$"}${varName}" ]; then
135+
docker_args="$docker_args -e ${varName}=${"$"}${varName}"
136+
fi
137+
'';
138+
in {
139+
type = "app";
140+
program = (pkgs.writeShellScript "runDockerImage" ''
141+
set -eEo pipefail
142+
export PATH="${pkgs.lib.makeBinPath [ pkgs.docker pkgs.coreutils]}"
143+
echo "Executing ${loadDockerImage.program}..." >&2
144+
${loadDockerImage.program}
145+
docker_args="-t --platform linux/amd64 --name ${imgAttributes.name}"
146+
147+
${addEnvVar "WALLET_ID"}
148+
${addEnvVar "WALLET_ADDRESS"}
149+
${addEnvVar "WALLET_PASSPHRASE"}
150+
${addEnvVar "JWT_SECRET"}
151+
${addEnvVar "WALLET_URL"}
152+
${addEnvVar "WALLET_CERTIFICATION_PRICE"}
153+
${addEnvVar "GH_ACCESS_TOKEN"}
154+
${addEnvVar "JWT_EXPIRATION"}
155+
${addEnvVar "SIGNATURE_TIMEOUT"}
156+
${addEnvVar "USE_WHITELIST"}
157+
${addEnvVar "UNSAFE_PLAIN_ADDRESS_AUTH"}
158+
${addEnvVar "PORT"}
159+
160+
if [[ -z "$PORT" ]]; then
161+
export PORT=9671
162+
fi
163+
docker_args="$docker_args -p $PORT:$PORT"
164+
165+
script="docker run --rm $docker_args ${imgAttributes.name}:${imgAttributes.tag}"
166+
echo $script >&2
167+
eval "$script"
168+
'').outPath;
169+
};
170+
pushDockerImage = {
171+
type = "app";
172+
#usage: nix run .\#apps.x86_64-linux.pushDockerImage -- <docker registry>
173+
#E.g. nix run .\#apps.x86_64-linux.pushDockerImage -- ghcr.io/demoiog
174+
program = (pkgs.writeShellScript "pushDockerImage" ''
175+
set -eEuo pipefail
176+
export PATH="${pkgs.lib.makeBinPath [ pkgs.docker pkgs.coreutils]}"
177+
${loadDockerImage.program}
178+
echo "Pushing docker image ${image}" >&2
179+
imageName="${imgAttributes.name}:${imgAttributes.tag}"
180+
181+
script="docker image tag $imageName $1/$imageName"
182+
echo $script >&2
183+
eval "$script"
184+
185+
script="docker push $1/$imageName"
186+
echo $script >&2
187+
eval "$script"
188+
189+
'').outPath;
190+
};
32191
in flake // {
33192
packages = flake.packages // {
34193
inherit (project.plan-nix.passthru) generateMaterialized;
194+
inherit image;
35195
};
36196
defaultPackage = flake.packages."plutus-certification:exe:plutus-certification";
37197
apps = flake.apps // {
198+
inherit loadDockerImage;
199+
inherit runDockerImage;
200+
inherit pushDockerImage;
38201
updateAllMaterialized = {
39202
type = "app";
40203
program = (pkgs.writeShellScript "updateAllMaterialized" ''

0 commit comments

Comments
 (0)