Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku: How to release an existing image in gitlab CI/CD?

I would like to deploy my application as a container from Gitlab CI/CD pipeline.

A few days ago I could deploy my docker image as written in the heroku devCenter.

docker login --username=_ --password=$(heroku auth:token) registry.heroku.com

and pushed it to the heroku registry.

docker tag imageregistry.heroku.com/app/process-type

docker push registry.heroku.com/app/process-type

But then they changed the deploy in 2 steps

heroku cointainer:push

heroku container:release

Before the update it was deployed when the container was pushed into the container registry. Now I need to release it in any way.

I tried to rename the image to release and tried to install heroku CLI but then I cannot log into heroku registry.

How did you solve it?

like image 802
Julian Stier Avatar asked Jun 18 '18 12:06

Julian Stier


People also ask

How do I push an image into Heroku?

To deploy your Docker image to Heroku, simply run one command in the directory of your Dockerfile: $ heroku container:push web === Building web Step 1 : FROM alpine:latest ... Successfully built 74bab4bf0df3 === Pushing web The push refers to a repository [registry.heroku.com/yourapp/web] c8821d626157: Pushed ...

How do I release a Heroku container?

When you release your Docker images, by running heroku container:release , your release phase process type needs to be specified: $ heroku container:release web release Releasing images web,release to your-app-name... done Running release command... Migrating database.

Does Heroku support GitLab?

It makes GitLab, on every push, use Node. js docker runner to deploy the app to Heroku. To make the deployment we'll use DPL (more information about Travis), that is, a deploy tool made for continuous deployment that will help us to deploy our app to Heroku.


2 Answers

Here's a working solution I found yesterday which trigger a release. You can keep your deployment with docker and just add this little script to your pipeline.

#!/bin/bash
imageId=$(docker inspect registry.heroku.com/$YOUR_HEROKU_APP/web --format={{.Id}})
payload='{"updates":[{"type":"web","docker_image":"'"$imageId"'"}]}'
curl -n -X PATCH https://api.heroku.com/apps/${YOUR_HEROKU_APP}/formation \
-d "$payload" \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.heroku+json; version=3.docker-releases" \
-H "Authorization: Bearer $YOUR_HEROKU_API_KEY"

This solution comes from Kai tödter and you can find it at https://toedter.com/2018/06/02/heroku-docker-deployment-update/

like image 173
Sam Avatar answered Sep 21 '22 23:09

Sam


Here's one simple way of doing it:

#.gitlab-ci.yml
..............
deploy_stage:
stage: deploy
tags:
- docker
only:
- master
script:
- docker login --username=_ --password=$HEROKU_API_KEY registry.heroku.com
- docker pull $CONTAINER_IMAGE:staging
- docker tag $CONTAINER_IMAGE:staging registry.heroku.com/django-cloud/web
- docker push registry.heroku.com/django-cloud/web
- docker run --rm -e HEROKU_API_KEY=$HEROKU_API_KEY wingrunr21/alpine-heroku-cli container:release web --app django-cloud

Ref: https://gitlab.com/Banzyme2/django-cloud9-dokcer

like image 27
ENDEESA Avatar answered Sep 23 '22 23:09

ENDEESA