<commit_before>#######################################
# VARIABLES
#
# Set these at runtime to override the below defaults.
# e.g.:
# `make DOCKER_OPTS_CMD=/bin/bash console`
# `make USERNAME=root DOCKER_OPTS_CMD=/bin/bash run`
# `make AIRSTACK_IMAGE_TAG=debug build`
#######################################

# Uncomment when debugging Makefile
# SHELL = sh -xv

TOP_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
CURR_DIR := $(notdir $(patsubst %/,%,$(dir $(TOP_DIR))))
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
USERNAME := airstack
USERDIR := $(USERNAME)

AIRSTACK_TEMPLATES_FILES := Dockerfile.core Dockerfile.packages Dockerfile.packages.dev Dockerfile.services Dockerfile.debug Dockerfile.tests
AIRSTACK_TEMPLATES_DIR := build/templates
AIRSTACK_CACHE_DIR := build/cache
AIRSTACK_IMAGE_REPO := airstack
AIRSTACK_IMAGE_NAME := $(shell cat $(TOP_DIR)/env/AIRSTACK_IMAGE_NAME)
AIRSTACK_IMAGE_TAG := latest
AIRSTACK_IMAGE_FULLNAME := $(AIRSTACK_IMAGE_REPO)/$(AIRSTACK_IMAGE_NAME):$(AIRSTACK_IMAGE_TAG)

DOCKER_OPTS_CMD := sh -c "{ /etc/runit/2 &}; chpst -u $(USERNAME) bash"
DOCKER_OPTS_USER := --user $(USERNAME)
DOCKER_OPTS_USER_CONSOLE := --user root
DOCKER_OPTS_RUN := --detach
DOCKER_OPTS_RUN_CONSOLE := --rm -it
DOCKER_OPTS_BUILD := --rm
DOCKER_OPTS_COMMON := --publish-all --workdir /home/$(USERDIR) -e HOME=$(USERDIR) $(AIRSTACK_IMAGE_FULLNAME)
DOCKER_OPTS_LINUX := --volume $(CURR_DIR)/:/files/host/
DOCKER_OPTS_OSX := --volume $(ROOTDIR)/:/files/host/

ifeq ($(uname_S),Darwin)
	OS_SPECIFIC_RUNOPTS := $(DOCKER_OPTS_OSX)
else
	OS_SPECIFIC_RUNOPTS := $(DOCKER_OPTS_LINUX)
endif

# .PHONY should include all commands. Arrange in order that they appear in the Makefile
.PHONY: default all init \
	build build-all debug build-debug build-dev build-prod \
	clean clean-all clean-dev clean-prod \
	console console-debug console-dev console-prod \
	console-single console-single-dev console-single-prod \
	run run-debug run-dev run-prod \
	repair stats ps blank ssh \
	test test-all test-dev test-prod


################################################################################
# GENERAL COMMANDS
################################################################################

default: build

all:
	@echo all
	make build

init:
	@echo init
	# empty template files
	$(foreach var,$(AIRSTACK_TEMPLATES_FILES),$(shell [ -e $(AIRSTACK_TEMPLATES_DIR)/$(var) ] ||  touch $(AIRSTACK_TEMPLATES_DIR)/$(var) ]))
	# default .airstackignore file
	@[ -e $(TOP_DIR).airstackignore ] || printf ".git\n.gitignore\n.dockerignore\n.airstackignore\n.DS_Store\nbuild/cache/*.tar*\n_wip" > $(TOP_DIR).airstackignore
	@[ -d $(TOP_DIR)$(AIRSTACK_CACHE_DIR) ] || mkdir -vp $(TOP_DIR)$(AIRSTACK_CACHE_DIR)
ifeq ($(uname_S),Darwin)
ifneq ($(shell boot2docker status),running)
	@boot2docker up
endif
export AIRSTACK_HOST=tcp://$(shell boot2docker ip 2>/dev/null):2375
endif

################################################################################
# BUILD COMMANDS
#
# Commands for building containers.
################################################################################

build-all: build build-dev build-prod

