Skip to content

Commit

Permalink
Some minor docker(-compose) improvements
Browse files Browse the repository at this point in the history
- build only via docker (& make) and not also with docker-compose
- consistent tagging
- consistent support of ADD_APT_PKGS
- some additional stop/clean-up targets

Signed-off-by: g2flyer <[email protected]>
  • Loading branch information
g2flyer committed Jan 24, 2024
1 parent 1204450 commit af054f9
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 112 deletions.
69 changes: 41 additions & 28 deletions docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions docker/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 4 additions & 10 deletions docker/ccf_base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 3 additions & 13 deletions docker/client_base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 2 additions & 9 deletions docker/pdo_ccf.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion docker/pdo_ccf_base.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand Down
5 changes: 5 additions & 0 deletions docker/pdo_client.bashrc
Original file line number Diff line number Diff line change
@@ -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"

12 changes: 2 additions & 10 deletions docker/pdo_client.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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" ]
7 changes: 1 addition & 6 deletions docker/pdo_services.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down
15 changes: 3 additions & 12 deletions docker/services_base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
32 changes: 13 additions & 19 deletions docker/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit af054f9

Please sign in to comment.