Skip to content

Commit

Permalink
debug makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
fqjony committed Dec 23, 2024
1 parent afaaf5e commit 367a083
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
uses: docker/setup-buildx-action@v3

- name: Run Development Pipeline
# run: make dev-pipeline
run: MULTIPLATFORM=true make dev-pipeline
run: make dev-pipeline
# run: MULTIPLATFORM=true make dev-pipeline
working-directory: .
env:
AZURE_CREDS: ${{ secrets.AZURE_CREDS }}
Expand Down
37 changes: 28 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,35 @@ build:
# Run Docker container (supports interactive mode)
run: clean
@echo "Running Docker container..."
@docker run $(if $(INTERACTIVE),-it,-d) --rm --name $(CONTAINER_NAME) \
$(foreach file,$(wildcard *.json),\
$(eval CREDS_VAR_NAME=$(shell echo "$(file)" | sed -e 's/\.json//g' -e 's/\./_/g' | tr '[:lower:]' '[:upper:]')) \
$(eval CREDS_VAR_VALUE=$(shell cat "$(file)" | jq -c .)) \
-e $(CREDS_VAR_NAME)='$(CREDS_VAR_VALUE)' \
) \
$(foreach env_var,$(filter %_CREDS,$(.VARIABLES)),\
-e $(env_var)=$($(env_var)) \
) \

@echo "Detecting JSON credentials files..."
$(eval JSON_CREDS_ENV := $(shell \
for file in $(wildcard *.json); do \
CREDS_VAR_NAME=$$(echo "$${file}" | sed -e 's/\.json//g' -e 's/\./_/g' | tr '[:lower:]' '[:upper:]'); \
CREDS_VAR_VALUE=$$(cat "$${file}" | jq -c .); \
echo "-e $${CREDS_VAR_NAME}='$${CREDS_VAR_VALUE}'"; \
done \
))
@echo "JSON_CREDS_ENV: $(JSON_CREDS_ENV)"

@echo "Detecting host environment credentials..."
$(eval CREDS_ENV := $(shell bash -c '\
for env_var in $(filter %_CREDS,$(.VARIABLES)); do \
creds_value=$${!env_var}; \
echo "-e $${env_var}='$${creds_value}'"; \
done \
'))
@echo "CREDS_ENV: $(CREDS_ENV)"

@echo "Setting Docker volumes if any..."
$(eval DOCKER_VOLUMES := $(if $(VOLUMES),\
$(foreach vol,$(VOLUMES),-v $(vol)) \
))

@docker run $(if $(INTERACTIVE),-it,-d) --rm --name $(CONTAINER_NAME) \
$(JSON_CREDS_ENV) \
$(CREDS_ENV) \
$(DOCKER_VOLUMES) \
$(DOCKER_IMAGE) $(COMMAND)
$(if $(filter false,$(INTERACTIVE)),docker logs -f $(CONTAINER_NAME);)

Expand Down
4 changes: 0 additions & 4 deletions Makefile.help
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ HELP_LOG = "View the container logs:"
HELP_CLEAN = "Delete the running container:"
HELP_TEST = "Run the validation tests:"
HELP_DEV_PIPELINE = "Run the development pipeline:"
HELP_STRINGIFY_CREDS = "Stringify JSON credential files and set them as environment variables:"

# Help target
help:
@echo ""
@echo "Usage:"
@echo ""
@echo "$(HELP_STRINGIFY_CREDS)"
@echo "make stringify-creds"
@echo ""
@echo "$(HELP_BUILD)"
@echo "make build"
@echo ""
Expand Down

0 comments on commit 367a083

Please sign in to comment.