Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.3 deploy (SSH2) #1396

Merged
merged 33 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ jobs:
CONFIG_MAIL_USERNAME:
CONFIG_MAILING_SENDER_EMAIL: ${{ secrets.CONFIG_MAILING_SENDER_EMAIL }}
CONFIG_SKAUTIS_APPLICATION_ID: ${{ secrets.CONFIG_SKAUTIS_APPLICATION_ID }}
CONFIG_SKAUTIS_TEST_MODE: ${{ secrets.CONFIG_SKAUTIS_TEST_MODE }}
CONFIG_SKAUTIS_TEST_MODE: ${{ vars.CONFIG_SKAUTIS_TEST_MODE }}
CONFIG_RECAPTCHA_SITE_KEY: ${{ secrets.CONFIG_RECAPTCHA_SITE_KEY }}
CONFIG_RECAPTCHA_SECRET_KEY: ${{ secrets.CONFIG_RECAPTCHA_SECRET_KEY }}
DEPLOY_DIRECTORY: ${{ secrets.DEPLOY_DIRECTORY }}
DEPLOY_LEBEDA: ${{ secrets.DEPLOY_LEBEDA }}
DEPLOY_DIRECTORY: ${{ vars.DEPLOY_DIRECTORY }}
DEPLOY_LEBEDA: ${{ vars.DEPLOY_LEBEDA }}
DEPLOY_SSH_HOST: ${{ secrets.DEPLOY_SSH_HOST }}
DEPLOY_SSH_IP: ${{ secrets.DEPLOY_SSH_IP }}
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
Expand Down Expand Up @@ -66,10 +66,13 @@ jobs:
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Setup SSH key and deploy
- name: Setup SSH2
run: |
mkdir -p /root/.ssh
ssh-keyscan -H "${DEPLOY_SSH_HOST}","${DEPLOY_SSH_IP}" >> /root/.ssh/known_hosts
eval `ssh-agent -s`
echo "${DEPLOY_SSH_KEY}" | tr -d '\r' | ssh-add -
phing deploy
apt-get -y install libssh2-1-dev
pecl install pecl.php.net/ssh2-1.4.1
echo extension=ssh2.so > /usr/local/etc/php/conf.d/ssh2.ini
echo "${{ secrets.DEPLOY_SSH_KEY }}" > id_rsa
chmod 600 id_rsa
ssh-keygen -f id_rsa -y > id_rsa.pub
- name: Deploy
run: phing deploy
23 changes: 13 additions & 10 deletions .github/workflows/deploy-manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ jobs:
CONFIG_MAIL_HOST: ${{ secrets.CONFIG_MAIL_HOST }}
CONFIG_MAIL_PASSWORD: ${{ secrets.CONFIG_MAIL_PASSWORD }}
CONFIG_MAIL_PORT: ${{ secrets.CONFIG_MAIL_PORT }}
CONFIG_MAIL_SECURE: ${{ secrets.CONFIG_MAIL_SECURE }}
CONFIG_MAIL_SECURE: ${{ vars.CONFIG_MAIL_SECURE }}
CONFIG_MAIL_SMTP: ${{ secrets.CONFIG_MAIL_SMTP }}
CONFIG_MAIL_USERNAME: ${{ secrets.CONFIG_MAIL_USERNAME }}
CONFIG_MAILING_SENDER_EMAIL: ${{ secrets.CONFIG_MAILING_SENDER_EMAIL }}
CONFIG_SKAUTIS_APPLICATION_ID: ${{ secrets.CONFIG_SKAUTIS_APPLICATION_ID }}
CONFIG_SKAUTIS_TEST_MODE: ${{ secrets.CONFIG_SKAUTIS_TEST_MODE }}
CONFIG_SKAUTIS_TEST_MODE: ${{ vars.CONFIG_SKAUTIS_TEST_MODE }}
CONFIG_RECAPTCHA_SITE_KEY: ${{ secrets.CONFIG_RECAPTCHA_SITE_KEY }}
CONFIG_RECAPTCHA_SECRET_KEY: ${{ secrets.CONFIG_RECAPTCHA_SECRET_KEY }}
DEPLOY_DIRECTORY: ${{ secrets.DEPLOY_DIRECTORY }}
DEPLOY_LEBEDA: ${{ secrets.DEPLOY_LEBEDA }}
DEPLOY_DIRECTORY: ${{ vars.DEPLOY_DIRECTORY }}
DEPLOY_LEBEDA: ${{ vars.DEPLOY_LEBEDA }}
DEPLOY_SSH_HOST: ${{ secrets.DEPLOY_SSH_HOST }}
DEPLOY_SSH_IP: ${{ secrets.DEPLOY_SSH_IP }}
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
Expand Down Expand Up @@ -69,10 +69,13 @@ jobs:
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Setup SSH key and deploy
- name: Setup SSH2
run: |
mkdir -p /root/.ssh
ssh-keyscan -H "${DEPLOY_SSH_HOST}","${DEPLOY_SSH_IP}" >> /root/.ssh/known_hosts
eval `ssh-agent -s`
echo "${DEPLOY_SSH_KEY}" | tr -d '\r' | ssh-add -
phing deploy
apt-get -y install libssh2-1-dev
pecl install pecl.php.net/ssh2-1.4.1
echo extension=ssh2.so > /usr/local/etc/php/conf.d/ssh2.ini
echo "${{ secrets.DEPLOY_SSH_KEY }}" > id_rsa
chmod 600 id_rsa
ssh-keygen -f id_rsa -y > id_rsa.pub
- name: Deploy
run: phing deploy
21 changes: 12 additions & 9 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ jobs:
CONFIG_MAIL_USERNAME:
CONFIG_MAILING_SENDER_EMAIL: ${{ secrets.CONFIG_MAILING_SENDER_EMAIL }}
CONFIG_SKAUTIS_APPLICATION_ID: ${{ secrets.CONFIG_SKAUTIS_APPLICATION_ID }}
CONFIG_SKAUTIS_TEST_MODE: ${{ secrets.CONFIG_SKAUTIS_TEST_MODE }}
CONFIG_SKAUTIS_TEST_MODE: ${{ vars.CONFIG_SKAUTIS_TEST_MODE }}
CONFIG_RECAPTCHA_SITE_KEY: ${{ secrets.CONFIG_RECAPTCHA_SITE_KEY }}
CONFIG_RECAPTCHA_SECRET_KEY: ${{ secrets.CONFIG_RECAPTCHA_SECRET_KEY }}
DEPLOY_DIRECTORY: ${{ secrets.DEPLOY_DIRECTORY }}
DEPLOY_LEBEDA: ${{ secrets.DEPLOY_LEBEDA }}
DEPLOY_DIRECTORY: ${{ vars.DEPLOY_DIRECTORY }}
DEPLOY_LEBEDA: ${{ vars.DEPLOY_LEBEDA }}
DEPLOY_SSH_HOST: ${{ secrets.DEPLOY_SSH_HOST }}
DEPLOY_SSH_IP: ${{ secrets.DEPLOY_SSH_IP }}
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
Expand Down Expand Up @@ -65,10 +65,13 @@ jobs:
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Setup SSH key and deploy
- name: Setup SSH2
run: |
mkdir -p /root/.ssh
ssh-keyscan -H "${DEPLOY_SSH_HOST}","${DEPLOY_SSH_IP}" >> /root/.ssh/known_hosts
eval `ssh-agent -s`
echo "${DEPLOY_SSH_KEY}" | tr -d '\r' | ssh-add -
phing deploy
apt-get -y install libssh2-1-dev
pecl install pecl.php.net/ssh2-1.4.1
echo extension=ssh2.so > /usr/local/etc/php/conf.d/ssh2.ini
echo "${{ secrets.DEPLOY_SSH_KEY }}" > id_rsa
chmod 600 id_rsa
ssh-keygen -f id_rsa -y > id_rsa.pub
- name: Deploy
run: phing deploy
72 changes: 29 additions & 43 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<project name="SRS" basedir="." default="main">
<property name="tempDir" value="temp"/>

