From e4754b342b2725181b91ba8eb63cfe094bffa0bc Mon Sep 17 00:00:00 2001 From: f Date: Wed, 19 May 2021 17:55:55 -0300 Subject: [PATCH] =?UTF-8?q?trabajar=20con=20un=20entorno=20de=20pruebas=20?= =?UTF-8?q?que=20es=20igual=20a=20producci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- Dockerfile | 10 ++++------ Makefile | 27 +++++++++++++++++++++------ monit.conf | 4 ---- sync_assets.sh | 5 ----- 4 files changed, 25 insertions(+), 21 deletions(-) delete mode 100644 sync_assets.sh diff --git a/Dockerfile b/Dockerfile index 1aa97b16..3781772b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,8 +6,10 @@ FROM alpine:3.13.5 AS build MAINTAINER "f " ARG RAILS_MASTER_KEY +ARG BRANCH # Un entorno base +ENV BRANCH=$BRANCH ENV SECRET_KEY_BASE solo_es_necesaria_para_correr_rake ENV RAILS_ENV production ENV RAILS_MASTER_KEY=$RAILS_MASTER_KEY @@ -47,17 +49,16 @@ COPY --chown=app:www-data ./.git/ ./.git/ # Hacer un clon limpio del repositorio en lugar de copiar todos los # archivos RUN cd .. && git clone sutty checkout +RUN cd ../checkout && git checkout $BRANCH WORKDIR /home/app/checkout # Traer las gemas: +RUN rm -r ./vendor RUN mv ../sutty/vendor ./vendor RUN mv ../sutty/.bundle ./.bundle # Instalar secretos COPY --chown=app:root ./config/credentials.yml.enc ./config/ -# Traer los assets pre-compilados -COPY --chown=app:www-data ./public/assets ./public/assets -COPY --chown=app:www-data ./public/packs ./public/packs # Eliminar la necesidad de un runtime JS en producción, porque los # assets ya están pre-compilados. @@ -110,13 +111,10 @@ RUN rm -rf /srv/http/_sites /srv/http/_deploy RUN ln -s data/_storage /srv/http/_storage RUN ln -s data/_sites /srv/http/_sites RUN ln -s data/_deploy /srv/http/_deploy -RUN ln -s data/_public /srv/http/_public RUN ln -s data/_private /srv/http/_private # Volver a root para cerrar la compilación USER root -# Sincronizar los assets a un directorio compartido -RUN install -m 755 /srv/http/sync_assets.sh /usr/local/bin/sync_assets # Instalar la configuración de monit RUN install -m 640 -o root -g root /srv/http/monit.conf /etc/monit.d/sutty.conf RUN apk add --no-cache daemonize ruby-webrick diff --git a/Makefile b/Makefile index af466482..c7f4fd39 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,20 @@ assets := package.json yarn.lock $(shell find app/assets/ app/javascript/ -type 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) @@ -49,12 +63,12 @@ clean: # 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 + 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/sutty:latest | ssh root@$(delegate).sutty.nl docker load - date +%F | xargs git tag -f + 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. @@ -100,13 +114,14 @@ $(dirs): ota: assets sudo chgrp -R 82 public/ - rsync -avi --delete-after public/ athshe:/srv/sutty/srv/http/data/_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 root@athshe.sutty.nl:/tmp/ + scp ./0*.patch $(delegate):/tmp/ rm ./0*.patch /etc/hosts: always diff --git a/monit.conf b/monit.conf index b8c9e442..f574c56d 100644 --- a/monit.conf +++ b/monit.conf @@ -6,10 +6,6 @@ check process prometheus with pidfile /tmp/prometheus.pid start program = "/usr/local/bin/sutty prometheus" stop program = "/bin/sh -c 'cat /tmp/prometheus.pid | xargs kill'" -check program sync_assets - with path /usr/local/bin/sync_assets - if status = 0 then unmonitor - check program blazer_5m with path "/bin/sh -c 'cd /srv/http && foreman start blazer_5m'" as uid "app" and gid "www-data" diff --git a/sync_assets.sh b/sync_assets.sh deleted file mode 100644 index 1c1a6ca1..00000000 --- a/sync_assets.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -# Sincronizar assets desde public a _public para que estén disponibles -# en el contenedor web. - -rsync -a --delete-after /srv/http/public/ /srv/http/_public/