Skip to content

Instantly share code, notes, and snippets.

@Wanchai
Last active September 20, 2020 21:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wanchai/614bce96547655318911e039aa55271a to your computer and use it in GitHub Desktop.
Save Wanchai/614bce96547655318911e039aa55271a to your computer and use it in GitHub Desktop.
Deploy an app from Gitlab registry to Heroku (.Net Core example). See -> http://blog.thomasmalicet.com/2018/04/deploy-app-from-gitlabs-registry-to.html
image: docker:git
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay
# You can find this on your Gitlab repo page, under "Registry"
CONTAINER_GITLAB: registry.gitlab.com/<USER OR GROUP NAME>/<REPO NAME>
# It's just a tag, use whatever you want : back, front, test, staging...
CONTAINER_TAG: latest
# Change with the name of your Heroku app
CONTAINER_HEROKU: registry.heroku.com/<HEROKU APP NAME>/web
# Can be found on: https://dashboard.heroku.com/account under "API Key"
HEROKU_API_KEY: <LOOKS LIKE A GUID>
# Heroku User name for login: usually an e-mail address
HEROKU_USER: myname@company.com
# Order of tasks
stages:
- dockerize
- deploy
# Register in your gitlab registry. The environment variables are set automatically, don't change anything.
before_script:
- docker login -u gitlab-ci-token -p "$CI_BUILD_TOKEN" "$CI_REGISTRY"
dockerize:
stage: dockerize
script:
# Make an image from the current folder and tag it with the registry name and tag you defined
- docker build -t $CONTAINER_GITLAB:$CONTAINER_TAG .
# Push to Gitlab
- docker push $CONTAINER_GITLAB:$CONTAINER_TAG
only:
- master
# At this point, you could go to your repo "Registry" page on Gitlab and see your image
deploy_to_heroku:
stage: deploy
# On Your CI/CD page on Gitlab, under "Environment", you can add new ones with informations like these and get informations about this deploy task
environment:
name: staging
url: https://<HEROKU APP NAME>.herokuapp.com/
services:
- docker:dind
script:
# Login to Heroku's registry
- docker login --username=$HEROKU_USER --password=$HEROKU_API_KEY registry.heroku.com
# Gets your Gitlab image
- docker pull $CONTAINER_GITLAB:$CONTAINER_TAG
# Make it good looking for Heroku
- docker tag $CONTAINER_GITLAB:$CONTAINER_TAG $CONTAINER_HEROKU
# Push it to Heroku
- docker push $CONTAINER_HEROKU
only:
- master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment