diff --git a/.env b/.env deleted file mode 100644 index e69de29..0000000 diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..df2788b --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +HAINISH=../haini.sh/haini.sh diff --git a/.gitignore b/.gitignore index e9a5701..bb9da80 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,5 @@ /yarn-error.log yarn-debug.log* .yarn-integrity + +.env diff --git a/Gemfile b/Gemfile index 01ba485..5e1ce79 100644 --- a/Gemfile +++ b/Gemfile @@ -29,6 +29,7 @@ group :development, :test do end group :development do + gem 'brakeman' # Access an interactive console on exception pages or by calling 'console' anywhere in the code. gem 'web-console', '>= 4.1.0' # Display performance information such as SQL time and flame graphs for each request in your browser. diff --git a/Gemfile.lock b/Gemfile.lock index 56bcb77..8d91652 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -66,6 +66,7 @@ GEM bindex (0.8.1-x86_64-linux-musl) bootsnap (1.7.5-x86_64-linux-musl) msgpack (~> 1.0) + brakeman (5.0.4) builder (3.2.4) byebug (11.1.3-x86_64-linux-musl) capybara (3.35.3) @@ -220,6 +221,7 @@ PLATFORMS DEPENDENCIES bootsnap (>= 1.4.4) + brakeman byebug capybara (>= 3.26) jbuilder (~> 2.7) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4ed6b4c --- /dev/null +++ b/Makefile @@ -0,0 +1,106 @@ +SHELL := /bin/bash +.DEFAULT_GOAL := help + +# Copiar el archivo de configuración y avisar cuando hay que +# actualizarlo. +.env: .env.example + @test -f $@ || cp -v $< $@ + @test -f $@ && echo "Revisa $@ para actualizarlo con respecto a $<" + @test -f $@ && diff -auN --color $@ $< + +include .env + +export + +# XXX: El espacio antes del comentario cuenta como espacio +args ?=## Argumentos para Hain +hain ?= $(HAINISH)## Ubicación de Hainish + +help: always ## Ayuda + @echo -e "Sutty\n" | sed -re "s/^.*/\x1B[38;5;197m&\x1B[0m/" + @echo -e "Servidor: https://panel.$(SUTTY_WITH_PORT)/\n" + @echo -e "Uso: make TAREA args=\"ARGUMENTOS\"\n" + @echo -e "Tareas:\n" + @grep -E "^[a-z\-]+:.*##" Makefile | sed -re "s/(.*):.*##(.*)/\1;\2/" | column -s ";" -t | sed -re "s/^([^ ]+) /\x1B[38;5;197m\1\x1B[0m/" + @echo -e "\nArgumentos:\n" + @grep -E "^[a-z\-]+ \?=.*##" Makefile | sed -re "s/(.*) \?=.*##(.*)/\1;\2/" | column -s ";" -t | sed -re "s/^([^ ]+) /\x1B[38;5;197m\1\x1B[0m/" + +assets: node_modules public/packs/manifest.json.br ## Compilar los assets + +test: always ## Ejecutar los tests + $(MAKE) rake args="test RAILS_ENV=test $(args)" + +postgresql: /etc/hosts ## Iniciar la base de datos + pgrep postgres >/dev/null || $(hain) postgresql + +serve-js: /etc/hosts node_modules ## Iniciar el servidor de desarrollo de Javascript + $(hain) 'bundle exec ./bin/webpack-dev-server' + +serve: /etc/hosts postgresql Gemfile.lock ## Iniciar el servidor de desarrollo de Rails + $(MAKE) rails args=server + +rails: ## Tareas de Rails + $(MAKE) bundle args="exec rails $(args)" + +rake: ## Tareas de Rake + $(MAKE) bundle args="exec rake $(args)" + +bundle: ## Tareas de bundler + $(hain) 'bundle $(args)' + +rubocop: ## Yutea el código que está por ser commiteado + git status --porcelain \ + | grep -E "^(A|M)" \ + | sed "s/^...//" \ + | grep ".rb$$" \ + | ../haini.sh/haini.sh "xargs -r ./bin/rubocop --auto-correct" + +audit: ## Encuentra dependencias con vulnerabilidades + $(hain) 'gem install bundler-audit' + $(hain) 'bundle audit --update' + +brakeman: ## Busca posibles vulnerabilidades en Sutty + $(MAKE) bundle args='exec brakeman' + +yarn: ## Tareas de yarn + $(hain) 'yarn $(args)' + +clean: ## Limpieza + rm -rf _sites/test-* _deploy/test-* log/*.log tmp/cache tmp/letter_opener tmp/miniprofiler tmp/storage + +build: Gemfile.lock ## Generar la imagen Docker + 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 + @echo -e "\a" + +save: ## Subir la imagen Docker al nodo delegado + time docker save sutty/$(container):latest | ssh root@$(delegate) docker load + date +%F | xargs -I {} git tag -f $(container)-{} + @echo -e "\a" + +# Todos los archivos de assets. Si alguno cambia, se van a recompilar +# los assets que luego se suben al nodo delegado. +assets := package.json yarn.lock $(shell find app/assets/ app/javascript/ -type f) +public/packs/manifest.json.br: $(assets) + $(hain) 'RAILS_ENV=production NODE_ENV=production bundle exec rake assets:precompile assets:clean' + +# Correr un test en particular por ejemplo +# `make test/models/usuarie_test.rb` +tests := $(shell find test/ -name "*_test.rb") +$(tests): always + $(MAKE) test args="TEST=$@" + +# Agrega las direcciones locales al sistema +/etc/hosts: always + @echo "Chequeando si es necesario agregar el dominio local $(SUTTY)" + @grep -q " postgresql.$(SUTTY)$$" $@ || echo -e "127.0.0.1 postgresql.$(SUTTY)\n::1 postgresql.$(SUTTY)" | sudo tee -a $@ + +# Instala las dependencias de Javascript +node_modules: package.json + $(MAKE) yarn + +# Instala las dependencias de Rails +Gemfile.lock: Gemfile + $(MAKE) bundle args=install + +.PHONY: always