Skip to content

Commit

Permalink
Port to OSX
Browse files Browse the repository at this point in the history
- Addapt how colors are handled in terminal
- Addapt how stat command is formatted
- Replace 'sed' with 'awk'
- Avoid UID hack on OSX

Signed-off-by: David Pordomingo <[email protected]>
  • Loading branch information
dpordomingo committed Jul 29, 2019
1 parent 3a4c99f commit 1eff7f6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
25 changes: 18 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ DOCKER_PASSWORD ?=
# will cause make docker-push to also push the latest tag.
DOCKER_PUSH_LATEST ?=

STAT := stat -c
LOGIN_USER := 0 # 'root' UID
ifeq ($(shell uname),Darwin)
STAT := stat -f
# In OSX there's no problem if the host user and the internal user are
# different when reading and accessing data trough docker volumes.
LOGIN_USER := superset
endif
SOURCED_UI_ABS_PATH := $(shell pwd)
LOCAL_USER := $(shell $(STAT) "%u" superset/superset)
export SOURCED_UI_ABS_PATH
export LOCAL_USER
export LOGIN_USER


# Build information
VERSION ?= latest
# Travis CI
Expand Down Expand Up @@ -55,22 +70,18 @@ apply-patch:
watch:
@DIRECTORY_TO_OBSERVE=$(PATCH_SOURCE_DIR) bash watcher

SOURCED_DIR_OWNER := `stat -c "%u" superset/superset`
# Writes the proper `docker-compose.override.yml` as the sourced global override file
.PHONY: set-override
set-override: $(OVERRIDE_BACKUP_PATH)
@sed \
-e "s~\$${SOURCED_UI_ABS_PATH}~`pwd`~" \
-e "s~\$${LOCAL_USER:-}~$(SOURCED_DIR_OWNER)~" \
$(OVERRIDE_TEMPLATE_PATH) > $(OVERRIDE_OUTPUT_PATH)
@awk '{ system("echo \""$$0"\"") }' $(OVERRIDE_TEMPLATE_PATH) > $(OVERRIDE_OUTPUT_PATH)

# Writes the proper `docker-compose.override.yml` as the sourced global override file
$(OVERRIDE_BACKUP_PATH):
@mkdir -p ~/.sourced/compose-files/__active__
@if [ -f "$(OVERRIDE_OUTPUT_PATH)" ]; then \
cp $(OVERRIDE_OUTPUT_PATH) $(OVERRIDE_BACKUP_PATH); \
else \
/bin/echo -e "\e[33mno docker-compose.override.yml to backup\e[0m"; \
echo "\033[33mno docker-compose.override.yml to backup\033[0m"; \
fi;

# Prepares the development enviroment with with hot reloading
Expand Down Expand Up @@ -124,7 +135,7 @@ clean:
@if [ -f "$(OVERRIDE_BACKUP_PATH)" ]; then \
mv $(OVERRIDE_BACKUP_PATH) $(OVERRIDE_OUTPUT_PATH); \
else \
/bin/echo -e "\e[33mno docker-compose.override.yml.bak to restore\e[0m"; \
echo "\033[33mno docker-compose.override.yml.bak to restore\033[0m"; \
fi;

# Add superset upstream remote if doesn't exists
Expand Down
6 changes: 1 addition & 5 deletions srcd/contrib/docker/docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
version: '3.2'
services:
sourced-ui:
# Set the user as root inside of the container to have permissions to change
# internal `superset` UID and GUID, and make it match the host user.
# It will grant write access to the data from the volumes,
# inside of the container and on host file system (see #221)
user: 0:0
user: ${LOGIN_USER:-superset}:${LOGIN_USER:-superset}
volumes:
- ${SOURCED_UI_ABS_PATH}/superset/superset:/home/superset/superset
- ${SOURCED_UI_ABS_PATH}/superset/dashboards:/home/superset/dashboards
Expand Down
10 changes: 5 additions & 5 deletions watcher
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ trap ctrl_c SIGINT

function ctrl_c {
make --no-print-directory clean && \
echo -e "\e[92mPatch cleaned\e[0m" || \
echo -e "\e[33mCould not clean patch\e[0m"
echo -e "\033[1;92mPatch cleaned\033[0m" || \
echo -e "\033[1;33mCould not clean patch\033[0m"
exit $?
}

Expand All @@ -29,11 +29,11 @@ elif command -v fswatch > /dev/null 2>&1; then
wichWatcher=fswatch
function watcher { watch_fswatch; }
else
echo -e "\e[31m[ERROR] No watcher available\e[0m"
echo -e "\033[1;31m[ERROR] No watcher available\033[0m"
echo "Neither 'inotify' nor 'fswatch' are available."
echo "You can follow 'CONTRIBUTING.md' guidelines to install one of them,"
echo ""
echo -e "\e[33m[alternative]\e[0m follow these steps:"
echo -e "\033[1;33m[alternative]\033[0m follow these steps:"
echo "1. run 'make set-override' first,"
echo "2. then 'make patch' every time you change a file in 'srcd' dir"
echo "3. and 'make clean' once you finish developing"
Expand All @@ -42,7 +42,7 @@ else
fi

make --no-print-directory apply-patch
echo -e "\e[92mWatching for changes in 'srcd'; using '${wichWatcher}' ...\e[0m"
echo -e "\033[1;92mWatching for changes in 'srcd'; using '${wichWatcher}' ...\033[0m"
while watcher; do
make --no-print-directory apply-patch
done

0 comments on commit 1eff7f6

Please sign in to comment.