DEV Community

Deploying to Heroku from GitHub Actions

Joe Nash on January 07, 2020

GitHub Actions give us a new way to deploy to Heroku, and to integrate Heroku with other parts of our development workflows. In a single GitHub Act...
Collapse
 
javaguirre profile image
Javier Aguirre

Hi! thank you for the article!

We also push from GH Actions to Heroku, but we just use git push since it seems it's easier, what's the difference doing it this way or just pushing? Does the build takes less time or more? Thanks!

What we do is:

 steps:
    - uses: actions/checkout@v1
    - name: Push to Heroku
      run: git push -f https://heroku:${{ secrets.HEROKU_API_TOKEN }}@git.heroku.com/${{ secrets.HEROKU_APP_STAGING }}.git origin/master:master
Enter fullscreen mode Exit fullscreen mode

What do you recommend?

Thanks!

Collapse
 
joenash profile image
Joe Nash

Hey Javier!
That’s awesome to hear. It’s not a straight pro/con toss-up, and which builds faster is going to depend on your stack, and that for the most part is also going to decide whether git or docker is better for you.
Docker is going to give you greater flexibility in what you run on Heroku, as you are providing the container. But git is going to be using the Heroku-curated environments that they do a lot of work to optimise around. There’s also, I believe, some features that are less supported for Docker, for example I believe Review Apps isn’t available if you go a certain route for docker deploys.

Collapse
 
javaguirre profile image
Javier Aguirre

Hi! We're using docker, heroku.yml, and the container stack! But instead of pushing to the container registry we use git push to Heroku, I don't understand if there is any difference in doing it your way or the way we do since both are docker deploys.

Thank you for your answer!

Collapse
 
lsgalves profile image
Leonardo Galves

Hi! great article, I was just curious about how the migration files would be executed. I tried this:

steps:
  - name: Migrate
    run: heroku container:run web ./manage.py migrate -a ${{ secrets.HEROKU_APP_NAME }}
Enter fullscreen mode Exit fullscreen mode

But I get "the input device is not a TTY".

And you can add an environment variable for all the steps added to your job, like this:

jobs:
  build:
    env:
      HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
sabiou profile image
Farouk Sabiou • Edited

Hi, thanks for the article. I followed the same step to configure an heroku deployment but I get this error:

Run heroku container:push -a habu-server web
heroku container:push -a habu-server web
shell: /bin/bash -e {0}
env:
HEROKU_API_KEY: ***
› Warning: heroku update available from 7.47.3 to 7.47.4.
▸ No images to push
Error: Process completed with exit code 1.

Collapse
 
gusbemacbe profile image
Gustavo Benedetto Conti Papi

Change ubuntu-latest to ubuntu-20.04.

Add this source code before Login to Heroku Container registry

    - name: Update Heroku
      env: 
        HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
      run: sudo apt update && sudo apt install heroku
Enter fullscreen mode Exit fullscreen mode
Collapse
 
r0nunes profile image
Renato O. Nunes • Edited

Hey!!

I tried to add the code above, but I still have the same error

Collapse
 
frenzyfunky profile image
Yağız Yorulmazlar

Is your Dockerfile in a subdirectory? If so, change the Dockerfile file name as "Dockerfile.web" and modify heroku push command as "heroku container:push -a $APP_NAME --context-path . --recursive"
In here recursive searches Dockerfiles in current and subdirectories, context-path is specifies build context which is root directory.

Collapse
 
damiensn profile image
Damien S

Thank you very much for the article ! I found it very helpful.
But as I'm not really an expert in Docker I was wondering how you can pass environement variables for the build of the container and for the execution ?
I don't know if what I say is really clear, let me know if it isn't 😅

Collapse
 
shinjam profile image
Jae Min Shin • Edited

Hi, thank you for the article :)

I wonder how it is possible to use Heroku CLI even there aren't any codes about Heroku installation.
Does ubuntu-latest install by default or about actions/checkouts?

Thank you!

Collapse
 
manojap profile image
MANOJ AP

ENDED UP WITH THIS ERROR

Run heroku container:push -a *** web
▸ Couldn't find that app.

[error]Process completed with exit code 1.

Collapse
 
gusbemacbe profile image
Gustavo Benedetto Conti Papi

@manojap and @iamjithindas

Switch to a new source code:

name: Deploy

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v2
      - name: Updating Ubuntu system and Heroku
        env: 
          HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
        run: sudo apt update && sudo apt install heroku neofetch
      - name: Checking the info
        run: neofetch

      - uses: akhileshns/heroku-deploy@v3.8.8
        with:
          heroku_email: your Heroku e-mail
          heroku_api_key: ${{secrets.HEROKU_API_KEY}}
          heroku_app_name: your Heroku app names (go to your project's settings and check the app name)
          branch: HEAD
          useforce: false
          dynamicFiles: false
Enter fullscreen mode Exit fullscreen mode
Collapse
 
iamjithindas profile image
Jithin das A

I ended up with the same error. have you found what's the problem?

Collapse
 
landsprutte profile image
LandSprutte

can you pass enviroment-vars to the container aswell? Say you have a connectionUrl in your secrets you want to pass :D

Collapse
 
joenash profile image
Joe Nash

Yes you can! You just set them as inputs in the Action's metadata

Collapse
 
guanacone profile image
guanacone

Great article and everything was working perfectly till I added environmental variables in my project and now the build is failing. Could you elaborate a bit more on how to pass the environmental variables to the container? Thanks a lot!

Collapse
 
j_a_o_v_c_t_r profile image
João Victor Martins

Great article, man. Help me a lot. =)

Collapse
 
ddgroleau profile image
Dan Groleau

Very helpful, thanks a lot!