diff --git a/Gemfile b/Gemfile index cca5e1229..4706a64e0 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/ -source 'https://rubygems.org' +source 'https://gems.sutty.nl' # core - base ruby '2.7.4' diff --git a/Gemfile.lock b/Gemfile.lock index 9f1f07063..d977b6298 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,7 +17,7 @@ GIT mini_mime (>= 0.1.1) GEM - remote: https://rubygems.org/ + remote: https://gems.sutty.nl/ specs: PoParser (3.2.6) simple_po_parser (~> 1.1.6) @@ -95,6 +95,9 @@ GEM argon2 (2.1.1) ffi (~> 1.14) ffi-compiler (~> 1.0) + argon2 (2.1.1-x86_64-linux-musl) + ffi (~> 1.14) + ffi-compiler (~> 1.0) ast (2.4.2) autoprefixer-rails (10.4.2.0) execjs (~> 2) @@ -105,11 +108,14 @@ GEM tzinfo bootsnap (1.11.1) msgpack (~> 1.2) + bootsnap (1.11.1-x86_64-linux-musl) + msgpack (~> 1.2) brakeman (5.2.1) browser (5.3.1) buftok (0.2.0) builder (3.2.4) byebug (11.1.3) + byebug (11.1.3-x86_64-linux-musl) capybara (3.36.0) addressable matrix @@ -146,6 +152,7 @@ GEM daemons (1.4.1) dalli (3.2.1) debug_inspector (1.1.0) + debug_inspector (1.1.0-x86_64-linux-musl) delayed_job (4.1.10) activesupport (>= 3.0, < 8.0) delayed_job_active_record (4.1.7) @@ -171,6 +178,7 @@ GEM equalizer (0.0.11) erubi (1.10.0) eventmachine (1.2.7) + eventmachine (1.2.7-x86_64-linux-musl) execjs (2.8.1) factory_bot (6.2.1) activesupport (>= 5.0.0) @@ -205,6 +213,7 @@ GEM faraday_middleware (1.2.0) faraday (~> 1.0) ffi (1.15.5) + ffi (1.15.5-x86_64-linux-musl) ffi-compiler (1.0.1) ffi (>= 1.0.0) rake @@ -235,6 +244,7 @@ GEM hashdiff (1.0.1) hashie (5.0.0) hiredis (0.6.3) + hiredis (0.6.3-x86_64-linux-musl) htmlentities (4.3.4) http (4.4.1) addressable (~> 2.3) @@ -247,7 +257,10 @@ GEM http-form_data (2.3.0) http-parser (1.2.3) ffi-compiler (>= 1.0, < 2.0) + http-parser (1.2.3-x86_64-linux-musl) + ffi-compiler (>= 1.0, < 2.0) http_parser.rb (0.6.0) + http_parser.rb (0.6.0-x86_64-linux-musl) httpclient (2.8.3) i18n (1.10.0) concurrent-ruby (~> 1.0) @@ -261,14 +274,17 @@ GEM iniparse (1.5.0) interception (0.5) json (2.6.1) + json (2.6.1-x86_64-linux-musl) jwt (2.3.0) kgio (2.11.4) + kgio (2.11.4-x86_64-linux-musl) koala (3.1.0) addressable faraday (< 2) json (>= 1.8) rexml libv8 (8.4.255.0) + libv8 (8.4.255.0-x86_64-linux) listen (3.7.1) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) @@ -295,19 +311,25 @@ GEM libv8 (>= 6.9.411) minitest (5.15.0) msgpack (1.4.5) + msgpack (1.4.5-x86_64-linux-musl) multi_json (1.15.0) multi_xml (0.6.0) multipart-post (2.1.1) mysql2 (0.5.3) + mysql2 (0.5.3-x86_64-linux-musl) naught (1.1.0) nenv (0.3.0) nestful (1.1.4) net-ldap (0.17.0) netrc (0.11.0) nio4r (2.5.8) + nio4r (2.5.8-x86_64-linux-musl) nokogiri (1.13.4) mini_portile2 (~> 2.8.0) racc (~> 1.4) + nokogiri (1.13.4-x86_64-linux-musl) + mini_portile2 (~> 2.8.0) + racc (~> 1.4) nori (2.6.0) notiffany (0.1.3) nenv (~> 0.1) @@ -359,6 +381,7 @@ GEM omniauth (~> 1.5) omniauth-oauth2 (>= 1.4.0) openssl (3.0.0) + openssl (3.0.0-x86_64-linux-musl) overcommit (0.58.0) childprocess (>= 0.6.3, < 5) iniparse (~> 1.4) @@ -367,6 +390,7 @@ GEM parser (3.1.1.0) ast (~> 2.4.1) pg (0.21.0) + pg (0.21.0-x86_64-linux-musl) power_assert (2.0.1) pry (0.14.1) coderay (~> 1.1) @@ -385,11 +409,14 @@ GEM public_suffix (4.0.6) puma (4.3.12) nio4r (~> 2.0) + puma (4.3.12-x86_64-linux-musl) + nio4r (~> 2.0) pundit (2.2.0) activesupport (>= 3.0.0) pundit-matchers (1.7.0) rspec-rails (>= 3.0.0) racc (1.6.0) + racc (1.6.0-x86_64-linux-musl) rack (2.2.3) rack-livereload (0.3.17) rack @@ -427,6 +454,7 @@ GEM thor (>= 0.20.3, < 2.0) rainbow (3.1.1) raindrops (0.20.0) + raindrops (0.20.0-x86_64-linux-musl) rake (13.0.6) rb-fsevent (0.11.1) rb-inotify (0.10.1) @@ -458,6 +486,7 @@ GEM rspec-support (~> 3.10) rspec-support (3.11.0) rszr (0.5.2) + rszr (0.5.2-x86_64-linux-musl) rubocop (1.26.0) parallel (~> 1.10) parser (>= 3.1.0.0) @@ -494,6 +523,8 @@ GEM rubyzip (2.3.2) sassc (2.4.0) ffi (~> 1.9) + sassc (2.4.0-x86_64-linux-musl) + ffi (~> 1.9) sassc-rails (2.1.2) railties (>= 4.0.0) sassc (>= 2.0) @@ -556,10 +587,14 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.8) + unf_ext (0.0.8-x86_64-linux-musl) unicode-display_width (2.1.0) unicorn (6.1.0) kgio (~> 2.6) raindrops (~> 0.7) + unicorn (6.1.0-x86_64-linux-musl) + kgio (~> 2.6) + raindrops (~> 0.7) valid_email2 (4.0.3) activemodel (>= 3.2) mail (~> 2.5) @@ -575,6 +610,8 @@ GEM hashdiff (>= 0.4.0, < 2.0.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) + websocket-driver (0.7.5-x86_64-linux-musl) + websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) writeexcel (1.0.5) xpath (3.2.0) @@ -589,6 +626,7 @@ GEM PLATFORMS ruby + x86_64-linux-musl DEPENDENCIES PoParser @@ -700,7 +738,7 @@ DEPENDENCIES zendesk_api RUBY VERSION - ruby 2.7.4p191 + ruby 2.7.5p203 BUNDLED WITH 2.2.20 diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..36139d7a9 --- /dev/null +++ b/Makefile @@ -0,0 +1,149 @@ +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 +commit ?= origin/rails## Commit desde el que actualizar +env ?= staging## Entorno del nodo delegado +sutty ?= $(SUTTY)## Dirección local +delegate ?= $(DELEGATE)## Cambia el nodo delegado +hain ?= $(HAINISH)## Ubicación de Hainish + +# El nodo delegado tiene dos entornos, production y staging. +# Dependiendo del entorno que elijamos, se van a generar los assets y el +# contenedor y subirse a un servidor u otro. No utilizamos CI/CD (aún). +# +# Production es el entorno de panel.sutty.nl +ifeq ($(env),production) +container ?= sutty +## TODO: Cambiar a otra cosa +branch ?= rails +public ?= public +endif + +# Staging es el entorno de panel.staging.sutty.nl +ifeq ($(env),staging) +container := staging +branch := staging +public := staging +endif + +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: ## Corre rails dentro del entorno de desarrollo (pasar argumentos con args=). + $(MAKE) bundle args="exec rails $(args)" + +rake: ## Corre rake dentro del entorno de desarrollo (pasar argumentos con args=). + $(MAKE) bundle args="exec rake $(args)" + +bundle: ## Corre bundle dentro del entorno de desarrollo (pasar argumentos con args=). + $(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" + +ota-js: assets ## Actualizar Javascript en el nodo delegado + sudo chgrp -R 82 public/ + rsync -avi --delete-after public/ root@$(delegate):/srv/sutty/srv/http/data/_$(public)/ + ssh root@$(delegate) docker exec $(container) sh -c "cat /srv/http/tmp/puma.pid | xargs -r kill -USR2" + +ota: ## Actualizar Rails en el nodo delegado + umask 022; git format-patch $(commit) + scp ./0*.patch $(delegate):/tmp/ + ssh $(delegate) mkdir -p /tmp/patches-$(commit)/ + scp ./0*.patch $(delegate):/tmp/patches-$(commit)/ + scp ./ota.sh $(delegate):/tmp/ + ssh $(delegate) docker cp /tmp/patches-$(shell echo $(commit) | cut -d / -f 1) $(container):/tmp/ + 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) + rm ./0*.patch + +# 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) 'PANEL_URL=https://panel.sutty.nl 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 " $(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 $@ + @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