|
| 1 | +name: Website Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + environment_name: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + url: |
| 10 | + required: false |
| 11 | + type: string |
| 12 | + target: |
| 13 | + required: false |
| 14 | + type: string |
| 15 | + default: 'www' |
| 16 | + action: |
| 17 | + required: false |
| 18 | + type: string |
| 19 | + default: 'deploy' # Or 'teardown' |
| 20 | + secrets: |
| 21 | + OVH_USERNAME: |
| 22 | + required: true |
| 23 | + OVH_HOSTNAME: |
| 24 | + required: true |
| 25 | + OVH_PASSWORD: |
| 26 | + required: true |
| 27 | + |
| 28 | +jobs: |
| 29 | + apply: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + concurrency: |
| 32 | + group: website-ovh-${{ inputs.target }} |
| 33 | + environment: |
| 34 | + name: ${{ inputs.environment_name }} |
| 35 | + url: ${{ inputs.url }} |
| 36 | + steps: |
| 37 | + - name: Forbid tearing down production |
| 38 | + if: ${{ inputs.target == 'www' && inputs.action == 'teardown' }} |
| 39 | + run: | |
| 40 | + echo "Tearing down production is not allowed!" |
| 41 | + exit 1 |
| 42 | + - name: Check out repository |
| 43 | + if: ${{ inputs.action != 'teardown' }} |
| 44 | + uses: actions/checkout@v4.2.2 |
| 45 | + with: |
| 46 | + fetch-depth: 0 |
| 47 | + - name: Set up Python |
| 48 | + if: ${{ inputs.action != 'teardown' }} |
| 49 | + uses: actions/setup-python@v6 |
| 50 | + with: |
| 51 | + python-version: 3.12 |
| 52 | + cache: 'pip' # caching pip dependencies |
| 53 | + - name: Install Python dependencies |
| 54 | + if: ${{ inputs.action != 'teardown' }} |
| 55 | + run: | |
| 56 | + pip install -r requirements.txt |
| 57 | + - name: Install dependencies |
| 58 | + run: | |
| 59 | + sudo apt-get update |
| 60 | + sudo apt-get install -y lftp |
| 61 | +
|
| 62 | + - name: Setup PR website HTACCESS |
| 63 | + if: ${{ inputs.target == 'www' }} |
| 64 | + env: |
| 65 | + OVH_USERNAME: ${{ secrets.OVH_USERNAME }} |
| 66 | + OVH_HOSTNAME: ${{ secrets.OVH_HOSTNAME }} |
| 67 | + LFTP_PASSWORD: ${{ secrets.OVH_PASSWORD }} |
| 68 | + MAIN_WEBSITE: ${{ vars.MAIN_WEBSITE }} |
| 69 | + run: | |
| 70 | + mkdir -p ${HOME}/.ssh/ |
| 71 | + ssh-keyscan "${OVH_HOSTNAME}" >> "${HOME}/.ssh/known_hosts" |
| 72 | + cat > .htaccess <<EOF |
| 73 | + Options -Indexes |
| 74 | + ErrorDocument 403 https://${MAIN_WEBSITE} |
| 75 | + EOF |
| 76 | + lftp --env-password -u ${OVH_USERNAME} sftp://${OVH_HOSTNAME} \ |
| 77 | + -e "put .htaccess -o /home/${OVH_USERNAME}/pulls/.htaccess" |
| 78 | +
|
| 79 | + - name: Build |
| 80 | + if: ${{ inputs.action != 'teardown' }} |
| 81 | + env: |
| 82 | + SITEURL: ${{ inputs.url }} |
| 83 | + run: | |
| 84 | + pelican -e SITEURL="\"$SITEURL\"" |
| 85 | + sed -E '/\{% (end)?verbatim %\}/d' htaccess > ./output/.htaccess |
| 86 | + # Migrated from netlify.toml |
| 87 | + cat >> ./output/.htaccess <<EOF |
| 88 | + <IfModule mod_headers.c> |
| 89 | + # Global security headers |
| 90 | + Header set Content-Security-Policy "default-src 'self'; style-src 'self'; script-src 'self'" |
| 91 | + Header set Permissions-Policy "ambient-light-sensor=(); autoplay=(); accelerometer=(); camera=(); display-capture=(); document-domain=(); encrypted-media=(); fullscreen=(); gyroscope=(); magnetometer=(); microphone=(); midi=(); payment=(); picture-in-picture=(); sync-xhr=(); usb=(); wake-lock=(); xr-spatial-tracking=()" |
| 92 | + Header set Referrer-Policy "no-referrer-when-downgrade" |
| 93 | + Header set X-Content-Type-Options "nosniff" |
| 94 | + Header set X-Frame-Options "DENY" |
| 95 | + Header set X-XSS-Protection "1; mode=block" |
| 96 | +
|
| 97 | + # Override CSP for /news/* pages |
| 98 | + SetEnvIf Request_URI "^/news/" is_news |
| 99 | + Header set Content-Security-Policy "default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'sha256-UPkidoMErzWw1gW/eY4LhAi9ZkPch3PP31d6KQoJ6Yc=' 'sha256-G40wI6OaLZXCtrb02xUq1H1kEVWjstzoQ0FXKwsWxPw=' 'sha256-1CldwzdEg2k1wTmf7s5RWVd7NMXI/7nxxjJM2C4DqII=' https://mixxx.discourse.group/javascripts/embed.js *.discourse-cdn.com; frame-src 'self' https://www.youtube-nocookie.com https://mixxx.discourse.group ; img-src 'self' https://i.ytimg.com https://raw.githubusercontent.com/mixxxdj/ ; connect-src 'self' https://mixxx.discourse.group https://*.discourse-cdn.com" env=is_news |
| 100 | + </IfModule> |
| 101 | + EOF |
| 102 | + sed -E '/\{% (end)?verbatim %\}/d' content/robots.txt > ./output/robots.txt |
| 103 | + - name: Deploy website |
| 104 | + if: ${{ inputs.action != 'teardown' }} |
| 105 | + env: |
| 106 | + OVH_USERNAME: ${{ secrets.OVH_USERNAME }} |
| 107 | + OVH_HOSTNAME: ${{ secrets.OVH_HOSTNAME }} |
| 108 | + LFTP_PASSWORD: ${{ secrets.OVH_PASSWORD }} |
| 109 | + TARGET: ${{ inputs.target }} |
| 110 | + run: | |
| 111 | + set -exo pipefail |
| 112 | + mkdir -p ${HOME}/.ssh/ |
| 113 | + ssh-keyscan "${OVH_HOSTNAME}" >> "${HOME}/.ssh/known_hosts" |
| 114 | + lftp --env-password -u ${OVH_USERNAME} sftp://${OVH_HOSTNAME} \ |
| 115 | + -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" |
| 116 | +
|
| 117 | + - name: Delete website |
| 118 | + if: ${{ inputs.action == 'teardown' && inputs.target != 'www' }} |
| 119 | + env: |
| 120 | + OVH_USERNAME: ${{ secrets.OVH_USERNAME }} |
| 121 | + OVH_HOSTNAME: ${{ secrets.OVH_HOSTNAME }} |
| 122 | + LFTP_PASSWORD: ${{ secrets.OVH_PASSWORD }} |
| 123 | + TARGET: ${{ inputs.target }} |
| 124 | + run: | |
| 125 | + set -exo pipefail |
| 126 | + mkdir -p ${HOME}/.ssh/ |
| 127 | + mkdir -p /tmp/ovh_sshfs |
| 128 | + mkdir empty |
| 129 | + ssh-keyscan "${OVH_HOSTNAME}" >> "${HOME}/.ssh/known_hosts" |
| 130 | + 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" |
0 commit comments