-
Notifications
You must be signed in to change notification settings - Fork 52
141 lines (134 loc) · 4.73 KB
/
Copy pathovh.yaml
File metadata and controls
141 lines (134 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: Website Deploy
on:
workflow_call:
inputs:
environment_name:
required: true
type: string
url:
required: false
type: string
target:
required: false
type: string
default: 'www'
action:
required: false
type: string
default: 'deploy' # Or 'teardown'
ref:
required: false
type: string
approval_required:
required: false
type: boolean
default: false
secrets:
OVH_USERNAME:
required: true
OVH_HOSTNAME:
required: true
OVH_PASSWORD:
required: true
jobs:
apply:
runs-on: ubuntu-latest
concurrency:
group: website-ovh-${{ inputs.target }}
environment:
name: ${{ inputs.environment_name }}
url: ${{ inputs.url }}
steps:
- name: Require maintainer approval
if: ${{ inputs.action != 'teardown' && inputs.approval_required }}
run: |
echo "::error::Preview deploy requires a maintainer to add the 'preview-approved' label on this pull request."
exit 1
- name: Forbid tearing down production
if: ${{ inputs.target == 'www' && inputs.action == 'teardown' }}
run: |
echo "Tearing down production is not allowed!"
exit 1
- name: Check out repository
if: ${{ inputs.action != 'teardown' }}
uses: actions/checkout@v4.2.2
with:
fetch-depth: 0
ref: ${{ inputs.ref }}
- name: Set up Python
if: ${{ inputs.action != 'teardown' }}
uses: actions/setup-python@v6
with:
python-version: 3.12
cache: 'pip' # caching pip dependencies
- name: Install Python dependencies
if: ${{ inputs.action != 'teardown' }}
run: |
pip install -r requirements.txt
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y lftp
- name: Setup PR website HTACCESS
if: ${{ inputs.target == 'www' }}
env:
OVH_USERNAME: ${{ secrets.OVH_USERNAME }}
OVH_HOSTNAME: ${{ secrets.OVH_HOSTNAME }}
LFTP_PASSWORD: ${{ secrets.OVH_PASSWORD }}
MAIN_WEBSITE: ${{ vars.MAIN_WEBSITE }}
run: |
mkdir -p ${HOME}/.ssh/
ssh-keyscan "${OVH_HOSTNAME}" >> "${HOME}/.ssh/known_hosts"
cat > .htaccess <<EOF
Options -ExecCGI -Indexes
ErrorDocument 403 https://${MAIN_WEBSITE}
RemoveHandler .php .phtml .phar .cgi .pl .py
RemoveType .php .phtml .phar
<FilesMatch "\.(php|phtml|phar|cgi|pl|py)$">
Require all denied
</FilesMatch>
<IfModule mod_php.c>
php_flag engine off
</IfModule>
EOF
lftp --env-password -u ${OVH_USERNAME} sftp://${OVH_HOSTNAME} \
-e "put .htaccess -o /home/${OVH_USERNAME}/pulls/.htaccess"
- name: Build
if: ${{ inputs.action != 'teardown' }}
env:
SITEURL: ${{ inputs.url }}
run: |
pelican -e SITEURL="\"$SITEURL\""
python tools/generate_htaccess.py \
--template htaccess \
--redirects content/_redirects \
--netlify-config netlify.toml \
--output ./output/.htaccess
sed -E '/\{% (end)?verbatim %\}/d' content/robots.txt > ./output/robots.txt
- name: Deploy website
if: ${{ inputs.action != 'teardown' }}
env:
OVH_USERNAME: ${{ secrets.OVH_USERNAME }}
OVH_HOSTNAME: ${{ secrets.OVH_HOSTNAME }}
LFTP_PASSWORD: ${{ secrets.OVH_PASSWORD }}
TARGET: ${{ inputs.target }}
run: |
set -exo pipefail
mkdir -p ${HOME}/.ssh/
ssh-keyscan "${OVH_HOSTNAME}" >> "${HOME}/.ssh/known_hosts"
lftp --env-password -u ${OVH_USERNAME} sftp://${OVH_HOSTNAME} \
-e "set sftp:connect-program \"ssh -o Compression=no\"; set mirror:parallel-transfer-count 16; set mirror:parallel-directories yes; mirror -vv --delete -P 16 -R ./output /home/${OVH_USERNAME}/${TARGET}; quit"
- name: Delete website
if: ${{ inputs.action == 'teardown' && inputs.target != 'www' }}
env:
OVH_USERNAME: ${{ secrets.OVH_USERNAME }}
OVH_HOSTNAME: ${{ secrets.OVH_HOSTNAME }}
LFTP_PASSWORD: ${{ secrets.OVH_PASSWORD }}
TARGET: ${{ inputs.target }}
run: |
set -exo pipefail
mkdir -p ${HOME}/.ssh/
mkdir -p /tmp/ovh_sshfs
mkdir empty
ssh-keyscan "${OVH_HOSTNAME}" >> "${HOME}/.ssh/known_hosts"
lftp --env-password -u ${OVH_USERNAME} sftp://${OVH_HOSTNAME} -e "set sftp:connect-program \"ssh -o Compression=no\"; set mirror:parallel-transfer-count 16; set mirror:parallel-directories yes; mirror -vv --delete -P 16 -R ./empty /home/${OVH_USERNAME}/${TARGET}; rmdir /home/${OVH_USERNAME}/${TARGET}; quit"