mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-25 16:16:22 +00:00
e4754b342b
al correr `make ota build save` se genera un entorno de staging en panel.staging.sutty.nl con los datos de los sitios y una copia de la base de datos. no copiamos los sitios porque les usuaries van a entrar a hacer pruebas en staging y esperar encontrar los cambios luego en producción. además usaría mucho almacenamiento hacer copias. al correr `make env=production ota build save` se realiza el mismo proceso para producción. los assets se alojan por fuera para que podamos actualizarlos sin tocar el contenedor y separar los de production de los de staging. estos cambios van en línea con ansible-sutty-deploy.
133 lines
4.1 KiB
Makefile
133 lines
4.1 KiB
Makefile
.SHELL := /bin/bash
|
|
# 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.13
|
|
hain ?= ../haini.sh/haini.sh
|
|
|
|
env ?= staging
|
|
|
|
ifeq ($(env),production)
|
|
container ?= sutty
|
|
branch ?= rails
|
|
public ?= public
|
|
endif
|
|
|
|
ifeq ($(env),staging)
|
|
container := staging
|
|
branch := staging
|
|
public := staging
|
|
endif
|
|
|
|
export
|
|
|
|
public/packs/manifest.json.br: $(assets)
|
|
$(hain) 'cd /Sutty/sutty; 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
|
|
|
|
test/%_test.rb: always
|
|
$(hain) 'cd /Sutty/sutty; bundle exec rake test TEST="$@" RAILS_ENV=test'
|
|
|
|
test: always
|
|
$(hain) 'cd /Sutty/sutty; RAILS_ENV=test bundle exec rake test'
|
|
|
|
serve: /etc/hosts
|
|
$(hain) 'cd /Sutty/sutty; bundle exec rails s -b "ssl://0.0.0.0:3000?key=../sutty.local/domain/$(SUTTY).key&cert=../sutty.local/domain/$(SUTTY).crt"'
|
|
|
|
# make rails args="db:migrate"
|
|
rails:
|
|
$(MAKE) bundle args="exec rails $(args)"
|
|
|
|
rake:
|
|
$(MAKE) bundle args="exec rake $(args)"
|
|
|
|
bundle:
|
|
$(hain) 'cd /Sutty/sutty; bundle $(args)'
|
|
|
|
# Servir JS con el dev server.
|
|
# Esto acelera la compilación del javascript, tiene que correrse por separado
|
|
# de serve.
|
|
serve-js: /etc/hosts
|
|
$(hain) 'cd /Sutty/sutty; bundle exec ./bin/webpack-dev-server'
|
|
|
|
# Limpiar los archivos de testeo
|
|
clean:
|
|
rm -rf _sites/test-* _deploy/test-*
|
|
|
|
# Generar la imagen Docker
|
|
build: assets
|
|
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
|
|
|
|
save:
|
|
time docker save sutty/$(container):latest | ssh root@$(delegate).sutty.nl docker load
|
|
date +%F | xargs -I {} git tag -f $(container)-{}
|
|
@echo -e "\a"
|
|
|
|
# proyectos.
|
|
../gems/:
|
|
mkdir -p $@
|
|
|
|
# Crear el directorio donde se almacenan las gemas binarias
|
|
# TODO: Mover a un proyecto propio, porque lo utilizamos en todos los
|
|
gem_dir := $(shell readlink -f ../gems)
|
|
gem_cache_dir := $(gem_dir)/cache
|
|
gem_binary_dir := $(gem_dir)/$(alpine_version)
|
|
ifeq ($(MAKECMDGOALS),build-gems)
|
|
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
|
|
|
|
$(gem_binary_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 $@
|
|
|
|
ota: assets
|
|
sudo chgrp -R 82 public/
|
|
rsync -avi --delete-after public/ $(delegate):/srv/sutty/srv/http/data/_$(public)/
|
|
ssh $(delegate) docker exec $(container) sh -c "cat /srv/http/tmp/puma.pid | xargs -r kill -USR2"
|
|
|
|
# Hotfixes
|
|
commit ?= origin/rails
|
|
ota-rb:
|
|
umask 022; git format-patch $(commit)
|
|
scp ./0*.patch $(delegate):/tmp/
|
|
rm ./0*.patch
|
|
|
|
/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 api.$(SUTTY)" | sudo tee -a $@
|
|
@grep -q " panel.$(SUTTY)$$" $@ || echo -e "127.0.0.1 panel.$(SUTTY)\n::1 panel.$(SUTTY)" | sudo tee -a $@
|
|
|
|
.PHONY: always
|