mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-26 09:06:21 +00:00
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:
parent
dab44aa1cf
commit
e4754b342b
4 changed files with 25 additions and 21 deletions
10
Dockerfile
10
Dockerfile
|
@ -6,8 +6,10 @@ FROM alpine:3.13.5 AS build
|
||||||
MAINTAINER "f <f@sutty.nl>"
|
MAINTAINER "f <f@sutty.nl>"
|
||||||
|
|
||||||
ARG RAILS_MASTER_KEY
|
ARG RAILS_MASTER_KEY
|
||||||
|
ARG BRANCH
|
||||||
|
|
||||||
# Un entorno base
|
# Un entorno base
|
||||||
|
ENV BRANCH=$BRANCH
|
||||||
ENV SECRET_KEY_BASE solo_es_necesaria_para_correr_rake
|
ENV SECRET_KEY_BASE solo_es_necesaria_para_correr_rake
|
||||||
ENV RAILS_ENV production
|
ENV RAILS_ENV production
|
||||||
ENV RAILS_MASTER_KEY=$RAILS_MASTER_KEY
|
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
|
# Hacer un clon limpio del repositorio en lugar de copiar todos los
|
||||||
# archivos
|
# archivos
|
||||||
RUN cd .. && git clone sutty checkout
|
RUN cd .. && git clone sutty checkout
|
||||||
|
RUN cd ../checkout && git checkout $BRANCH
|
||||||
|
|
||||||
WORKDIR /home/app/checkout
|
WORKDIR /home/app/checkout
|
||||||
# Traer las gemas:
|
# Traer las gemas:
|
||||||
|
RUN rm -r ./vendor
|
||||||
RUN mv ../sutty/vendor ./vendor
|
RUN mv ../sutty/vendor ./vendor
|
||||||
RUN mv ../sutty/.bundle ./.bundle
|
RUN mv ../sutty/.bundle ./.bundle
|
||||||
|
|
||||||
# Instalar secretos
|
# Instalar secretos
|
||||||
COPY --chown=app:root ./config/credentials.yml.enc ./config/
|
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
|
# Eliminar la necesidad de un runtime JS en producción, porque los
|
||||||
# assets ya están pre-compilados.
|
# 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/_storage /srv/http/_storage
|
||||||
RUN ln -s data/_sites /srv/http/_sites
|
RUN ln -s data/_sites /srv/http/_sites
|
||||||
RUN ln -s data/_deploy /srv/http/_deploy
|
RUN ln -s data/_deploy /srv/http/_deploy
|
||||||
RUN ln -s data/_public /srv/http/_public
|
|
||||||
RUN ln -s data/_private /srv/http/_private
|
RUN ln -s data/_private /srv/http/_private
|
||||||
|
|
||||||
# Volver a root para cerrar la compilación
|
# Volver a root para cerrar la compilación
|
||||||
USER root
|
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
|
# Instalar la configuración de monit
|
||||||
RUN install -m 640 -o root -g root /srv/http/monit.conf /etc/monit.d/sutty.conf
|
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
|
RUN apk add --no-cache daemonize ruby-webrick
|
||||||
|
|
27
Makefile
27
Makefile
|
@ -11,6 +11,20 @@ assets := package.json yarn.lock $(shell find app/assets/ app/javascript/ -type
|
||||||
alpine_version := 3.13
|
alpine_version := 3.13
|
||||||
hain ?= ../haini.sh/haini.sh
|
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
|
export
|
||||||
|
|
||||||
public/packs/manifest.json.br: $(assets)
|
public/packs/manifest.json.br: $(assets)
|
||||||
|
@ -49,12 +63,12 @@ clean:
|
||||||
|
|
||||||
# Generar la imagen Docker
|
# Generar la imagen Docker
|
||||||
build: assets
|
build: assets
|
||||||
time docker build --build-arg="RAILS_MASTER_KEY=`cat config/master.key`" -t sutty/sutty .
|
time docker build --build-arg="BRANCH=$(branch)" --build-arg="RAILS_MASTER_KEY=`cat config/master.key`" -t sutty/$(container) .
|
||||||
docker tag sutty/sutty:latest sutty:keep
|
docker tag sutty/$(container):latest sutty:keep
|
||||||
|
|
||||||
save:
|
save:
|
||||||
time docker save sutty/sutty:latest | ssh root@$(delegate).sutty.nl docker load
|
time docker save sutty/$(container):latest | ssh root@$(delegate).sutty.nl docker load
|
||||||
date +%F | xargs git tag -f
|
date +%F | xargs -I {} git tag -f $(container)-{}
|
||||||
@echo -e "\a"
|
@echo -e "\a"
|
||||||
|
|
||||||
# proyectos.
|
# proyectos.
|
||||||
|
@ -100,13 +114,14 @@ $(dirs):
|
||||||
|
|
||||||
ota: assets
|
ota: assets
|
||||||
sudo chgrp -R 82 public/
|
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
|
# Hotfixes
|
||||||
commit ?= origin/rails
|
commit ?= origin/rails
|
||||||
ota-rb:
|
ota-rb:
|
||||||
umask 022; git format-patch $(commit)
|
umask 022; git format-patch $(commit)
|
||||||
scp ./0*.patch root@athshe.sutty.nl:/tmp/
|
scp ./0*.patch $(delegate):/tmp/
|
||||||
rm ./0*.patch
|
rm ./0*.patch
|
||||||
|
|
||||||
/etc/hosts: always
|
/etc/hosts: always
|
||||||
|
|
|
@ -6,10 +6,6 @@ check process prometheus with pidfile /tmp/prometheus.pid
|
||||||
start program = "/usr/local/bin/sutty prometheus"
|
start program = "/usr/local/bin/sutty prometheus"
|
||||||
stop program = "/bin/sh -c 'cat /tmp/prometheus.pid | xargs kill'"
|
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
|
check program blazer_5m
|
||||||
with path "/bin/sh -c 'cd /srv/http && foreman start blazer_5m'"
|
with path "/bin/sh -c 'cd /srv/http && foreman start blazer_5m'"
|
||||||
as uid "app" and gid "www-data"
|
as uid "app" and gid "www-data"
|
||||||
|
|
|
@ -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/
|
|
Loading…
Reference in a new issue