trabajar con un entorno de pruebas que es igual a producción

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.
This commit is contained in:
f 2021-05-19 17:55:55 -03:00
parent dab44aa1cf
commit e4754b342b
4 changed files with 25 additions and 21 deletions

View File

@ -6,8 +6,10 @@ FROM alpine:3.13.5 AS build
MAINTAINER "f <f@sutty.nl>"
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

View File

@ -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

View File

@ -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"

View File

@ -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/