diff --git a/docker/Makefile b/docker/Makefile index 45a9e44c..14c03788 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -25,6 +25,8 @@ PDO_REPO ?= ${PDO_SOURCE_ROOT} PDO_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD) +PDO_VERSION ?= $(shell cd repository; bin/get_version) + # PDO_USER_UID, PDO_GROUP_UID -- # The UID/GID for the user accounts that will be created in the container; this is # important especially when the containers are being used for development; note @@ -38,11 +40,9 @@ PDO_GROUP_UID ?= $(shell id -g) # Turns out that setting the script directory from the Makefile's name # does not work very well if the path contains spaces in the name; in # fact lots of things break very badly; set this explicitly -SCRIPT_DIR ?= ${PDO_SOURCE_ROOT}/docker +DOCKER_DIR ?= ${PDO_SOURCE_ROOT}/docker DOCKER_USERNAME = $(LOGNAME) -DOCKER_BUILDARGS += --build-arg PDO_HOSTNAME=$(PDO_HOSTNAME) -DOCKER_BUILDARGS += --build-arg PDO_LEDGER_URL=$(PDO_LEDGER_URL) DOCKER_BUILDARGS += --build-arg UID=$(PDO_USER_UID) DOCKER_BUILDARGS += --build-arg GID=$(PDO_GROUP_UID) DOCKER_ARGS = $(DOCKER_BUILDARGS) @@ -56,32 +56,47 @@ TIMESTAMP := $(shell /bin/date "+%Y%m%d%H%M%S") all : $(addprefix build_,$(IMAGES)) rebuild_% : repository - @ docker build $(DOCKER_ARGS) \ + docker build $(DOCKER_ARGS) \ --build-arg REBUILD=$(TIMESTAMP) \ - --build-arg PDO_VERSION=$(shell cd repository; bin/get_version) \ - --tag pdo_$*:$(shell cd repository; bin/get_version) \ - --file $(SCRIPT_DIR)/pdo_$*.dockerfile . + --build-arg PDO_VERSION=$(PDO_VERSION) \ + --tag pdo_$*:$(PDO_VERSION) \ + --file $(DOCKER_DIR)/pdo_$*.dockerfile . build_% : repository - @ docker build $(DOCKER_ARGS) \ - --build-arg PDO_VERSION=$(shell cd repository; bin/get_version) \ - --tag pdo_$*:$(shell cd repository; bin/get_version) \ - --file $(SCRIPT_DIR)/pdo_$*.dockerfile . + docker build $(DOCKER_ARGS) \ + --build-arg PDO_VERSION=$(PDO_VERSION) \ + --tag pdo_$*:$(PDO_VERSION) \ + --file $(DOCKER_DIR)/pdo_$*.dockerfile . + +# docker build dependencies +build_client: build_base +build_services: build_services_base +build_services_base: build_base +build_ccf: build_ccf_base + clean_% : - @ docker rmi -f pdo_$* + @ docker rmi -f pdo_$*:$(PDO_VERSION) + +run_ccf : build_ccf stop_ccf + @ docker run -v $(DOCKER_DIR)/xfer/:/project/pdo/xfer -e PDO_HOSTNAME=${PDO_HOSTNAME} --network host --name ccf_container -P -d pdo_ccf:$(PDO_VERSION) + +run_services : build_base build_services_base build_services stop_services + @ docker run -v $(DOCKER_DIR)/xfer/:/project/pdo/xfer -e PDO_HOSTNAME=${PDO_HOSTNAME} --network host --name services_container -P -d pdo_services:$(PDO_VERSION) -run_ccf : build_ccf +run_client : build_base build_client + @docker run -v $(DOCKER_DIR)/xfer/:/project/pdo/xfer -e PDO_HOSTNAME=${PDO_HOSTNAME} -it --network host --name client_container pdo_client:$(PDO_VERSION) -c "stty cols $$(tput cols) rows $$(tput lines) && bash" + +stop_all : stop_ccf stop_services stop_client + +stop_ccf : - docker rm -f ccf_container - @ docker run -v $(SCRIPT_DIR)/xfer/:/project/pdo/xfer --network host --name ccf_container -P -d pdo_ccf -run_services : build_base build_services_base build_services +stop_services : - docker rm -f services_container - @ docker run -v $(SCRIPT_DIR)/xfer/:/project/pdo/xfer --network host --name services_container -P -d pdo_services -run_client : build_base build_client +stop_client : - docker rm -f client_container - @ docker run -v $(SCRIPT_DIR)/xfer/:/project/pdo/xfer -it --network host --name client_container pdo_client # ----------------------------------------------------------------- # We need a repository with the source for the branch we are going @@ -109,14 +124,12 @@ TEST_FILES += -f services_base.yaml TEST_FILES += -f ccf_base.yaml TEST_FILES += -f test.yaml -build_test : repository - PDO_USER_UID=$(PDO_USER_UID) PDO_GROUP_UID=$(PDO_GROUP_UID) \ - docker-compose $(TEST_FILES) build \ - --build-arg PDO_VERSION=$(shell cd repository; bin/get_version) +build_test : repository build_services build_ccf build_client + +test : clean_config clean_repository build_test stop_all + PDO_VERSION=$(PDO_VERSION) docker-compose $(TEST_FILES) up --abort-on-container-exit + PDO_VERSION=$(PDO_VERSION) docker-compose $(TEST_FILES) down -test : clean_config clean_repository build_base build_services_base build_ccf_base build_test - docker-compose $(TEST_FILES) up --abort-on-container-exit - docker-compose $(TEST_FILES) down # ----------------------------------------------------------------- # Cleaning is a bit interesting because the containers don't go away @@ -131,9 +144,9 @@ clean_images : $(addprefix clean_,$(IMAGES)) @ if [ ! -z "$(_IMAGES_)" ]; then docker rmi -f $(_IMAGES_); fi clean_config : - @ rm -f $(SCRIPT_DIR)/xfer/ccf/keys/*.pem $(SCRIPT_DIR)/xfer/ccf/etc/*.toml - @ rm -f $(SCRIPT_DIR)/xfer/services/keys/*.pem $(SCRIPT_DIR)/xfer/services/etc/*.toml - @ rm -f $(SCRIPT_DIR)/xfer/services/etc/site.psh + @ rm -f $(DOCKER_DIR)/xfer/ccf/keys/*.pem $(DOCKER_DIR)/xfer/ccf/etc/*.toml + @ rm -f $(DOCKER_DIR)/xfer/services/keys/*.pem $(DOCKER_DIR)/xfer/services/etc/*.toml + @ rm -f $(DOCKER_DIR)/xfer/services/etc/site.psh clean : clean_images clean_config clean_repository diff --git a/docker/base.yaml b/docker/base.yaml index 8333d0f0..2e8062a3 100644 --- a/docker/base.yaml +++ b/docker/base.yaml @@ -17,7 +17,7 @@ version: "3.4" services: base_container: - image: pdo_base - build: - context: . - dockerfile: pdo_base.dockerfile + image: pdo_base:${PDO_VERSION:-latest} + # build containers only via Makefile and directly via docker build + # as we use containers also outside of docker-compose to prevent + # double-build diff --git a/docker/ccf_base.yaml b/docker/ccf_base.yaml index a2bedb4c..73a0c760 100644 --- a/docker/ccf_base.yaml +++ b/docker/ccf_base.yaml @@ -16,16 +16,10 @@ version: "3.4" services: ccf_container: - image: pdo_ccf - build: - context: . - dockerfile: pdo_ccf.dockerfile - args: - PDO_INTERPRETER: ${PDO_INTERPRETER:-wawaka} - PDO_LEDGER_TYPE: ccf - PDO_HOSTNAME: ${PDO_HOSTNAME} - PDO_LEDGER_URL: ${PDO_LEDGER_URL} - SGX_MODE: ${SGX_MODE:-SIM} + image: pdo_ccf:${PDO_VERSION:-latest} + # build containers only via Makefile and directly via docker build + # as we use containers also outside of docker-compose to prevent + # double-build container_name: ccf_container network_mode: "host" volumes: diff --git a/docker/client_base.yaml b/docker/client_base.yaml index 0929529b..e610e6f7 100644 --- a/docker/client_base.yaml +++ b/docker/client_base.yaml @@ -16,19 +16,9 @@ version: "3.4" services: client_container: - image: pdo_client - build: - context: . - dockerfile: pdo_client.dockerfile - args: - UID: ${PDO_USER_UID:-1000} - GID: ${PDO_GROUP_UID:-1000} - PDO_INTERPRETER: ${PDO_INTERPRETER:-wawaka} - PDO_LEDGER_TYPE: ccf - PDO_HOSTNAME: ${PDO_HOSTNAME} - PDO_LEDGER_URL: ${PDO_LEDGER_URL} - PDO_LOG_LEVEL: ${PDO_LOG_LEVEL:-info} - PDO_DEBUG_BUILD: ${PDO_DEBUG_BUILD:-0} + image: pdo_client:${PDO_VERSION:-latest} + # build containers only via Makefile and directly via docker build + # as we use containers also outside of docker-compose to prevent depends_on: - ccf_container - services_container diff --git a/docker/pdo_ccf.dockerfile b/docker/pdo_ccf.dockerfile index 6a1ee6b2..00a3c70f 100644 --- a/docker/pdo_ccf.dockerfile +++ b/docker/pdo_ccf.dockerfile @@ -20,9 +20,9 @@ FROM pdo_ccf_base:${PDO_VERSION} # ----------------------------------------------------------------- # set up the PDO sources # ----------------------------------------------------------------- -ARG REBUILD 0 +ARG REBUILD=0 -ARG SGX_MODE SIM +ARG SGX_MODE=SIM ENV SGX_MODE=$SGX_MODE ARG PDO_DEBUG_BUILD=0 @@ -49,13 +49,6 @@ RUN /project/pdo/tools/build_ccf.sh # Network ports for running services EXPOSE 6600 -ARG PDO_HOSTNAME -ENV PDO_HOSTNAME=$PDO_HOSTNAME - -ARG PDO_LEDGER_URL -ENV PDO_LEDGER_URL=$PDO_LEDGER_URL - -# Note that the entry point when specified with exec syntax # can be extended through the docker run interface far more # easily than if you use the other specification format of # a single string diff --git a/docker/pdo_ccf_base.dockerfile b/docker/pdo_ccf_base.dockerfile index 5eabdc31..46a80203 100644 --- a/docker/pdo_ccf_base.dockerfile +++ b/docker/pdo_ccf_base.dockerfile @@ -39,7 +39,8 @@ RUN apt-get update \ python3-virtualenv \ virtualenv \ net-tools \ - wget + wget \ + ${ADD_APT_PKGS} RUN echo "deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu ${UBUNTU_NAME} main" >> /etc/apt/sources.list RUN curl https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | apt-key add - diff --git a/docker/pdo_client.bashrc b/docker/pdo_client.bashrc new file mode 100644 index 00000000..ea5288e5 --- /dev/null +++ b/docker/pdo_client.bashrc @@ -0,0 +1,5 @@ +/usr/bin/echo -e "\ +NOTE: to setup environment, \"source /project/pdo/tools/start_client.sh\"\n\ + with the arguments \"--mode build\" to build a new client environment (default mode)\n\ + or \"--mode copy\" to copy one from the xfer directory" + diff --git a/docker/pdo_client.dockerfile b/docker/pdo_client.dockerfile index c8bb7f17..cde95e51 100644 --- a/docker/pdo_client.dockerfile +++ b/docker/pdo_client.dockerfile @@ -35,7 +35,7 @@ USER $UNAME # ----------------------------------------------------------------- # set up the PDO sources # ----------------------------------------------------------------- -ARG REBUILD 0 +ARG REBUILD=0 ARG PDO_DEBUG_BUILD=0 ENV PDO_DEBUG_BUILD=${PDO_DEBUG_BUILD} @@ -65,13 +65,5 @@ COPY --chown=${UNAME}:${UNAME} tools/*.sh ./ # build it!!! RUN /project/pdo/tools/build_client.sh -ARG PDO_HOSTNAME -ENV PDO_HOSTNAME=$PDO_HOSTNAME - -ARG PDO_LEDGER_URL -ENV PDO_LEDGER_URL=$PDO_LEDGER_URL - -# the client is set up for interactive access; the environment can be -# set up by source /project/pdo/tools/start_client.sh with the arguments -# to build a new client environment or copy one from the xfer directory +COPY --chown=${UNAME}:${UNAME} pdo_client.bashrc /project/pdo/.bashrc ENTRYPOINT [ "/bin/bash" ] diff --git a/docker/pdo_services.dockerfile b/docker/pdo_services.dockerfile index 73710765..1d93ba85 100644 --- a/docker/pdo_services.dockerfile +++ b/docker/pdo_services.dockerfile @@ -20,7 +20,7 @@ FROM pdo_services_base:${PDO_VERSION} # ----------------------------------------------------------------- # set up the PDO sources # ----------------------------------------------------------------- -ARG REBUILD 0 +ARG REBUILD=0 ARG PDO_DEBUG_BUILD=0 ENV PDO_DEBUG_BUILD=${PDO_DEBUG_BUILD} @@ -55,11 +55,6 @@ EXPOSE 7001 7002 7003 7004 7005 EXPOSE 7101 7102 7103 7104 7105 EXPOSE 7201 7202 7203 7204 7205 -ARG PDO_HOSTNAME -ENV PDO_HOSTNAME=$PDO_HOSTNAME - -ARG PDO_LEDGER_URL -ENV PDO_LEDGER_URL=$PDO_LEDGER_URL # Note that the entry point when specified with exec syntax # can be extended through the docker run interface far more diff --git a/docker/services_base.yaml b/docker/services_base.yaml index 72c619e2..6ec5f99d 100644 --- a/docker/services_base.yaml +++ b/docker/services_base.yaml @@ -17,18 +17,9 @@ version: "3.4" services: services_container: - image: pdo_services - build: - context: . - dockerfile: pdo_services.dockerfile - args: - PDO_INTERPRETER: ${PDO_INTERPRETER:-wawaka} - PDO_HOSTNAME: ${PDO_HOSTNAME} - PDO_LEDGER_TYPE: ccf - PDO_LEDGER_URL: ${PDO_LEDGER_URL} - SGX_MODE: ${SGX_MODE:-SIM} - PDO_LOG_LEVEL: ${PDO_LOG_LEVEL:-info} - PDO_DEBUG_BUILD: ${PDO_DEBUG_BUILD:-0} + image: pdo_services:${PDO_VERSION:-latest} + # build containers only via Makefile and directly via docker build + # as we use containers also outside of docker-compose to prevent container_name: services_container network_mode: "host" depends_on: diff --git a/docker/test.yaml b/docker/test.yaml index 8eab36f8..27640b03 100644 --- a/docker/test.yaml +++ b/docker/test.yaml @@ -16,29 +16,23 @@ version: "3.4" services: ccf_container: - build: - args: - PDO_VERSION: ${PDO_VERSION} - PDO_HOSTNAME: localhost - PDO_LEDGER_URL: http://localhost:6600 + environment: + - PDO_VERSION=${PDO_VERSION} + - PDO_HOSTNAME=localhost entrypoint: /project/pdo/tools/run_ccf_tests.sh services_container: - build: - args: - PDO_VERSION: ${PDO_VERSION} - PDO_HOSTNAME: localhost - PDO_LEDGER_URL: http://localhost:6600 - PDO_LOG_LEVEL: ${PDO_LOG_LEVEL:-info} - PDO_DEBUG_BUILD: ${PDO_DEBUG_BUILD:-0} + environment: + - PDO_VERSION=${PDO_VERSION} + - PDO_HOSTNAME=localhost + - PDO_LOG_LEVEL=${PDO_LOG_LEVEL:-info} + - PDO_DEBUG_BUILD=${PDO_DEBUG_BUILD:-0} entrypoint: /project/pdo/tools/run_services_tests.sh client_container: - build: - args: - PDO_VERSION: ${PDO_VERSION} - PDO_HOSTNAME: localhost - PDO_LEDGER_URL: http://localhost:6600 - PDO_LOG_LEVEL: ${PDO_LOG_LEVEL:-info} - PDO_DEBUG_BUILD: ${PDO_DEBUG_BUILD:-0} + environment: + - PDO_VERSION=${PDO_VERSION} + - PDO_HOSTNAME=localhost + - PDO_LOG_LEVEL=${PDO_LOG_LEVEL:-info} + - PDO_DEBUG_BUILD=${PDO_DEBUG_BUILD:-0} entrypoint: /project/pdo/tools/run_client_tests.sh