sutty/Makefile

89 lines
3 KiB
Makefile
Raw Normal View History

2019-09-18 18:47:43 +00:00
# Incluir las variables de entorno
2019-10-16 17:56:49 +00:00
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
root_dir := $(patsubst %/,%,$(dir $(mkfile_path)))
include $(root_dir)/.env
2019-09-18 18:47:43 +00:00
2020-09-22 18:17:59 +00:00
delegate := athshe
assets := package.json yarn.lock $(shell find app/assets/ app/javascript/ -type f)
alpine_version := 3.12
public/packs/manifest.json.br: $(assets)
2020-12-07 18:43:09 +00:00
PANEL_URL=https://panel.sutty.nl RAILS_ENV=production NODE_ENV=production bundle exec rake assets:precompile assets:clean
assets: public/packs/manifest.json.br
2021-01-09 17:25:41 +00:00
serve: /etc/hosts
bundle exec rails s -b "ssl://0.0.0.0:3000?key=../sutty.local/domain/$(SUTTY).key&cert=../sutty.local/domain/$(SUTTY).crt"
2021-02-10 16:21:19 +00:00
# Servir JS con el dev server.
# Esto acelera la compilación del javascript, tiene que correrse por separado
# de serve.
serve-js: /etc/hosts
bundle exec ./bin/webpack-dev-server
2019-09-18 18:47:43 +00:00
# Limpiar los archivos de testeo
clean:
rm -rf _sites/test-* _deploy/test-*
# Generar la imagen Docker
build: assets
time docker build --build-arg="RAILS_MASTER_KEY=`cat config/master.key`" -t sutty/sutty .
2020-09-22 18:17:59 +00:00
docker tag sutty/sutty:latest sutty:keep
2019-09-18 18:47:43 +00:00
2019-11-16 23:13:30 +00:00
save:
time docker save sutty/sutty:latest | ssh root@$(delegate).sutty.nl docker load
2020-09-22 18:17:59 +00:00
date +%F | xargs git tag -f
2020-12-07 18:43:09 +00:00
@echo -e "\a"
2019-11-16 23:13:30 +00:00
load:
ssh root@sutty.nl sh -c "gunzip -c sutty.latest.gz | docker load"
2019-09-18 18:47:43 +00:00
# Crear el directorio donde se almacenan las gemas binarias
../gems/:
mkdir -p $@
2019-10-16 17:56:49 +00:00
gem_dir := $(shell readlink -f ../gems)
2021-01-05 15:01:19 +00:00
gem_cache_dir := $(gem_dir)/cache
gem_binary_dir := $(gem_dir)/$(alpine_version)
ifeq ($(MAKECMDGOALS),build-gems)
2021-01-05 15:01:19 +00:00
gems := $(shell bundle show --paths | xargs -I {} sh -c 'find {}/ext/ -name extconf.rb &>/dev/null && basename {}')
gems := $(patsubst %-x86_64-linux,%,$(gems))
gems := $(patsubst %,$(gem_cache_dir)/%.gem,$(gems))
gems_musl := $(patsubst $(gem_cache_dir)/%.gem,$(gem_binary_dir)/%-x86_64-linux-musl.gem,$(gems))
endif
2019-10-16 17:56:49 +00:00
2021-01-05 15:01:19 +00:00
$(gem_binary_dir)/%-x86_64-linux-musl.gem:
@docker run \
2019-10-16 17:56:49 +00:00
-v $(gem_dir):/srv/gems \
-v `readlink -f ~/.ccache`:/home/builder/.ccache \
-e HTTP_BASIC_USER=$(HTTP_BASIC_USER) \
-e HTTP_BASIC_PASSWORD=$(HTTP_BASIC_PASSWORD) \
-e GEM=`echo $(notdir $*) | sed -re "s/-[^-]+$$//"` \
-e VERSION=`echo $(notdir $*) | sed -re "s/.*-([^-]+)$$/\1/"` \
-e JOBS=2 \
--rm -it \
sutty/gem-compiler:latest || echo "No se pudo compilar $*"
2019-09-18 18:47:43 +00:00
# Compilar todas las gemas binarias y subirlas a gems.sutty.nl para que
# al crear el contenedor no tengamos que compilarlas cada vez
build-gems: $(gems_musl)
cached_gems = $(wildcard $(gem_dir)/cache/*.gem)
rebuild_gems = $(patsubst $(gem_dir)/cache/%.gem,$(gem_dir)/$(alpine_version)/%-x86_64-linux-musl.gem,$(cached_gems))
rebuild-gems: $(rebuild_gems)
2019-10-16 17:56:49 +00:00
dirs := $(patsubst %,root/%,data sites deploy public)
$(dirs):
mkdir -p $@
2021-01-09 17:25:41 +00:00
/etc/hosts: always
@echo "Chequeando si es necesario agregar el dominio local $(SUTTY)"
@grep -q " $(SUTTY)$$" $@ || echo -e "127.0.0.1 $(SUTTY)\n::1 $(SUTTY)" | sudo tee -a $@
@grep -q " api.$(SUTTY)$$" $@ || echo -e "127.0.0.1 api.$(SUTTY)\n::1 $(SUTTY)" | sudo tee -a $@
@grep -q " panel.$(SUTTY)$$" $@ || echo -e "127.0.0.1 panel.$(SUTTY)\n::1 $(SUTTY)" | sudo tee -a $@
.PHONY: always