build: init
	> $(AIRSTACK_CACHE_DIR)/Dockerfile.$(AIRSTACK_IMAGE_TAG)
	$(foreach var,$(AIRSTACK_TEMPLATES_FILES),cat $(AIRSTACK_TEMPLATES_DIR)/$(var) >> $(AIRSTACK_CACHE_DIR)/Dockerfile.$(AIRSTACK_IMAGE_TAG);)
	ln -f $(AIRSTACK_CACHE_DIR)/Dockerfile.$(AIRSTACK_IMAGE_TAG) Dockerfile && \
	tar -zcvf $(TOP_DIR)build/cache/$(AIRSTACK_IMAGE_NAME).$(AIRSTACK_IMAGE_TAG).tar.gz -C $(TOP_DIR) -X .airstackignore . && \
	docker build $(DOCKER_OPTS_BUILD) --tag airstack/$(AIRSTACK_IMAGE_NAME):$(AIRSTACK_IMAGE_TAG) - < $(TOP_DIR)build/cache/$(AIRSTACK_IMAGE_NAME).$(AIRSTACK_IMAGE_TAG).tar.gz

build-debug:
	make DOCKER_OPTS_BUILD='--rm --no-cache' build

build-dev:
	make AIRSTACK_IMAGE_TAG=dev build

build-prod:
	make AIRSTACK_IMAGE_TAG=prod AIRSTACK_TEMPLATES_FILES="Dockerfile.core Dockerfile.packages Dockerfile.services Dockerfile.debug Dockerfile.tests" build

build-help:<commit_msg>Add build-tarball and build-tarball-docker<commit_after>#######################################
# VARIABLES
#
# Set these at runtime to override the below defaults.
# e.g.:
# `make DOCKER_OPTS_CMD=/bin/bash console`
# `make USERNAME=root DOCKER_OPTS_CMD=/bin/bash run`
# `make AIRSTACK_IMAGE_TAG=debug build`
#######################################

# Uncomment when debugging Makefile
# SHELL = sh -xv

TOP_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
CURR_DIR := $(notdir $(patsubst %/,%,$(dir $(TOP_DIR))))
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
USERNAME := airstack
USERDIR := $(USERNAME)

AIRSTACK_AIRSTACKIGNORE := .airstackignore
AIRSTACK_TEMPLATES_FILES := Dockerfile.core Dockerfile.packages Dockerfile.packages.dev Dockerfile.services Dockerfile.debug Dockerfile.tests
AIRSTACK_TEMPLATES_DIR := build/templates
AIRSTACK_CACHE_DIR := build/cache
AIRSTACK_IMAGE_REPO := airstack
AIRSTACK_IMAGE_NAME := $(shell cat $(TOP_DIR)/env/AIRSTACK_IMAGE_NAME)
AIRSTACK_IMAGE_TAG := latest
AIRSTACK_IMAGE_FULLNAME := $(AIRSTACK_IMAGE_REPO)/$(AIRSTACK_IMAGE_NAME):$(AIRSTACK_IMAGE_TAG)

DOCKER_OPTS_CMD := sh -c "{ /etc/runit/2 &}; chpst -u $(USERNAME) bash"
DOCKER_OPTS_USER := --user $(USERNAME)
DOCKER_OPTS_USER_CONSOLE := --user root
DOCKER_OPTS_RUN := --detach
DOCKER_OPTS_RUN_CONSOLE := --rm -it
DOCKER_OPTS_BUILD := --rm
DOCKER_OPTS_COMMON := --publish-all --workdir /home/$(USERDIR) -e HOME=$(USERDIR) $(AIRSTACK_IMAGE_FULLNAME)
DOCKER_OPTS_LINUX := --volume $(CURR_DIR)/:/files/host/
DOCKER_OPTS_OSX := --volume $(ROOTDIR)/:/files/host/

ifeq ($(uname_S),Darwin)
	OS_SPECIFIC_RUNOPTS := $(DOCKER_OPTS_OSX)
else
	OS_SPECIFIC_RUNOPTS := $(DOCKER_OPTS_LINUX)
endif

# .PHONY should include all commands. Arrange in order that they appear in the Makefile
.PHONY: default all init \
	build build-all debug build-debug build-dev build-prod \
	clean clean-all clean-dev clean-prod \
	console console-debug console-dev console-prod \
	console-single console-single-dev console-single-prod \
	run run-debug run-dev run-prod \
	repair stats ps blank ssh \
	test test-all test-dev test-prod


################################################################################
# GENERAL COMMANDS
################################################################################

default: build

all:
	@echo all
	make build