<target name="main" description="Runs tests and prepares deployable tarball">
<exec executable="composer" passthru="true">
<arg value="install"/>
Expand All @@ -20,8 +21,7 @@

<target name="prepare-tarball" description="Prepares deployable tarball with everything built">
<exec executable="git" outputProperty="build.hash">
<arg value="rev-parse"/>
<arg value="--short HEAD"/>
<arg line="rev-parse --short HEAD"/>
</exec>

<property name="build.dir" value="${tempDir}/builds/${build.hash}"/>
Expand Down Expand Up @@ -104,35 +104,30 @@
</fileset>
</tar>

<delete dir="${build.dir}" />
<delete dir="${build.dir}"/>
</target>

<target name="deploy:ssh">
<echo message="${comment}..."/>
<echo message="${command}"/>
<exec executable="ssh" passthru="true" checkreturn="true">
<arg value="${deploy.ssh.target}"/>
<arg value="-p ${deploy.ssh.port}"/>
<arg value="'${command}'"/>
</exec>
<ssh host="${deploy.ssh.host}" port="${deploy.ssh.port}" username="${deploy.ssh.username}" privkeyfile="id_rsa"
pubkeyfile="id_rsa.pub" command="${command}"/>
</target>

<target name="deploy:copy-tarball">
<property name="command" value="scp"/>
<property name="args" value="-P ${port} ${file} '${target}:${toDirectory}'"/>
<echo message="Copying files to ${deploy.ssh.target}"/>
<echo message="${command} ${args}"/>
<exec executable="${command}" passthru="true" checkreturn="true">
<arg value="${args}"/>
</exec>
<echo message="Copying ${file} to ${toDirectory}"/>
<scp host="${deploy.ssh.host}" port="${deploy.ssh.port}" username="${deploy.ssh.username}" privkeyfile="id_rsa"
pubkeyfile="id_rsa.pub" file="${file}" todir="${toDirectory}"/>
</target>

