github.com/containerd/nerdctl/v2@v2.0.0-beta.5.0.20240520001846-b5758f54fa28/examples/nerdctl-ipfs-registry-kubernetes/ipfs-cluster/bootstrap.yaml.sh (about)

     1  #!/bin/bash
     2  
     3  #   Copyright The containerd Authors.
     4  
     5  #   Licensed under the Apache License, Version 2.0 (the "License");
     6  #   you may not use this file except in compliance with the License.
     7  #   You may obtain a copy of the License at
     8  
     9  #       http://www.apache.org/licenses/LICENSE-2.0
    10  
    11  #   Unless required by applicable law or agreed to in writing, software
    12  #   distributed under the License is distributed on an "AS IS" BASIS,
    13  #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  #   See the License for the specific language governing permissions and
    15  #   limitations under the License.
    16  
    17  # Example script to prepare swarm key secret for IPFS bootstrap,
    18  # Example: ./bootstrap.yaml.sh > ./bootstrap.yaml
    19  
    20  set -eu -o pipefail
    21  
    22  for d in ipfs-key ipfs-swarm-key-gen ; do
    23      if ! which $d >/dev/null 2>&1 ; then
    24          echo "$d not found. See https://cluster.ipfs.io/documentation/guides/k8s/"
    25          exit 1
    26      fi
    27  done
    28  
    29  TMPIDFILE=$(mktemp)
    30  BOOTSTRAP_KEY=$(ipfs-key 2>"${TMPIDFILE}" | base64 -w 0)
    31  ID=$(cat "${TMPIDFILE}" | grep "ID " | sed -E 's/[^:]*: (.*)/\1/')
    32  rm "${TMPIDFILE}"
    33  
    34  BOOTSTRAP_PEER_PRIV_KEY=$(echo "${BOOTSTRAP_KEY}" | base64 -w 0)
    35  CLUSTER_SECRET=$(od  -vN 32 -An -tx1 /dev/urandom | tr -d ' \n' | base64 -w 0 -)
    36  
    37  SWARM_KEY=$(ipfs-swarm-key-gen | base64 -w 0)
    38  
    39  cat <<EOF
    40  apiVersion: v1
    41  kind: ConfigMap
    42  metadata:
    43    name: env-config
    44  data:
    45    cluster-bootstrap-peer-id: $ID
    46  ---
    47  apiVersion: v1
    48  kind: Secret
    49  metadata:
    50    name: secret-config
    51  type: Opaque
    52  data:
    53    cluster-secret: $CLUSTER_SECRET
    54    cluster-bootstrap-peer-priv-key: $BOOTSTRAP_PEER_PRIV_KEY
    55    ipfs-swarm-key: $SWARM_KEY
    56  EOF