DEV Community

Evan Lin
Evan Lin

Posted on • Originally published at evanlin.com on

[Golang] Deploy Docker Containers on GitHub with Heroku (One-Click)

title: [Learning Document][Golang] How to Deploy a Docker Container Directly on Heroku with a Single Click from Github
published: false
date: 2022-08-17 00:00:00 UTC
tags: 
canonical_url: http://www.evanlin.com/til-heroku-docker-deploy/
---

![image-20220819112137025](http://www.evanlin.com/images/2021/image-20220819112137025.png)

## Preface:

Recently, I saw a package imagor that is quite interesting. It can use Golang binding C's libvips to do image editing similar to ImageMagick. However, the one-click deployment to Heroku button that I like was missing, so I sent a PR to help him.

I have always liked adding a "one-click deploy to Heroku" button directly to the Github Repo. With many Golang Repos recently using some C language related underlying packages, many services have been packaged into Docker to do Github's CICD. But for developers who just want to quickly use the features of this package through Heroku, how to quickly import Deploy on Heroku is the focus of this article.

# A Package for Image Editing: imagor

The modifications described in this article will use the package [https://github.com/cshum/imagor](https://github.com/cshum/imagor) as an example.

## What is [imagor](https://github.com/cshum/imagor)

It is a package that uses Golang to directly operate the well-known image editing package [libvips (built with C)](https://www.libvips.org/), which already has a Docker image (`shumc/imagor`). There is a similar commercialized package here: [Imgproxy](https://github.com/imgproxy/imgproxy).

## Easy to use, powerful features

Quick deployment can be done with the following command:

Enter fullscreen mode Exit fullscreen mode

docker run -p 8000:8000 shumc/imagor -imagor-unsafe -imagor-auto-webp


And you can get the following results, you can check [https://github.com/cshum/imagor](https://github.com/cshum/imagor).

### Original Image

[![img](https://raw.githubusercontent.com/cshum/imagor/master/testdata/dancing-banana.gif)](https://raw.githubusercontent.com/cshum/imagor/master/testdata/dancing-banana.gif) [![img](https://raw.githubusercontent.com/cshum/imagor/master/testdata/gopher-front.png)](https://raw.githubusercontent.com/cshum/imagor/master/testdata/gopher-front.png)

### Composite

[![img](https://raw.githubusercontent.com/cshum/imagor/master/testdata/demo5.gif)](https://raw.githubusercontent.com/cshum/imagor/master/testdata/demo5.gif)

## Modification Process:

In fact, [https://github.com/cshum/imagor](https://github.com/cshum/imagor) already has a Docker Image. Here are some basic import processes:

### Add Heroku Support:

### 1. Add a new file `app.json`

Enter fullscreen mode Exit fullscreen mode

{
"name": "imagor",
"description": "Fast, Docker-ready image processing server in Go with libvips",
"keywords": [
"image",
"resize-images",
"crop-image",
"microservice",
"docker",
"jpeg",
"png",
"libvips"
],
"repository": "https://github.com/cshum/imagor",
"stack": "container",
"env": {
"IMAGOR_UNSAFE": {
"description": "Use Unsafe mode, default 1 for testing. In production environment, it is highly recommended turning off IMAGOR_UNSAFE and setting up URL signature using IMAGOR_SECRET, to prevent DDoS attacks that abuse multiple image operations.",
"required": true,
"value": "1"
},
"IMAGOR_SECRET": {
"description": "Secret key for URL signature.",
"required": false
}
}
}


- Let's write down a few important ones:
  - ` “repository”: “https://github.com/cshum/imagor”,`: Let Heroku know where to find other files.
  - `"stack": "container",`: This tells Heroku to look for the `Heroku.yml` file to continue the next process.
  - `IMAGOR_UNSAFE` This parameter is because this package defaults to URL signature (you can refer to [this article](https://docs.aws.amazon.com/zh_tw/AmazonS3/latest/userguide/PresignedUrlUploadObject.html))

### 2. Add heroku.yml

Enter fullscreen mode Exit fullscreen mode

build:
docker:
web: heroku/Dockerfile


We will continue to write the content of `heroku/Dockerfile` later. But in fact, in addition to `build:`, there are the following functions:

- **Parameter settings:** In this example, an ENV `S3_BUCKET` is set

- **Other Pluging settings:** In this example, a postgresql is started and the DATABASE alias is used

Just refer to the article [Building Docker Images with heroku.yml](https://devcenter.heroku.com/articles/build-docker-images-heroku-yml) to find out more about the usage of `Heroku.yml`.

### 3. Dockerfile for Heroku

Enter fullscreen mode Exit fullscreen mode

FROM shumc/imagor:latest
LABEL maintainer="Adrian Shum adrian@cshum.com"


There are not too many default processes here, which can be built every time, but I choose to let the release management return to the original image owner. So you can directly reference it here.

For the complete content, please refer to this PR [https://github.com/cshum/imagor/pull/142](https://github.com/cshum/imagor/pull/142)

# Results:

You can directly go to this Repo and click Deploy to deploy. [https://github.com/cshum/imagor](https://github.com/cshum/imagor)

You can also view the results through the following servers:

- [Display a Gopher image](https://imagor-kkdai.herokuapp.com/unsafe/fit-in/200x200/filters:fill(white)/https://raw.githubusercontent.com/cshum/imagor/master/testdata/gopher.png) ![](https://imagor-kkdai.herokuapp.com/unsafe/fit-in/200x200/filters:fill(white)/https://raw.githubusercontent.com/cshum/imagor/master/testdata/gopher.png)

- [That dancing banana](https://imagor-kkdai.herokuapp.com/unsafe/30x40:100x150/filters:fill(cyan)/raw.githubusercontent.com/cshum/imagor/master/testdata/dancing-banana.gif) ![](https://imagor-kkdai.herokuapp.com/unsafe/30x40:100x150/filters:fill(cyan)/raw.githubusercontent.com/cshum/imagor/master/testdata/dancing-banana.gif)

- [Combining two images](https://imagor-kkdai.herokuapp.com/unsafe/fit-in/200x150/filters:fill(yellow):watermark(raw.githubusercontent.com/cshum/imagor/master/testdata/gopher-front.png,repeat,bottom,0,40,40)/raw.githubusercontent.com/cshum/imagor/master/testdata/dancing-banana.gif) ![](https://imagor-kkdai.herokuapp.com/unsafe/fit-in/200x150/filters:fill(yellow):watermark(raw.githubusercontent.com/cshum/imagor/master/testdata/gopher-front.png,repeat,bottom,0,40,40)/raw.githubusercontent.com/cshum/imagor/master/testdata/dancing-banana.gif)

## Related Articles:

- [Heroku: Building Docker Images with heroku.yml](https://devcenter.heroku.com/articles/build-docker-images-heroku-yml)
- [How to Deploy Docker Container on Heroku?](https://medium.com/featurepreneur/how-to-deploy-docker-container-on-heroku-part-2-eaaaf1027f0b)
- [Deploy any web application to Heroku with Docker](https://medium.com/starbugs/deploy-any-web-application-to-heroku-with-docker-b64b9b0eb93)
- Two image editing servers written in Golang through [libvips](https://www.libvips.org/)
  - [https://github.com/imgproxy/imgproxy](https://github.com/imgproxy/imgproxy)
  - [https://github.com/cshum/imagor](https://github.com/cshum/imagor)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)