diff options
-rw-r--r-- | dream-api.lua | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/dream-api.lua b/dream-api.lua index 6aaad25..c1ce887 100644 --- a/dream-api.lua +++ b/dream-api.lua @@ -2,6 +2,7 @@ -- SPDX-FileCopyrightText: 2021 petites singularités -- SPDX-License-Identifier: AGPL-3.0-or-later + --[[ dream-api.lua ]] -- Require POST method to avoid search spider bots @@ -22,7 +23,6 @@ bare_repo = '/srv/www/public.cat/dream.git' -- In production require an existing Git tag to deploy if to == 'production' then tag = ngx.var.tag .. '' -- git tag to deploy - ngx.say("tag is now: " .. tag) -- TODO Check whether it's a known tag (and exit) @@ -38,20 +38,29 @@ ngx.say('Deploying ', tag, ' to ', to) local os = require 'os' +os.execute('cd /srv/www/public.cat') + -- Checkout the site -cmd_clone = 'test -f ' .. bare_repo .. '/config || umask 022 && git clone --bare -- ' .. upstream_repo .. ' ' .. bare_repo +cmd_clone = 'test -f ' .. bare_repo .. '/config || ( umask 022 && git clone --bare -- ' .. upstream_repo .. ' ' .. bare_repo .. ' ) ' ngx.say(cmd_clone) os.execute(cmd_clone) +os.execute('/usr/bin/find ' .. bare_repo .. ' -type d -exec chmod 0700 {} \\;') +os.execute('/usr/bin/find ' .. bare_repo .. ' -type f -exec chmod 0600 {} \\;') +-- Prepare deployment directory cmd_deploy_dir = 'mkdir -m 0755 -p ' .. deploy_dir ngx.say(cmd_deploy_dir) os.execute('mkdir -m 0755 -p ' .. deploy_dir) +-- Deploy the repository cmd_fetch = 'git --git-dir ' .. bare_repo .. ' fetch' ---cmd_deploy = cmd_fetch .. ' && ' .. cmd_fetch .. ' -t && cd ' .. deploy_dir .. ' && git --git-dir ' .. bare_repo .. ' --work-tree ' .. deploy_dir .. ' checkout -f ' .. tag -cmd_deploy = cmd_fetch .. ' -t && cd ' .. deploy_dir .. ' && git --git-dir ' .. bare_repo .. ' --work-tree ' .. deploy_dir .. ' checkout -f ' .. tag +cmd_deploy = cmd_fetch .. ' && ' .. cmd_fetch .. ' -t && cd ' .. deploy_dir .. ' && git --git-dir ' .. bare_repo .. ' --work-tree ' .. deploy_dir .. ' checkout -f ' .. tag +--cmd_deploy = cmd_fetch .. ' -t && cd ' .. deploy_dir .. ' && git --git-dir ' .. bare_repo .. ' --work-tree ' .. deploy_dir .. ' checkout -f ' .. tag ngx.say(cmd_deploy) os.execute(cmd_deploy) -ngx.exit(ngx.OK) +-- Fix permissions +os.execute('/usr/bin/find ' .. deploy_dir .. ' -type d -exec chmod 0755 {} \\;') +os.execute('/usr/bin/find ' .. deploy_dir .. ' -type f -exec chmod 0644 {} \\;') +ngx.exit(ngx.OK) |