<target name="deploy:cleanup">
<echo message="Getting previous releases"/>
<ssh host="${deploy.ssh.host}" port="${deploy.ssh.port}" username="${deploy.ssh.username}" privkeyfile="id_rsa"
pubkeyfile="id_rsa.pub" command="ls ${deploy.releasesDir}" property="allReleases"/>

<property name="command" value="echo $(ssh -p ${deploy.ssh.port} ${deploy.ssh.target} 'ls ${deploy.releasesDir}' | grep -v '^${deploy.releaseHash}$')"/>
<echo message="${command}"/>
<exec outputProperty="previousReleases" command="${command}" checkreturn="true"/>
<exec executable="bash" outputProperty="previousReleases" checkreturn="true">
<arg value="-c"/>
<arg line='"echo &apos;${allReleases}&apos; | grep -v &apos;^${deploy.releaseHash}$&apos; | tr &apos;\n&apos; &apos; &apos;"'/>
</exec>

<phingcall target="deploy:ssh">
<property name="comment" value="Deleting files"/>
Expand All @@ -146,18 +141,18 @@
<!-- Prepare variables -->
<property environment="env"/>
<property name="deploy.workDir" refid="env.DEPLOY_DIRECTORY"/>
<property name="deploy.releasesDir" value="${deploy.workDir}/releases"/>
<exec executable="git" outputProperty="build.hash">
<arg value="rev-parse"/>
<arg value="--short HEAD"/>
</exec>
<property name="deploy.lebeda" refid="env.DEPLOY_LEBEDA"/>
<property name="deploy.ssh.host" refid="env.DEPLOY_SSH_HOST"/>
<property name="deploy.ssh.username" refid="env.DEPLOY_SSH_USERNAME"/>
<property name="deploy.ssh.port" refid="env.DEPLOY_SSH_PORT"/>
<property name="deploy.ssh.target" value="${deploy.ssh.username}@${deploy.ssh.host}"/>
<property name="deploy.ssh.username" refid="env.DEPLOY_SSH_USERNAME"/>

