In this tutorial, we are using a custom docker image to push a git repo to a Dokku deployment (in fact, any remote git repo) in Gitlab CI runner.
Make sure you have a Gitlab account and a Dokku project hosted on Gitlab. This method works whether if you are using buildpacks or Dockerfile.
Make sure you have set up an app on the remote machine following these instructions and can successfully deploy to it from the local machine.
Visit "the Gitlab project > Settings > CI/CD." (or https://gitlab.com/**username**/**repo-name**/settings/ci_cd)
Click on "Secret variables > Expand" and fill in the blanks.
Key:
SSH_PRIVATE_KEY
Value: paste in an armored SSH private key registered in Dokku:
-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----
Environment scope:
production
(This make sure that SSH_PRIVATE_KEY is not available on merge requests or tests)Protected: don't check this checkbox unless you know what you are doing
Add a file named exactly .gitlab-ci.yml
at the root directory of the repo.
Here is a minimal Example:
stages:
- deploy
deploy to dokku: # job name, can be anything
image: ilyasemenov/gitlab-ci-git-push
stage: deploy
environment: production
only: [master] # only deploy and set SSH_PRIVATE_KEY on master branch
script: git-push ssh://dokku@<hostname>/<app name> # replace these with appropriate names
Commit this file.
Try git push
to Gitlab and visit "project > Pipelines" to see the deployment log.