For some very simple projects we wanted ensure, that we can use git as we do it in nearly every project.
Prerequisites:
- Project managed with Git
- Gitlab CE / EE
Requirements:
- Branch based deployment
- Master branch should be published for production
- Other branches should be deployed as well, but in other folder like builds/{branch}
- Website users should not see the subfolders if they visit the website
Basicly we manage our projects like in git flow, but any branch based way of using git should be sufficient.
- Create a new Projekt in Gitlab
- Add your files to Git-Repository
- Add pscss to your project or install it centrally on your server git server, alternatively you can also use npm with gulp to compile the scss files to css files
- Define the Build Variable CREDENTIALS in the Settings of the Projekt
- Add the following .gitlab-ci.yml file
stages:
- deploy
publishToMaster:
stage:deploy
script:
- Resources/Private/tools/bin/pscss Resources/Private/codeon/scss/style.scss > Resources/Public/css/style.css
- lftp -e "mirror --exclude ^\.git.* --exclude ^Resources/Private/ --exclude \.gitlab-ci.yaml -eRv $CI_PROJECT_DIR builds/$CI_BUILD_REF_NAME; quit;" sftp://$CREDENTIALS
tags:
- local
To get the full functionality you should change the pathes in the .gitlab-ci.yml file or follow the file structure suggested by TYPO3.Flow.
Additionally we use npm with gulp to compile the files locally. On the Server we often use pscss to compile the files.
The result of this recipe is the following folder structure on the on the webserver:
ftp-root
builds
master
development
otherBranch
...
Now we need to add two more files
- .htaccess to redirect the requests to the ftp-root / document root folder into the builds/master folder
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*?)/?$ /builds/master/$1 [L]
RewriteRule ^$ /index.html [R=301,L]
- robots.txt which includes directives to avoid indexing the folders, which are not master
User-agent: * Disallow: /builds/