<exec executable="git" outputProperty="build.hash">
<arg line="rev-parse --short HEAD"/>
</exec>
<property name="deploy.releasesDir" value="${deploy.workDir}/releases"/>
<property name="deploy.releaseHash" value="${DSTAMP}-${TSTAMP}-${build.hash}"/>
<property name="deploy.release" value="${deploy.releasesDir}/${deploy.releaseHash}"/>
<property name="tarball" value="${deploy.release}.tar.gz"/>

<!-- Build tarball -->
<phingcall target="prepare-tarball">
Expand All @@ -170,14 +165,10 @@
</phingcall>

<phingcall target="deploy:copy-tarball">
<property name="target" value="${deploy.ssh.target}"/>
<property name="port" value="${deploy.ssh.port}"/>
<property name="file" value="${tempDir}/builds/${deploy.releaseHash}.tar.gz"/>
<property name="toDirectory" value="${deploy.releasesDir}"/>
</phingcall>

<property name="tarball" value="${deploy.release}.tar.gz"/>

<phingcall target="deploy:ssh">
<property name="comment" value="Extracting tarball to release directory"/>
<property name="command" value="tar -xzf ${tarball} -C ${deploy.releasesDir}"/>
Expand All @@ -190,7 +181,8 @@

<phingcall target="deploy:ssh">
<property name="comment" value="Copying custom CSS"/>
<property name="command" value="cp ${deploy.workDir}/www/css/web/style.css ${deploy.release}/www/css/web || true"/>
<property name="command"
value="cp ${deploy.workDir}/www/css/web/style.css ${deploy.release}/www/css/web || true"/>
</phingcall>

<phingcall target="deploy:ssh">
Expand Down Expand Up @@ -255,16 +247,17 @@

<phingcall target="deploy:ssh">
<property name="comment" value="Swapping release to ${deploy.releaseHash}"/>
<property name="command" value="rm -rf ${deploy.workDir}/www &amp;&amp; ln -s ${deploy.release}/www ${deploy.workDir}/www"/>
<property name="command"
value="rm -rf ${deploy.workDir}/www &amp;&amp; ln -s ${deploy.release}/www ${deploy.workDir}/www"/>
</phingcall>

<phingcall target="deploy:cleanup"/>
</target>

<target name="deploy:app-command">
<condition property="phpCommand"
value="php81-cli &quot;${deploy.release}/www/console.php ${command}&quot;"
else="php8.1 ${deploy.release}/www/console.php ${command}">
value="php83-cli &quot;${deploy.release}/www/console.php ${command}&quot;"
else="php8.3 ${deploy.release}/www/console.php ${command}">
<equals arg1="${deploy.lebeda}" arg2="true"/>
</condition>
<phingcall target="deploy:ssh">
Expand Down Expand Up @@ -310,15 +303,8 @@
</target>

<target name="static-analysis">
<exec executable="php" passthru="true" checkreturn="true">
<arg value="-d memory_limit=1024M"/>
<arg value="vendor/bin/phpstan"/>
<arg value="analyse"/>
<arg value="-l6"/>
<arg value="-cphpstan.neon"/>
<arg value="app"/>
<arg value="--no-progress"/>
</exec>
<phpstan executable="vendor/bin/phpstan" command="analyse" passthru="true" checkReturn="true" paths="app"
configuration="phpstan.neon" level="6" noProgress="true" memoryLimit="1024M"/>
</target>

<target name="coding-standard">
Expand Down