2021-05-06 20:56:34 +00:00
|
|
|
.SHELL := /bin/bash
|
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
|
2020-09-11 17:46:23 +00:00
|
|
|
|
2020-06-01 21:46:06 +00:00
|
|
|
assets := package.json yarn.lock $(shell find app/assets/ app/javascript/ -type f)
|
|
|
|
|
2021-04-26 16:04:55 +00:00
|
|
|
alpine_version := 3.13
|
|
|
|
hain ?= ../haini.sh/haini.sh
|
|
|
|
|
2021-05-19 20:55:55 +00:00
|
|
|
env ?= staging
|
|
|
|
|
|
|
|
ifeq ($(env),production)
|
|
|
|
container ?= sutty
|
|
|
|
branch ?= rails
|
|
|
|
public ?= public
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(env),staging)
|
|
|
|
container := staging
|
|
|
|
branch := staging
|
|
|
|
public := staging
|
|
|
|
endif
|
|
|
|
|
2021-04-26 16:04:55 +00:00
|
|
|
export
|
2020-10-08 18:15:50 +00:00
|
|
|
|
2021-02-11 21:08:55 +00:00
|
|
|
public/packs/manifest.json.br: $(assets)
|
2021-04-26 16:04:55 +00:00
|
|
|
$(hain) 'cd /Sutty/sutty; PANEL_URL=https://panel.sutty.nl RAILS_ENV=production NODE_ENV=production bundle exec rake assets:precompile assets:clean'
|
2020-06-01 21:46:06 +00:00
|
|
|
|
2021-02-11 21:08:55 +00:00
|
|
|
assets: public/packs/manifest.json.br
|
2020-06-01 21:46:06 +00:00
|
|
|
|
2021-06-26 23:34:53 +00:00
|
|
|
tests := $(shell find test/ -name "*_test.rb")
|
|
|
|
$(tests): always
|
2021-04-27 14:31:57 +00:00
|
|
|
$(hain) 'cd /Sutty/sutty; bundle exec rake test TEST="$@" RAILS_ENV=test'
|
|
|
|
|
|
|
|
test: always
|
2021-05-06 21:11:10 +00:00
|
|
|
$(hain) 'cd /Sutty/sutty; RAILS_ENV=test bundle exec rake test'
|
2021-04-27 14:31:57 +00:00
|
|
|
|
2021-06-08 17:36:48 +00:00
|
|
|
postgresql: /etc/hosts
|
|
|
|
pgrep postgres >/dev/null || $(hain) postgresql
|
|
|
|
|
|
|
|
serve: /etc/hosts postgresql
|
|
|
|
$(MAKE) rails args=server
|
2020-02-06 16:18:10 +00:00
|
|
|
|
2021-05-06 18:19:34 +00:00
|
|
|
# make rails args="db:migrate"
|
|
|
|
rails:
|
2021-05-17 16:14:57 +00:00
|
|
|
$(MAKE) bundle args="exec rails $(args)"
|
2021-05-06 18:19:34 +00:00
|
|
|
|
|
|
|
rake:
|
2021-05-17 16:14:57 +00:00
|
|
|
$(MAKE) bundle args="exec rake $(args)"
|
|
|
|
|
|
|
|
bundle:
|
|
|
|
$(hain) 'cd /Sutty/sutty; bundle $(args)'
|
2021-05-06 18:19:34 +00:00
|
|
|
|
2021-06-16 15:08:05 +00:00
|
|
|
yarn:
|
|
|
|
$(hain) 'yarn $(args)'
|
2021-05-06 18:19:34 +00:00
|
|
|
|
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
|
2021-04-26 16:04:55 +00:00
|
|
|
$(hain) 'cd /Sutty/sutty; bundle exec ./bin/webpack-dev-server'
|
2021-02-10 16:21:19 +00:00
|
|
|
|
2019-09-18 18:47:43 +00:00
|
|
|
# Limpiar los archivos de testeo
|
|
|
|
clean:
|
|
|
|
rm -rf _sites/test-* _deploy/test-*
|
|
|
|
|
|
|
|
# Generar la imagen Docker
|
2020-06-01 21:46:06 +00:00
|
|
|
build: assets
|
2021-05-19 20:55:55 +00:00
|
|
|
time docker build --build-arg="BRANCH=$(branch)" --build-arg="RAILS_MASTER_KEY=`cat config/master.key`" -t sutty/$(container) .
|
|
|
|
docker tag sutty/$(container):latest sutty:keep
|
2019-09-18 18:47:43 +00:00
|
|
|
|
2019-11-16 23:13:30 +00:00
|
|
|
save:
|
2021-05-19 20:55:55 +00:00
|
|
|
time docker save sutty/$(container):latest | ssh root@$(delegate).sutty.nl docker load
|
|
|
|
date +%F | xargs -I {} git tag -f $(container)-{}
|
2020-12-07 18:43:09 +00:00
|
|
|
@echo -e "\a"
|
2019-11-16 23:13:30 +00:00
|
|
|
|
2021-05-06 20:56:34 +00:00
|
|
|
# proyectos.
|
2019-09-18 18:47:43 +00:00
|
|
|
../gems/:
|
|
|
|
mkdir -p $@
|
|
|
|
|
2021-05-06 20:56:34 +00:00
|
|
|
# Crear el directorio donde se almacenan las gemas binarias
|
|
|
|
# TODO: Mover a un proyecto propio, porque lo utilizamos en todos los
|
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)
|
2020-10-08 18:15:50 +00:00
|
|
|
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))
|
2020-02-06 17:18:14 +00:00
|
|
|
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:
|
2020-10-08 18:15:50 +00:00
|
|
|
@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) \
|
2020-10-08 18:15:50 +00:00
|
|
|
-e GEM=`echo $(notdir $*) | sed -re "s/-[^-]+$$//"` \
|
|
|
|
-e VERSION=`echo $(notdir $*) | sed -re "s/.*-([^-]+)$$/\1/"` \
|
2020-06-01 21:46:06 +00:00
|
|
|
-e JOBS=2 \
|
2020-10-08 18:15:50 +00:00
|
|
|
--rm -it \
|
|
|
|
sutty/gem-compiler:latest || echo "No se pudo compilar $*"
|
2020-06-01 21:46:06 +00:00
|
|
|
|
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
|
2020-10-08 18:15:50 +00:00
|
|
|
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-02-26 13:22:30 +00:00
|
|
|
ota: assets
|
|
|
|
sudo chgrp -R 82 public/
|
2021-05-19 20:55:55 +00:00
|
|
|
rsync -avi --delete-after public/ $(delegate):/srv/sutty/srv/http/data/_$(public)/
|
2021-06-22 01:31:48 +00:00
|
|
|
rsync -avi --delete-after public/ $(delegate):/srv/sutty/srv/http/data/_public/_staging/
|
2021-05-19 20:55:55 +00:00
|
|
|
ssh $(delegate) docker exec $(container) sh -c "cat /srv/http/tmp/puma.pid | xargs -r kill -USR2"
|
2021-02-26 13:22:30 +00:00
|
|
|
|
2021-04-27 14:52:02 +00:00
|
|
|
# Hotfixes
|
2021-06-16 15:08:21 +00:00
|
|
|
#
|
|
|
|
# TODO: Reemplazar esto por git pull en el contenedor
|
2021-05-06 20:56:34 +00:00
|
|
|
commit ?= origin/rails
|
2021-04-27 14:52:02 +00:00
|
|
|
ota-rb:
|
|
|
|
umask 022; git format-patch $(commit)
|
2021-05-19 20:55:55 +00:00
|
|
|
scp ./0*.patch $(delegate):/tmp/
|
2021-06-16 15:08:21 +00:00
|
|
|
ssh $(delegate) mkdir -p /tmp/patches-$(commit)/
|
|
|
|
scp ./0*.patch $(delegate):/tmp/patches-$(commit)/
|
|
|
|
scp ./ota.sh $(delegate):/tmp/
|
2021-07-13 20:24:09 +00:00
|
|
|
ssh $(delegate) docker cp /tmp/patches-$(shell echo $(commit) | cut -d / -f 1) $(container):/tmp/
|
2021-06-16 15:08:21 +00:00
|
|
|
ssh $(delegate) docker cp /tmp/ota.sh $(container):/usr/local/bin/ota
|
|
|
|
ssh $(delegate) docker exec $(container) apk add --no-cache patch
|
|
|
|
ssh $(delegate) docker exec $(container) ota $(commit)
|
2021-04-27 14:52:02 +00:00
|
|
|
rm ./0*.patch
|
|
|
|
|
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 $@
|
2021-02-11 22:33:18 +00:00
|
|
|
@grep -q " api.$(SUTTY)$$" $@ || echo -e "127.0.0.1 api.$(SUTTY)\n::1 api.$(SUTTY)" | sudo tee -a $@
|
|
|
|
@grep -q " panel.$(SUTTY)$$" $@ || echo -e "127.0.0.1 panel.$(SUTTY)\n::1 panel.$(SUTTY)" | sudo tee -a $@
|
2021-06-08 17:36:48 +00:00
|
|
|
@grep -q " postgresql.$(SUTTY)$$" $@ || echo -e "127.0.0.1 postgresql.$(SUTTY)\n::1 postgresql.$(SUTTY)" | sudo tee -a $@
|
2021-01-09 17:25:41 +00:00
|
|
|
|
|
|
|
.PHONY: always
|