forked from dfinity/internet-identity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-build
executable file
·127 lines (103 loc) · 3.32 KB
/
docker-build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env bash
# vim: ft=bash
# Build internet_identity.wasm inside docker. This outputs a single file, internet_identity.wasm,
# in the top-level directory.
set -euo pipefail
# Make sure we always run from the root
SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPTS_DIR/.."
function title() {
echo "Build Internet Identity inside Docker"
}
function usage() {
cat << EOF
Usage:
$0 [--internet-identity] [--archive]
Options:
--internet-identity build the internet_identity canister (alongside other specifically mentioned canisters), defaults to --internet-identity
--archive build the archive canister (alongside other specifically mentioned canisters), defaults to --internet-identity
Environment:
II_FETCH_ROOT_KEY When set to "1", enable the "II_FETCH_ROOT_KEY" feature.
II_DUMMY_CAPTCHA When set to "1", enable the "II_DUMMY_CAPTCHA" feature.
II_DUMMY_AUTH When set to "1", enable the "II_DUMMY_AUTH" feature.
II_INSECURE_REQUESTS When set to "1", enable the "II_INSECURE_REQUESTS" feature.
EOF
}
function help() {
cat << EOF
This will create (and override) "./internet_identity.wasm". For more information on build features, see:
https://github.com/dfinity/internet-identity#build-features-and-flavors
EOF
}
## Building
# forward "feature" environment variables ("$2") to the docker build
# NOTE: feature name ("$1") must be lower case as it's used in the image name
function check_feature() {
local varname="$2"
local featurename="$1"
local value="${!varname:-}"
if [[ "$value" == "1" ]]
then
echo "Using feature $featurename ($varname)"
docker_build_args+=( --build-arg "$varname=$value" )
image_name="$image_name-$featurename"
fi
}
# Builds a single canister using docker
# build_canister CANISTER
# CANISTER: possible values: [internet_identity, archive]
function build() {
image_name="ii-docker-build"
canister="$1"
docker_build_args=( --target "scratch_$canister" )
check_feature "fetchrootkey" "II_FETCH_ROOT_KEY"
check_feature "dummycaptcha" "II_DUMMY_CAPTCHA"
check_feature "dummyauth" "II_DUMMY_AUTH"
check_feature "insecurerequests" "II_INSECURE_REQUESTS"
docker_build_args+=(--tag "$image_name" .)
echo "The following image name will be used: $image_name"
tmp_outdir=$(mktemp -d)
set -x
DOCKER_BUILDKIT=1 docker build "${docker_build_args[@]}" --output "$tmp_outdir"
set +x
echo "Copying build output from $tmp_outdir to $PWD"
cp "$tmp_outdir/$canister.wasm" .
echo "Removing $tmp_outdir"
rm -rf "$tmp_outdir"
}
# ARGUMENT PARSING
CANISTERS=()
while [[ $# -gt 0 ]]
do
case $1 in
-h|--help)
title
usage
help
exit 0
;;
--internet-identity)
CANISTERS+=("internet_identity")
shift
;;
--archive)
CANISTERS+=("archive")
shift
;;
*)
echo "ERROR: unknown argument $1"
usage
echo
echo "Use '$0 --help' for more information"
exit 1
;;
esac
done
# build II by default
if [ ${#CANISTERS[@]} -eq 0 ]; then
CANISTERS=("internet_identity")
fi
for canister in "${CANISTERS[@]}"
do
build "$canister"
done