Code Monkey home page Code Monkey logo

gitlab-ci-git-push's Introduction

GitLab CI runner that pushes to git

This GitLab CI runner image allows to deploy a GitLab project to a remote Git repo (useful for Dokku, Heroku, Deis, etc.)

How to use

Create .gitlab-ci.yml:

image: ilyasemenov/gitlab-ci-git-push

variables:
  # Prevent "shallow update not allowed" error.
  # Set it to maximum possible count of *new* commits that you foresee being pushed to a remote.
  GIT_DEPTH: 1000

stages:
  - deploy

deploy to production:
  stage: deploy
  environment: production
  only:
    - master
  script: git-push [email protected]:myapp

Go to GitLab > Project > Settings > CI/CD > Secret Variables, and add a variable SSH_PRIVATE_KEY:

-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----

Make sure your private ssh key is not encrypted, or Gitlab won't be able to authenticate to your SSH server. You'll know if it is encrypted if you open it up and the top has something like:

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED

If it is, you can decrypt it by running: openssl rsa -in enc.key -out dec.key

Pushing to a branch other than master

By default, git-push will push to branch master of a remote repository (that's what Dokku wants). You can override this with:

git-push [email protected]:repo branch

Pushing to Git running on a non-standard port

git-push ssh://[email protected]:8022/myapp

Not doing force push

By default, git push will be forced. You can disable force push by setting environment variable DISABLE_FORCE_PUSH to any value.

gitlab-ci-git-push's People

Contributors

brianbroderick avatar ilyasemenov avatar kasappeal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gitlab-ci-git-push's Issues

Add the ability to specify the SSH port

My SSH (and therefore my git server) runs on a nonstandard port, so it would be nice if I could specify the -p parameter (or other arguments to be passed to SSH) to connect.

Doesn't work on first deploy (when remote has no master)

Show following error:

error: unable to push to unqualified destination: master
The destination refspec neither matches an existing ref on the remote nor
begins with refs/, and we are unable to guess a prefix based on the source ref.
error: failed to push some refs to '[email protected]:sota'
ERROR: Job failed: exit code 1

Getting "error: option `push-option' requires a value"

This container was working fine but I think the recent commit has broken things for me. The gitlab-ci.yml file reads

deploytostaging:
    image: ilyasemenov/gitlab-ci-git-push
    stage: deploy
    script: git-push dokku@<my dokku server>:admin-staging
    only:
        - develop

but I get this error on build:

error: option `push-option' requires a value
usage: git push [<options>] [<repository> [<refspec>...]]

Working on gitlab.com ?

Hey, I'm not sure if I get it right. Does this package allow me to push to a regular private https://gitlab.com/username/repo ? 🙏

Wrong branch is used with GIT_STRATEGY=clone

При добавлении второго аргумента $branch пуш не происходит.
Ниже логи

$ git-push [email protected]:dev $CI_COMMIT_REF_NAME
# dokku.me:22 SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
# dokku.me:22 SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
# dokku.me:22 SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
Warning: Permanently added the ECDSA host key for IP address 'XX.XX.XX.XXX' to the list of known hosts.
To dokku.me:dev
   769ba3a..42eafbd  HEAD -> develop
Job succeeded

Также я пробовал добавлять вместо $CI_COMMIT_REF_NAME конткретные ветки(develop, staging) - результат аналогичный.

Permission denied (publickey) error when pushing to GitHub

I tried to set up the Gitlab CI as described but I'm getting this error:

Warning: Permanently added the RSA host key for IP address '140.82.114.3' to the list of known hosts. Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

This tells me everything is ok but the SSH keys.

One thing is ticking me is what is directed in this repos README (GitLab > Project > Settings > CI/CD > Secret Variables) and what is available at Gitlab right now is different. I'm suspicious that something has changed at Gitlab that broke this.

The Gitlab repo is https://gitlab.com/emreiyican/newsletter-server
The GitHub repo is https://github.com/emreiyican/newsletter_server

The .gitlab-ci.yml is below

`
image: ilyasemenov/gitlab-ci-git-push

variables:
GIT_DEPTH: 1000

stages:

  • push

before_script:

  • 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
  • eval $(ssh-agent -s)
  • mkdir -p ~/.ssh
  • chmod 700 ~/.ssh
  • echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -

push to github:
stage: push
environment: production
script: git-push [email protected]:newsletter_server
`

I also tried without the 'before_script' part and got the same result.

I created the keys with ssh-keygen -f temp.key -q -N "" && cat temp.key && cat temp.key.pub on my machine. Pasted both outputs to their respective places as printed.

At Gitlab, the SSH_PRIVATE_KEY is configured as a Variable, with environment scope production and protect variable selected.

To debug I added a line to echo the SSH_PRIVATE_KEY in the Gitlab CI file and saw that it was successfully printing the private key.

How to use

Do you have to use your image? Aka does it need a Docker runner to work or can you just use the script to get it to work?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.