I have two projects in Gitlab where one is a submodule (let's call repo "frontend-templates") of the other (let's call this repo "main"). I have set up a Gitlab CI build for the "frontend-templates" repo. The thing is that I don't need testing or building. I only need deploying for this CI in the needed directory. So, I registered a runner for "frontend-templates" project and added .gitlab-ci.yml to the root directory:
job_main:
type: deploy
script: echo "Do nothing"
/home/gitlab-runner/builds/6231b425/0/Gasimzada/frontend-templates
echo "Do nothing"
/var/www/myapp/submodules/frontend-templates
script: cd /var/www/myapp/submodules/frontend-templates && git pull
cannot open /var/www/myapp/.git/modules/submodules/frontend-templates/FETCH_HEAD: Permission denied
gulp
You can simply perform some form of deployment using the directory you are in. You can rename/delete the directory of the currently deployed code and copy the checkout code there (rm -rf /var/www/myapp/submodules/frontend-templates && cp -r . /var/www/myapp/submodules/frontend-templates
) or you can use rsync
to do the synchronization.
However, these are not atomic operations - they will leave your deployed code in an uncertain state while they are being performed and in a mess if they fail. I'd suggest your /var/www/myapp/submodules/frontend-templates is just a symlink to a directory containing the code:
/var/www/myapp/submodules
| - 7348110b
| - a03ed59a
| - frontend-templates -> ./a03ed59a
You can name the code directories according to the commit hash. The job itself could then look something like this:
job_main:
type: deploy
script:
- cp -r . /var/www/myapp/submodules/$CI_BUILD_REF
- ln -s ./$CI_BUILD_REF /var/www/myapp/submodules/templink
- mv -Tf /var/www/myapp/submodules/templink /var/www/myapp/submodules/frontend-templates
NOTE: Obviously, the runner will need necessary file permissions to perform the tasks.