Добавил деплой в продакшен через docker

- Создание образа
- Запись в реестре
- Развертывание из реестра на сервере
This commit is contained in:
Anton Vakhrushev 2022-08-15 12:15:37 +03:00
parent 7007b184d0
commit 6a7047cfe9
Signed by: av
GPG Key ID: 581F7473F7A21FA2
5 changed files with 43 additions and 1 deletions

View File

@ -1,4 +1,3 @@
/node_modules
/output_*
/var
/vendor

1
.env
View File

@ -1,2 +1,3 @@
PROJECT=homepage
PHP_IMAGE=homepage-php
NODE_IMAGE=homepage-node

View File

@ -0,0 +1,3 @@
FROM nginx:stable
COPY output_prod /usr/share/nginx/html

View File

@ -0,0 +1,11 @@
version: '2'
services:
nginx:
image: '${NGINX_IMAGE}'
# user: '${CURRENT_UID}:${CURRENT_GID}'
restart: unless-stopped
ports:
- '${WEB_SERVER_PORT}:80'
env_file:
- .env

28
tools/build-and-deploy-in-prod Executable file
View File

@ -0,0 +1,28 @@
#!/bin/bash
set -eu
set -x
source .env
ssh_host=homepage@51.250.85.23
repo=cr.yandex/crplfk0168i4o8kd7ade
timestamp=$(date +%s)
commit=$(git rev-parse --short HEAD)
nginx_image_tag="${repo}/homepage-nginx:${commit}-${timestamp}"
echo $timestamp
echo $commit
docker build \
--file docker/Dockerfile.nginx.prod \
--tag "${nginx_image_tag}" \
"$PWD"
docker push "${nginx_image_tag}"
scp ./docker/docker-compose.prod.yml "${ssh_host}:/home/homepage/docker-compose.yml"
ssh "${ssh_host}" -t "\
cp .env .env.prod; \
echo NGINX_IMAGE=${nginx_image_tag} >> .env.prod; \
docker-compose --project-name homepage --env-file=.env.prod up --detach"