# Incluir las variables de entorno mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) root_dir := $(patsubst %/,%,$(dir $(mkfile_path))) include $(root_dir)/.env delegate := athshe assets := package.json yarn.lock $(shell find app/assets/ app/javascript/ -type f) alpine_version := 3.12 public/assets-production/: $(assets) RAILS_ENV=production bundle exec rake assets:precompile assets:clean rsync --delete-after -a public/assets/ $@ public/packs-production/: public/packs/ rsync -a --delete-after $< $@ assets: public/assets-production/ public/packs-production/ serve: bundle exec rails s -b "ssl://0.0.0.0:3000?key=../sutty.local/domain/sutty.local.key&cert=../sutty.local/domain/sutty.local.crt" # 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 . docker tag sutty/sutty:latest sutty:keep save: time docker save sutty/sutty:latest | ssh root@$(delegate).sutty.nl docker load date +%F | xargs git tag -f load: ssh root@sutty.nl sh -c "gunzip -c sutty.latest.gz | docker load" # Crear el directorio donde se almacenan las gemas binarias ../gems/: mkdir -p $@ gem_dir := $(shell readlink -f ../gems) ifeq ($(MAKECMDGOALS),build-gems) gems := $(shell bundle show --paths | xargs -I {} sh -c 'test -f {}/ext/*/extconf.rb && basename {}') gems += $(shell bundle show --paths | xargs -I {} sh -c 'test -f {}/ext/extconf.rb && basename {}') gems := $(patsubst %,$(gem_dir)/cache/%.gem,$(gems)) gems_musl := $(patsubst $(gem_dir)/cache/%.gem,$(gem_dir)/$(alpine_version)/%-x86_64-linux-musl.gem,$(gems)) endif $(gem_dir)/%-x86_64-linux-musl.gem: @docker run \ -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 $*" # 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) dirs := $(patsubst %,root/%,data sites deploy public) $(dirs): mkdir -p $@ test-container: $(dirs) docker run -v $(PWD)/root/data:/srv/http/data \ -v $(PWD)/root/sites:/srv/http/_sites \ -v $(PWD)/root/deploy:/srv/http/_deploy \ -v $(PWD)/root/public:/srv/http/_public \ -v $(PWD)/config/credentials.yml.enc:/srv/http/config/credentials.yml.enc \ -e RAILS_MASTER_KEY=`cat config/master.key` \ -e RAILS_ENV=production \ -it \ --rm \ --name=sutty \ sutty/sutty /bin/sh