In my team, we use Gitlab as a remote repository, so we are looking for a solution to auto deploy our apps to Heroku. We found Codeship for auto deploying apps to Heroku from Github.
Any tips? Tricks?
In my team, we use Gitlab as a remote repository, so we are looking for a solution to auto deploy our apps to Heroku. We found Codeship for auto deploying apps to Heroku from Github.
Any tips? Tricks?
 
    
     
    
    If you are not prepared to use Ruby/dpl you can deploy to Heroku as follows:
Look up your Heroku API key (Account settings -> API Key on the Heroku web console) and make it available as a Gitlab secret variable e.g. HEROKU_API_KEY (Please note the values is not the same as what heroku auth:token returns...)
Then add two script lines in your .gitlab-ci.yml config file at the relevant job:
git remote add heroku https://heroku:$HEROKU_API_KEY@git.heroku.com/<name of your heroku app>.git
git push -f heroku HEAD:master
You can see detailed explanation at http://blog.thecodewhisperer.com/permalink/deploying-jekyll-to-heroku-using-gitlab-ci
Here is the solution I found , restating in case the link is broken:
Configure project
This is what the .gitlab-ci.yml file looks like for this project:
test:
  script:
  # this configures Django application to use attached postgres database that is run on `postgres` host
  - export DATABASE_URL=postgres://postgres:@postgres:5432/python-test-app
  - apt-get update -qy
  - apt-get install -y python-dev python-pip
  - pip install -r requirements.txt
  - python manage.py test
staging:
  type: deploy
  script:
  - apt-get update -qy
  - apt-get install -y ruby-dev
  - gem install dpl
  - dpl --provider=heroku --app=gitlab-ci-python-test-staging --api-key=$HEROKU_STAGING_API_KEY
  only:
  - master
production:
  type: deploy
  script:
  - apt-get update -qy
  - apt-get install -y ruby-dev
  - gem install dpl
  - dpl --provider=heroku --app=gitlab-ci-python-test-prod --api-key=$HEROKU_PRODUCTION_API_KEY
  only:
  - tags
This project has three jobs:
test - used to test Django application,
staging - used to automatically deploy staging environment every push to master branch
production - used to automatically deploy production environmnet for every created tag
Store API keys
You'll need to create two variables in Project > Variables:
HEROKU_STAGING_API_KEY - Heroku API key used to deploy staging app,
HEROKU_PRODUCTION_API_KEY - Heroku API key used to deploy production app.
To complete dnit13's answer:
Make sure your environment variables are unprotected.
Go to Settings > CI/CD > Environment variables and untick Protected Variable.
More information on this thread.
 
    
    base on the documentaion of gitlab-ci has deployment tool that use to directly communicate with these providers, Heroku, Cloud Foundry, AWS/S3 etc.
here is the basic usage of dpl for your job script
staging:
  stage: deploy
  script:
    - apt-get update -yq
    - apt-get install -y ruby-dev
    - gem install dpl
    - dpl --provider=heroku --app=my-app-staging --api_key=$HEROKU_STAGING_API_KEY
  only:
    - main
for those seeker here just read this gitlab dpl documentation
