diff --git a/Dockerfile b/Dockerfile index 1aa97b1..3781772 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 af46648..c7f4fd3 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 b8c9e44..f574c56 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 1c1a6ca..0000000 --- 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/