diff --git a/Makefile b/Makefile index 4ef6efcb986..d2ad2246900 100644 --- a/Makefile +++ b/Makefile @@ -66,6 +66,7 @@ MSP_SAMPLECONFIG = $(shell git ls-files msp/sampleconfig/*.pem) PROJECT_FILES = $(shell git ls-files) IMAGES = peer orderer ccenv javaenv buildenv testenv zookeeper kafka +pkgmap.configtxgen := $(PKGNAME)/common/configtx/tool/configtxgen pkgmap.peer := $(PKGNAME)/peer pkgmap.orderer := $(PKGNAME)/orderer pkgmap.block-listener := $(PKGNAME)/examples/events/block-listener @@ -96,6 +97,9 @@ peer-docker: build/image/peer/$(DUMMY) orderer: build/bin/orderer orderer-docker: build/image/orderer/$(DUMMY) +.PHONY: configtxgen +configtxgen: build/bin/configtxgen + buildenv: build/image/buildenv/$(DUMMY) build/image/testenv/$(DUMMY): build/image/buildenv/$(DUMMY) diff --git a/common/configtx/tool/configtxgen/main.go b/common/configtx/tool/configtxgen/main.go new file mode 100644 index 00000000000..aac401b3f35 --- /dev/null +++ b/common/configtx/tool/configtxgen/main.go @@ -0,0 +1,56 @@ +/* +Copyright IBM Corp. 2017 All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "flag" + "io/ioutil" + + genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig" + "github.com/hyperledger/fabric/common/configtx/tool/provisional" + "github.com/hyperledger/fabric/protos/utils" + + logging "github.com/op/go-logging" +) + +const ( + DefaultGenesisFileLocation = "genesis.block" +) + +var logger = logging.MustGetLogger("common/configtx/tool") + +func main() { + var writePath, profile string + + dryRun := flag.Bool("dryRun", false, "Whether to only generate but not write the genesis block file.") + flag.StringVar(&writePath, "path", DefaultGenesisFileLocation, "The path to write the genesis block to.") + flag.StringVar(&profile, "profile", genesisconfig.SampleInsecureProfile, "The profile from configtx.yaml to use for generation.") + flag.Parse() + + logging.SetLevel(logging.INFO, "") + + logger.Info("Loading configuration") + config := genesisconfig.Load(profile) + + logger.Info("Generating genesis block") + genesisBlock := provisional.New(config).GenesisBlock() + + if !*dryRun { + logger.Info("Writing genesis block") + ioutil.WriteFile(writePath, utils.MarshalOrPanic(genesisBlock), 0644) + } +} diff --git a/common/configtx/tool/localconfig/config.go b/common/configtx/tool/localconfig/config.go index f9751b555c4..4c1b235140c 100644 --- a/common/configtx/tool/localconfig/config.go +++ b/common/configtx/tool/localconfig/config.go @@ -39,10 +39,6 @@ const ( var logger = logging.MustGetLogger("configtx/tool/localconfig") -func init() { - logging.SetLevel(logging.ERROR, "") -} - // Prefix is the default config prefix for the orderer const Prefix string = "CONFIGTX" @@ -189,7 +185,8 @@ func Load(profile string) *Profile { // for environment variables config.SetEnvPrefix(Prefix) config.AutomaticEnv() - replacer := strings.NewReplacer(".", "_") + // This replacer allows substitution within the particular profile without having to fully qualify the name + replacer := strings.NewReplacer(strings.ToUpper(fmt.Sprintf("profiles.%s.", profile)), "", ".", "_") config.SetEnvKeyReplacer(replacer) err := config.ReadInConfig() @@ -208,6 +205,7 @@ func Load(profile string) *Profile { if !ok { logger.Panicf("Could not find profile %s", profile) } + result.completeInitialization() return result diff --git a/docs/configtxgen.md b/docs/configtxgen.md new file mode 100644 index 00000000000..cc3358ff670 --- /dev/null +++ b/docs/configtxgen.md @@ -0,0 +1,30 @@ +# Configuring using the configtxgen tool + +This document describe the usage for the `configtxgen` utility for manipulating fabric channel configuration. + +For now, the tool is primarily focused on generating the genesis block for bootstrapping the orderer, but it is intended to be enhanced in the future for generating new channel configurations as well as reconfiguring existing channels. + +## Building the tool + +Building the tool is as simple as `make configtxgen`. This will create a `configtxgen` binary at `build/bin/configtxgen` which is included in the Vagrant development environment path by default. + +## Configuration Profiles + +The configuration parameters supplied to the `configtxgen` tool are primarily provided by the `configtx.yaml` file. This file is located at `fabric/common/configtx/tool/configtx.yaml` in the fabric.git repository. + +This configuration file is split primarily into three pieces. + +1. The `Profiles` section. By default, this section includes some sample configurations which can be used for development or testing scenarios, and refer to crypto material present in the fabric.git tree. These profiles can make a good starting point for construction a real deployment profile. The `configtxgen` tool allows you to specify the profile it is operating under by passing the `-profile` flag. Profiles may explicitly declare all configuration, but usually inherit configuration from the defaults in (3) below. +2. The `Organizations` section. By default, this section includes a single reference to the sampleconfig MSP definition. For production deployments, the sample organization should be removed, and the MSP definitions of the network members should be referenced and defined instead. Each element in the `Organizations` section should be tagged with an anchor label such as `&orgName` which will allow the definition to be referenced in the `Profiles` sections. +3. The default sections. There are default sections for `Orderer` and `Application` configuration, these include attributes like `BatchTimeout` and are generally used as the base inherited values for the profiles. + +This configuration file may be edited, or, individual properties may be overridden by setting environment variables, such as `CONFIGTX_ORDERER_ORDERERTYPE=kafka`. Note that the `Profiles` element and profile name do not need to be specified. + +## Bootstrapping the orderer +After creating a configuration profile as desired, simply invoke +``` +configtxgen -profile <profile_name> +``` +This will produce a `genesis.block` file in the current directory. You may optionally specify another filename by passing in the `-path` parameter, or, you may skip the writing of the file by passing the `dryRun` parameter if you simply wish to test parsing of the file. + +Then, to utilize this genesis block, before starting the orderer, simply specify `ORDERER_GENERAL_GENESISMETHOD=file` and `ORDERER_GENERAL_GENESISFILE=$PWD/genesis.block` or modify the `orderer.yaml` file to encode these values. diff --git a/images/orderer/Dockerfile.in b/images/orderer/Dockerfile.in index ff917e42b2d..5ca59340e61 100644 --- a/images/orderer/Dockerfile.in +++ b/images/orderer/Dockerfile.in @@ -1,6 +1,7 @@ FROM hyperledger/fabric-baseos:_BASE_TAG_ ENV ORDERER_CFG_PATH /etc/hyperledger/fabric ENV ORDERER_GENERAL_LOCALMSPDIR $ORDERER_CFG_PATH/msp/sampleconfig +ENV ORDERER_GENERAL_GENESISPROFILE=SampleInsecureSolo RUN mkdir -p /var/hyperledger/production $ORDERER_CFG_PATH COPY payload/orderer /usr/local/bin COPY payload/configtx.yaml $ORDERER_CFG_PATH/ diff --git a/orderer/network_test.go b/orderer/network_test.go index df77c11cfe4..f3342babf9c 100644 --- a/orderer/network_test.go +++ b/orderer/network_test.go @@ -308,7 +308,7 @@ func generateConfigEnv(peerNum uint64, grpcPort int, peerCommPort string, certFi envs = append(envs, fmt.Sprintf("ORDERER_CFG_PATH=%s", ordererDir)) envs = append(envs, fmt.Sprintf("ORDERER_GENERAL_LOCALMSPDIR=%s", ordererDir+"/../msp/sampleconfig")) envs = append(envs, fmt.Sprintf("ORDERER_GENERAL_LISTENPORT=%d", grpcPort)) - envs = append(envs, fmt.Sprintf("CONFIGTX_PROFILES_SAMPLEINSECURESOLO_ORDERER_ORDERERTYPE=%s", "sbft")) + envs = append(envs, fmt.Sprintf("CONFIGTX_ORDERER_ORDERERTYPE=%s", "sbft")) envs = append(envs, fmt.Sprintf("ORDERER_GENERAL_GENESISPROFILE=%s", genesisconfig.SampleInsecureProfile)) envs = append(envs, fmt.Sprintf("ORDERER_GENESIS_DEPRECATEDBATCHTIMEOUT=%d", 1000)) envs = append(envs, fmt.Sprintf("ORDERER_GENESIS_DEPRECATED=%d", 1000000000))