init:
	@echo init
	# empty template files
	$(foreach var,$(AIRSTACK_TEMPLATES_FILES),$(shell [ -e $(AIRSTACK_TEMPLATES_DIR)/$(var) ] ||  touch $(AIRSTACK_TEMPLATES_DIR)/$(var) ]))
	# default .airstackignore file
	@[ -e $(TOP_DIR).airstackignore ] || printf ".git\n.gitignore\n.dockerignore\n.airstackignore\n.DS_Store\nbuild/cache/*.tar*\n_wip" > $(TOP_DIR).airstackignore
	@[ -d $(TOP_DIR)$(AIRSTACK_CACHE_DIR) ] || mkdir -vp $(TOP_DIR)$(AIRSTACK_CACHE_DIR)
ifeq ($(uname_S),Darwin)
ifneq ($(shell boot2docker status),running)
	@boot2docker up
endif
export AIRSTACK_HOST=tcp://$(shell boot2docker ip 2>/dev/null):2375
endif

################################################################################
# BUILD COMMANDS
#
# Commands for building containers.
################################################################################

build-all: build build-dev build-prod

build-tarball:
	tar -cvf $(TOP_DIR)build/cache/$(AIRSTACK_IMAGE_NAME).$(AIRSTACK_IMAGE_TAG).tar -C $(TOP_DIR) -X $(AIRSTACK_AIRSTACKIGNORE) .

build-tarball-docker: build-tarball
	> $(AIRSTACK_CACHE_DIR)/Dockerfile.$(AIRSTACK_IMAGE_TAG)
	$(foreach var,$(AIRSTACK_TEMPLATES_FILES),cat $(AIRSTACK_TEMPLATES_DIR)/$(var) >> $(AIRSTACK_CACHE_DIR)/Dockerfile.$(AIRSTACK_IMAGE_TAG);)
	ln -f $(AIRSTACK_CACHE_DIR)/Dockerfile.$(AIRSTACK_IMAGE_TAG) $(AIRSTACK_CACHE_DIR)/Dockerfile
	tar -C $(TOP_DIR)/$(AIRSTACK_CACHE_DIR) --append --file=$(AIRSTACK_IMAGE_TAG).tar Dockerfile

build-docker: init build-tarball-docker
	docker build $(DOCKER_OPTS_BUILD) --tag airstack/$(AIRSTACK_IMAGE_NAME):$(AIRSTACK_IMAGE_TAG) - < $(TOP_DIR)build/cache/$(AIRSTACK_IMAGE_NAME).$(AIRSTACK_IMAGE_TAG).tar

build: build-docker
# build: init
# 	> $(AIRSTACK_CACHE_DIR)/Dockerfile.$(AIRSTACK_IMAGE_TAG)
# 	$(foreach var,$(AIRSTACK_TEMPLATES_FILES),cat $(AIRSTACK_TEMPLATES_DIR)/$(var) >> $(AIRSTACK_CACHE_DIR)/Dockerfile.$(AIRSTACK_IMAGE_TAG);)
# 	ln -f $(AIRSTACK_CACHE_DIR)/Dockerfile.$(AIRSTACK_IMAGE_TAG) Dockerfile && \
# 	tar -zcvf $(TOP_DIR)build/cache/$(AIRSTACK_IMAGE_NAME).$(AIRSTACK_IMAGE_TAG).tar.gz -C $(TOP_DIR) -X $(AIRSTACK_AIRSTACKIGNORE) . && \
# 	docker build $(DOCKER_OPTS_BUILD) --tag airstack/$(AIRSTACK_IMAGE_NAME):$(AIRSTACK_IMAGE_TAG) - < $(TOP_DIR)build/cache/$(AIRSTACK_IMAGE_NAME).$(AIRSTACK_IMAGE_TAG).tar.gz

build-debug:
	make DOCKER_OPTS_BUILD='--rm --no-cache' build

build-dev:
	make AIRSTACK_IMAGE_TAG=dev build

build-prod:
	make AIRSTACK_IMAGE_TAG=prod AIRSTACK_TEMPLATES_FILES="Dockerfile.core Dockerfile.packages Dockerfile.services Dockerfile.debug Dockerfile.tests" build

build-help:
{'fraction_non_alphanumeric': 0.21941682493576137, 'fraction_numerical': 0.0022343872193051058, 'mean_word_length': 6.422885572139304, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '27054', 'n_tokens_mistral': 3406, 'n_tokens_neox': 3152, 'n_words': 570}