github.com/leonlxy/hyperledger@v1.0.0-alpha.0.20170427033203-34922035d248/docker-env.mk (about)

     1  # Copyright London Stock Exchange Group All Rights Reserved.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #      http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  ifneq ($(shell uname),Darwin)
    16  DOCKER_RUN_FLAGS=--user=$(shell id -u)
    17  endif
    18  
    19  ifeq ($(shell uname -m),s390x)
    20  ifneq ($(shell id -u),0)
    21  DOCKER_RUN_FLAGS+=-v /etc/passwd:/etc/passwd:ro
    22  endif
    23  endif
    24  
    25  ifneq ($(http_proxy),)
    26  DOCKER_BUILD_FLAGS+=--build-arg 'http_proxy=$(http_proxy)'
    27  DOCKER_RUN_FLAGS+=-e 'http_proxy=$(http_proxy)'
    28  endif
    29  ifneq ($(https_proxy),)
    30  DOCKER_BUILD_FLAGS+=--build-arg 'https_proxy=$(https_proxy)'
    31  DOCKER_RUN_FLAGS+=-e 'https_proxy=$(https_proxy)'
    32  endif
    33  ifneq ($(HTTP_PROXY),)
    34  DOCKER_BUILD_FLAGS+=--build-arg 'HTTP_PROXY=$(HTTP_PROXY)'
    35  DOCKER_RUN_FLAGS+=-e 'HTTP_PROXY=$(HTTP_PROXY)'
    36  endif
    37  ifneq ($(HTTPS_PROXY),)
    38  DOCKER_BUILD_FLAGS+=--build-arg 'HTTPS_PROXY=$(HTTPS_PROXY)'
    39  DOCKER_RUN_FLAGS+=-e 'HTTPS_PROXY=$(HTTPS_PROXY)'
    40  endif
    41  ifneq ($(no_proxy),)
    42  DOCKER_BUILD_FLAGS+=--build-arg 'no_proxy=$(no_proxy)'
    43  DOCKER_RUN_FLAGS+=-e 'no_proxy=$(no_proxy)'
    44  endif
    45  ifneq ($(NO_PROXY),)
    46  DOCKER_BUILD_FLAGS+=--build-arg 'NO_PROXY=$(NO_PROXY)'
    47  DOCKER_RUN_FLAGS+=-e 'NO_PROXY=$(NO_PROXY)'
    48  endif
    49  
    50  DRUN = docker run -i --rm $(DOCKER_RUN_FLAGS) \
    51  	-v $(abspath .):/opt/gopath/src/$(PKGNAME) \
    52  	-w /opt/gopath/src/$(PKGNAME)
    53  
    54  DBUILD = docker build $(DOCKER_BUILD_FLAGS)
    55  
    56  BASE_DOCKER_NS ?= hyperledger
    57  BASE_DOCKER_TAG=$(ARCH)-$(BASEIMAGE_RELEASE)
    58  
    59  DOCKER_NS ?= hyperledger
    60  DOCKER_TAG=$(ARCH)-$(PROJECT_VERSION)
    61  
    62  BASE_DOCKER_LABEL=org.hyperledger.fabric
    63  
    64  DOCKER_GO_LDFLAGS += $(GO_LDFLAGS)
    65  DOCKER_GO_LDFLAGS += -linkmode external -extldflags '-static -lpthread'
    66  
    67  #
    68  # What is a .dummy file?
    69  #
    70  # Make is designed to work with files.  It uses the presence (or lack thereof)
    71  # and timestamps of files when deciding if a given target needs to be rebuilt.
    72  # Docker containers throw a wrench into the works because the output of docker
    73  # builds do not translate into standard files that makefile rules can evaluate.
    74  # Therefore, we have to fake it.  We do this by constructioning our rules such
    75  # as
    76  #       my-docker-target/.dummy:
    77  #              docker build ...
    78  #              touch $@
    79  #
    80  # If the docker-build succeeds, the touch operation creates/updates the .dummy
    81  # file.  If it fails, the touch command never runs.  This means the .dummy
    82  # file follows relatively 1:1 with the underlying container.
    83  #
    84  # This isn't perfect, however.  For instance, someone could delete a docker
    85  # container using docker-rmi outside of the build, and make would be fooled
    86  # into thinking the dependency is statisfied when it really isn't.  This is
    87  # our closest approximation we can come up with.
    88  #
    89  # As an aside, also note that we incorporate the version number in the .dummy
    90  # file to differentiate different tags to fix FAB-1145
    91  #
    92  DUMMY = .dummy-$(DOCKER_TAG)