Изменил деплой

Вместо deployer - fabric/invoke
This commit is contained in:
Anton Vakhrushev 2022-08-15 15:45:57 +03:00
parent 2c4ca426fd
commit 0cb732c803
Signed by: av
GPG Key ID: 581F7473F7A21FA2
6 changed files with 50 additions and 83 deletions

2
.gitignore vendored
View File

@ -1,7 +1,9 @@
.idea/
.vscode/
output_*
node_modules/
var/
vendor/
.php_cs.cache
.php-cs-fixer.cache

View File

@ -70,7 +70,7 @@ watch: clean build-assets
# Deploy
deploy: build-prod
./tools/build-and-deploy-in-prod
invoke deploy
rollback:
./tools/dep rollback production -vv

View File

@ -1,49 +0,0 @@
<?php
namespace Deployer;
require 'recipe/common.php';
host('vakhrushev.me')
->user('homepage')
->stage('production')
->set('deploy_path', '/var/www/homepage')
;
host('192.168.50.10')
->stage('test')
->user('homepage')
->set('deploy_path', '/var/www/homepage')
->addSshOption('UserKnownHostsFile', '/dev/null')
->addSshOption('StrictHostKeyChecking', 'no')
;
// Saved releases
set('keep_releases', 2);
// Excluded dirs for upload
set('upload_excluded_dirs', []);
// Upload app sources on remote host
task('upload', function () {
$excluded = array_map(function ($dir) {
return sprintf('--exclude "%s"', $dir);
}, get('upload_excluded_dirs'));
upload(__DIR__ . '/output_prod/', '{{release_path}}', [
'options' => $excluded,
]);
});
// Deploy task
task('deploy', [
'deploy:info',
'deploy:prepare',
'deploy:lock',
'deploy:release',
'upload',
'deploy:symlink',
'deploy:unlock',
'cleanup',
]);
after('deploy', 'success');

View File

@ -28,8 +28,3 @@ curl -sLO https://getcomposer.org/download/2.3.10/composer.phar \
curl -sLO https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v3.9.5/php-cs-fixer.phar \
&& mv php-cs-fixer.phar /usr/local/bin/php-cs-fixer \
&& chmod +x /usr/local/bin/php-cs-fixer
# Deployer
curl -sLO https://deployer.org/releases/v6.8.0/deployer.phar \
&& mv deployer.phar /usr/local/bin/dep \
&& chmod +x /usr/local/bin/dep

47
tasks.py Normal file
View File

@ -0,0 +1,47 @@
from fabric import Connection
from invoke import task
from datetime import datetime
import subprocess as sp
import shlex
def run(args):
return sp.run(args, check=True, capture_output=True).stdout
@task
def deploy(c):
ssh_host = "homepage@51.250.85.23"
repo = "cr.yandex/crplfk0168i4o8kd7ade"
timestamp = int(datetime.now().timestamp())
commit = run(["git", "rev-parse", "--short", "HEAD"]).decode("utf-8").strip()
nginx_image_tag = f"{repo}/homepage-nginx:{commit}-{timestamp}"
print(f"Build nginx image {nginx_image_tag}")
run(
[
"docker",
"build",
"--file",
"docker/Dockerfile.nginx.prod",
"--tag",
nginx_image_tag,
".",
]
)
print("Push nginx image")
run(["docker", "push", nginx_image_tag])
print("Ready to setup remote host")
with Connection(ssh_host) as c:
c.put(
"./docker/docker-compose.prod.yml",
remote="/home/homepage/docker-compose.yml",
)
c.run("cp .env .env.prod")
c.run(f"echo NGINX_IMAGE={shlex.quote(nginx_image_tag)} >> .env.prod")
c.run("docker-compose --project-name homepage --env-file=.env.prod up --detach")

View File

@ -1,28 +0,0 @@
#!/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"