Skip to content

Commit

Permalink
add chain selector
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasochem committed Dec 26, 2020
1 parent 4d91bfb commit 81f5bbd
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 26 deletions.
4 changes: 2 additions & 2 deletions docker/polkadot-archive-downloader/Dockerfile.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM alpine
RUN apk add curl p7zip bash
COPY polkadot-archive-downloader.sh /
ENTRYPOINT ["/polkadot-archive-downloader.sh"]
COPY entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
CMD []
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

set -e

if [ -d /polkadot/.local/share/polkadot/chains/ksmcc3/db/ ]; then
if [ "${CHAIN}" == "polkadot" ]; then
chain_dir=polkadot
else
chain_dir=ksmcc3
fi

if [ -d /polkadot/.local/share/polkadot/chains/${chain_dir}/db/ ]; then
echo "Blockchain database already exists, no need to import, exiting"
exit 0
elif [ -z "$ARCHIVE_URL" ]; then
Expand All @@ -11,10 +17,10 @@ elif [ -z "$ARCHIVE_URL" ]; then
else
echo "Did not find pre-existing data, importing blockchain"
rm -rvf /polkadot/.local/share/polkadot
mkdir -p /polkadot/.local/share/polkadot/chains/ksmcc3/
mkdir -p /polkadot/.local/share/polkadot/chains/${chain_dir}/
echo "Will download $ARCHIVE_URL"
curl $ARCHIVE_URL -o /polkadot/polkadot_archive.7z
7z x /polkadot/polkadot_archive.7z -o/polkadot/.local/share/polkadot/chains/ksmcc3
curl -L $ARCHIVE_URL -o /polkadot/polkadot_archive.7z
7z x /polkadot/polkadot_archive.7z -o/polkadot/.local/share/polkadot/chains/${chain_dir}
rm -v /polkadot/polkadot_archive.7z
chmod -R 777 /polkadot/.local/
chown -R 1000:1000 /polkadot/.local/
Expand Down
6 changes: 3 additions & 3 deletions docker/polkadot-node-key-configurator/Dockerfile.template
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM parity/polkadot:latest
USER root
# install tools and dependencies
RUN apt-get update && \
RUN apt-get update --allow-insecure-repositories && \
DEBIAN_FRONTEND=noninteractive apt-get upgrade -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
xxd && \
Expand All @@ -11,7 +11,7 @@ RUN apt-get update && \
RUN curl https://storage.googleapis.com/polkadot259c91787f329be9_cloudbuild/subkey -o /usr/local/bin/subkey && \
chmod 777 /usr/local/bin/subkey
USER polkadot
COPY polkadot-node-key-configurator.sh /
ENTRYPOINT ["/polkadot-node-key-configurator.sh"]
COPY entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
CMD []

6 changes: 3 additions & 3 deletions docker/polkadot-private-node/Dockerfile.template
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
FROM parity/polkadot:((polkadot_version))
USER root
# install tools and dependencies
RUN apt-get update && \
RUN apt-get update --allow-insecure-repositories && \
DEBIAN_FRONTEND=noninteractive apt-get upgrade -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
jq xxd && \
apt-get autoremove -y && \
apt-get clean && \
find /var/lib/apt/lists/ -type f -not -name lock -delete;
USER polkadot
COPY polkadot-private-node.sh /
ENTRYPOINT ["/polkadot-private-node.sh"]
COPY entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
CMD []
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ fi
# unsafe flags are due to polkadot panic alerter needing to connect to the node with rpc
eval /usr/bin/polkadot --validator --wasm-execution Compiled \
--unsafe-pruning \
--out-peers=100 \
--pruning=1000 \
--prometheus-external \
--node-key-file /polkadot/k8s_local_node_key \
$node_key_param \
$name_param \
$telemetry_url_param \
$chain_param
6 changes: 3 additions & 3 deletions k8s/kustomization.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ namePrefix: ${kubernetes_name_prefix}-
imageTags:
- name: polkadot-private-node
newName: gcr.io/${project}/polkadot-private-node
newTag: latest
newTag: ${kubernetes_namespace}-latest
- name: polkadot-archive-downloader
newName: gcr.io/${project}/polkadot-archive-downloader
newTag: latest
newTag: ${kubernetes_namespace}-latest
- name: polkadot-node-key-configurator
newName: gcr.io/${project}/polkadot-node-key-configurator
newTag: latest
newTag: ${kubernetes_namespace}-latest

configMapGenerator:
- name: polkadot-configmap
Expand Down
7 changes: 7 additions & 0 deletions k8s/polkadot-private-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ spec:
resources:
limits:
cpu: 0
imagePullPolicy: Always
volumes:
- name: polkadot-node-keys
secret:
Expand All @@ -129,11 +130,17 @@ spec:
- name: polkadot-private-node-pv-claim
mountPath: /polkadot
env:
- name: CHAIN
valueFrom:
configMapKeyRef:
name: polkadot-configmap
key: CHAIN
- name: ARCHIVE_URL
valueFrom:
configMapKeyRef:
name: polkadot-configmap
key: ARCHIVE_URL
imagePullPolicy: Always
volumeClaimTemplates:
- metadata:
name: polkadot-private-node-pv-claim
21 changes: 11 additions & 10 deletions terraform/k8s.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@ resource "null_resource" "push_containers" {
set -e
set -x
find ${path.module}/../docker -mindepth 1 -maxdepth 1 -type d -printf '%f\n'| while read container; do
pushd ${path.module}/../docker/$container
build_container () {
cd $1
container=$(basename $1)
cp Dockerfile.template Dockerfile
sed -i "s/((polkadot_version))/${var.polkadot_version}/" Dockerfile
cat << EOY > cloudbuild.yaml
steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', "gcr.io/${module.terraform-gke-blockchain.project}/$container:latest", '.']
images: ["gcr.io/${module.terraform-gke-blockchain.project}/$container:latest"]
args: ['build', '-t', "gcr.io/${module.terraform-gke-blockchain.project}/$container:${var.kubernetes_namespace}-latest", '.']
images: ["gcr.io/${module.terraform-gke-blockchain.project}/$container:${var.kubernetes_namespace}-latest"]
EOY
gcloud builds submit --project ${module.terraform-gke-blockchain.project} --config cloudbuild.yaml .
rm -vf Dockerfile
rm -vf cloudbuild.yaml
popd
done
rm -v Dockerfile
rm cloudbuild.yaml
}
export -f build_container
find ${path.module}/../docker -mindepth 1 -maxdepth 1 -type d -exec bash -c 'build_container "$0"' {} \; -printf '%f\n'
#build_container ${path.module}/../docker/polkadot-archive-downloader
EOF
}
}
Expand Down
1 change: 1 addition & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ variable "chain" {
variable "polkadot_archive_url" {
type = string
description = "archive url"
default = "https://dot.polkashots.io/snapshot"
}

variable "polkadot_telemetry_url" {
Expand Down

0 comments on commit 81f5bbd

Please sign in to comment.