diff --git a/.env.dist b/.env.dist index 7b75bd5..456b0c1 100644 --- a/.env.dist +++ b/.env.dist @@ -1 +1,2 @@ -TAG_VERSION= \ No newline at end of file +BUILD_TAG= +REG_NS= #ghcr.io/vlizbe/vocabserver-app \ No newline at end of file diff --git a/.github/workflows/docker-images.yml b/.github/workflows/docker-images.yml index c3a8fc1..fd56198 100644 --- a/.github/workflows/docker-images.yml +++ b/.github/workflows/docker-images.yml @@ -38,11 +38,4 @@ jobs: fi echo $BUILD_TAG - - DIMGS="content-unification vocab-configs vocab-fetch" - cd services - for dimg in $DIMGS; do - echo "Building $REG_NS/$dimg:$BUILD_TAG" - docker build -t $REG_NS/$dimg:$BUILD_TAG -f $dimg/Dockerfile . - docker push $REG_NS/$dimg:$BUILD_TAG - done + make docker-push diff --git a/docker-compose.yml b/docker-compose.yml index 5ad928d..8d594f9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ x-logging: &default-logging max-file: "3" services: frontend: - image: ghcr.io/vlizbe/vocabserver-frontend:${TAG_VERSION} + image: ghcr.io/vlizbe/vocabserver-frontend:${BUILD_TAG} restart: always logging: *default-logging identifier: @@ -113,7 +113,7 @@ services: vocab-fetch: build: context: ./services/vocab-fetch - image: ghcr.io/vlizbe/vocabserver-app/vocab-fetch:${TAG_VERSION} + image: ${REG_NS:-vocabserver_app}/vocab-fetch:${BUILD_TAG} volumes: - ./data/vocab-fetch:/share # Run in dev mode to circument memory limitations @@ -126,7 +126,7 @@ services: content-unification: build: context: ./services/content-unification - image: ghcr.io/vlizbe/vocabserver-app/content-unification:${TAG_VERSION:-latest} + image: ${REG_NS:-vocabserver_app}/content-unification:${BUILD_TAG:-latest} volumes: - ./data/vocab-fetch:/share environment: @@ -144,7 +144,7 @@ services: restart: always logging: *default-logging webcomponent: - image: ghcr.io/vlizbe/vocabserver-webcomponent:${TAG_VERSION:-latest} + image: ghcr.io/vlizbe/vocabserver-webcomponent:${BUILD_TAG:-latest} ldes-consumer-manager: image: redpencil/ldes-consumer-manager:0.1.0 environment: @@ -157,7 +157,7 @@ services: vocab-configs: build: context: ./services/vocab-configs - image: ghcr.io/vlizbe/vocabserver-app/vocab-configs:${TAG_VERSION:-latest} + image: ${REG_NS:-vocabserver_app}/vocab-configs:${BUILD_TAG:-latest} environment: MU_APPLICATION_FILE_STORAGE_PATH: "vocab-configs/" MODE: "development" diff --git a/makefile b/makefile new file mode 100644 index 0000000..ec6f80f --- /dev/null +++ b/makefile @@ -0,0 +1,54 @@ +# Note: Ensure variable declarations in makefiles have NO trailing whitespace +# This can be achieved by sliding in the # comment-sign directly after the value + +include .env + +PROJECT := "vocabserver-app"# - this project +TIME_TAG := $(shell date +%s)# - the unix epoch +BUILD_TAG ?= ${TIME_TAG}# - provide the BUILD_TAG in the environment, or fallback to time +REG_NS ?= "vocabserver-app"# - allow the namespace to be overridden to e.g. ghcr.io/vlizbe/vocabserver-app +DIMGS="content-unification vocab-configs vocab-fetch"# - the list of docker images in docker-compose.yml ready to be pushed + +.PHONY: help docker-build docker-push docker-start docker-stop +.DEFAULT_GOAL := help + + +help: ## Shows this list of available targets and their effect. + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + + +# usage `make BUILD_TAG=0.2 docker-build` to include a specific tag to the build docker images +docker-build: ## Builds the docker-images as described in the local docker-compose.yml for ${REG_NS} and ${BUILD_TAG} + @echo "building all images as described in local docker-compose.yml for registry/namespace=${REG_NS} with tag=${BUILD_TAG}" + @env BUILD_TAG=${BUILD_TAG} REG_NS=${REG_NS} bash -c "docker compose build --no-cache" + + +# usage `make REG_NS=ghcr.io/vliz-be-opsci/kgap docker-build` to push images to github-container-registry +docker-push: docker-build ## Builds, then pushes the docker-images to ${REG_NS} + @echo "pushing docker images tagged=${BUILD_TAG} to registry/namespace=${REG_NS}" +ifeq ($(shell echo ${REG_NS} | egrep '.+/.+'),) # the 'shell' call is essential +# empty match indicates no registry-part is available to push to + @echo "not pushing docker images if no / between non-empty parts in REG_NS=${REG_NS}" + @exit 1 +else +# note the double $$ on dn distinction between makefile and shell var expansion + @for dn in "${DIMGS}"; do \ + docker push ${REG_NS}/${PROJECT}_$${dn}:${BUILD_TAG}; \ + done; +endif + + +docker-start: ## Launches local-named variants of the containers/images in docker-compose.yml + @echo "launching docker-stack for local test with default names and tags" + @mkdir -p ./data/ + @mkdir -p ./notebooks/ + @docker compose -p ${PROJECT} up -d + + +docker-stop: ## Stops local-named variants of those containers + @echo "shutting down docker-stack from docker-start" + @docker compose -p ${PROJECT} down + + +docker-clean: ## Helps (interactively) to cleanup containers and images linked to this project + @./docker_clean.sh ${PROJECT} \ No newline at end of file