[FYI - I am not looking to upgrade our Heroku account to Enterprise to take advantage of app grouping. We are a small team]
I am a collaborator on a heroku app. I was tasked with setting up dev-staging-production environments for the app and I am getting confused on how to setup Auto Deploy correctly with the GitHub-Heroku integration guide. I have been already given admin access to the original git repo.
From the 'owner' account on the production app I created two separate apps (dev and staging).
Now, I have 3 apps that I am a collaborator of:
(1) app.domain.com
(2) app-dev.domain.com
(3) app-staging.domain.com
I have created 3 remotes pointing to the 3 generated heroku-git repos:
live
dev
staging
I can push to the 3 Heroku apps easily by:
git push live master
git push dev master
git push staging master
BUT I want to setup auto-deploy for dev-staging apps.
I have pushed an "auto" branch onto dev and staging remote. My intention is for Heroku to detect pushes to that branch and "auto" deploy the code. But, heroku only detects pushes to "master" branch afaik.
git push dev release auto
git push staging release auto
But when I go to administer the Heroku dev-staging apps I only see the "master" branch in the Auto-deploy section. Shouldn't I also see the "auto" branch? Is the reason I am not seeing it because I didn't push auto as a remote branch on the ORIGINAL git repo? In which case, how do I structure this stuff as code lives in 2 separate environments (Heroku repo and GitHub repo)?
Ultimately, the plan is to setup some form of Continuous Integration and get tests run before releases happen across the dev-staging-production zones.
Am I overthinking this or is there a better way to get this stuff working? Appreciate it!
Heroku only tracks changes on the remote master Branch.
https://devcenter.heroku.com/articles/git#deploying-from-a-branch-besides-master
To push your dev branch to the Heroku master remote branch:
git push dev release:master
You may need to use the -f flag to force push (be careful!)
I think auto deploy on Heroku works only on default branch (usually named master), and you probably want to look into Heroku feature called pipelines. I've not used it myself yet and it's in beta stage, but it sounds like exactly what you're looking for. Not sure if I read it right, but it sounds like you created 3 individual projects, instead of branches in 1 project? How do you manage moving changes from one stage to another?
As for the CI setup I guess it depends on the kind of testing you're doing and the workflow. I'm in the middle of creating such process in my workplace, and what I will be proposing is as follows:
Devs develop and test on their local machines on feature branches before commiting and merging onto DEV branch
Commiting or merging onto the DEV branch triggers CI server, runs the build and perform PHPUnit and Behat tests
Successful build is being deployed to a server (possibly Heroku or any hosting provider that will support automated deployments) for QA.
Once tested and approved we can move the code onto STAGING branch repeat CI proccess and on success move to MASTER and go live.
We're using gilab.com to host our project and perform tests (CI server is included as standard even with free account), deploy dev and staging state for QA to Heroku, and finally host live version with a dedicated enterprise level provider.
Related
I am investigating adding an app.json file to my heroku pipeline to enable review apps.
Heroku offers the ability to generate one from your existing app setup, but I do not see any way to prevent it from automatically committing it to our repository's master branch.
I need to be able to see it before it gets committed to the master branch because we require at least two staff members to review all changes to the master branch (which triggers an automatic staging build) for SOC-2 security compliance.
Is there a way that I can see what it would generate without committing it to the repository?
I tried forking the repo and connecting the fork to it's own pipeline, but because it did not have any of our heroku add-ons or environment, it would not work for our production pipeline.
I am hesitant to just build the app.json file manually - it seems more prone to error. I would much prefer to get the automatically generated file and selectively remove items.
As a punchline to this story, I ended up investing enough time into the forked repository on it's own pipeline to demonstrate a POC
When you generate your app.json file, it should take you to a secondary screen that has the full app.json in plaintext at the bottom.
Why not open a PR with its contents in your project root. Once it's detected on the repository Heroku shouldn't ask you to regenerate it again.
Background: I have a project deployed to heroku. The heroku app is connected with github so I can press the "deploy" button from heroku's web api to manually deploy a branch on github to heroku.
What I'm trying to do is build a slack bot that will let me accomplish that via a slack command. Ideally, there'd be some function on heroku's platform api like .deploy('my_app', 'some_branch_on_github), but I can't seem to find it.
The platform api's build feature is close. That function lets you provide the public url of a tarball that heroku will then deploy. However, my github repo isn't public, so that doesn't work. A private repo shouldn't be a problem, though, since heroku's already connected to my github repo.
TLDR: How can I programmatically tell Heroku to deploy my app from a private github it's connected to?
I got a response from Heroku's support team asking pretty much the same question. Their answer was that what I'm trying to do is not possible, but will be at some point (although not in the next few months, anyway).
They suggested that I could just use the undocumented web api used by heroku's own web console (a POST to an endpoint on kolkrabbi.heroku.com). They did warn that, as a private api, that's likely to change without warning.
As of April 2020, Heroku has integrated GitHub natively without recourse to any janky undocumented Icelandic endpoints.
When configured, Heroku can automatically build and release (if the build is successful) pushes to the specified GitHub repo.
Enabling GitHub integration
You can configure GitHub integration in the Deploy tab of apps in
the Heroku Dashboard.
To configure GitHub integration, you have to authenticate with GitHub.
You only have to do this once per Heroku account.
GitHub repo admin access is required for you to configure automatic
GitHub deploys. This is because Heroku has to register a service hook on
the GitHub repo, and this action requires admin access. For GitHub
organizations, your GitHub account will also need to be a member of the
organization and not an outside collaborator.
If your repo is in a GitHub organization that has third-party
application restrictions
enabled,
an organization admin needs to approve Heroku for use with the
organization. More details are available on
GitHub.
After you link your Heroku app to a GitHub repo, you can selectively
deploy from branches or configure auto-deploys.
Manual deploys
With manual deploys, you can create an immediate deployment of any
branch from the GitHub repo that’s connected to your app. Use manual
deploys if you want to control when changes are deployed to Heroku.
You can also use manual deploys to temporarily deploy a branch other
than the one that’s configured for automatic deployment. For example,
you might have a development app synced to the development GitHub
branch, but you temporarily want to test a feature branch. Simply
trigger a manual deploy of the feature branch to test it on the Heroku
app. Note that release of the feature branch is overwritten on the next
successful GitHub push to the development branch.
Automatic deploys
When you enable automatic deploys for a GitHub branch, Heroku builds and
deploys all pushes to that branch. If, for example, you have a
development app on Heroku, you can configure pushes to your GitHub
development branch to be automatically built and deployed to that app.
If you’ve configured your GitHub repo to use automated Continuous
Integration (with Travis CI, for example), you can check the “Wait for
CI to pass before deploy” checkbox. When enabled, Heroku will only
auto-deploy after all the commit statuses of the relevant commit show
success.
This commit won’t auto-deploy because one of the checks shows a
pending status:
This commit will auto-deploy because all of the checks show a status of
success:
Review apps
With review apps enabled for a Heroku app, Heroku will create temporary
test apps for each pull request that’s opened on the GitHub repo that’s
connected to the parent app. Review apps are great if you’re using
GitHub Flow to propose,
discuss, and merge changes to your code base. Because pull request
branches are deployed to new apps on Heroku, it’s very simple for you
and your collaborators to test and debug code branches. You can also run
automated integration tests on the Heroku app representing a GitHub
branch.
See the Review apps
article
for details.
Heroku CI
Once you’ve connected your GitHub repo to your Pipeline, you can turn on
Heroku CI, our
visual, low-configuration test runner that integrates easily with Heroku
Pipelines (and so complements Review apps, existing Heroku apps, and our
GitHub integrations). Any Heroku Pipeline is already Heroku CI ready –
just turn it on in the Pipeline’s Settings tab.
Links to diffs
For apps that are linked to GitHub repos, releases in the Dashboard
Activity tab will include a “View Diff” link. Following the link
will take you to the GitHub comparison view, showing the changes made
since the last release.
Disconnecting from GitHub
Terminate an obsolete GitHub connection, if necessary.
Disconnecting individual apps
Individual apps can be disconnected in the GitHub pane of the
Deploy tab for the app.
Disconnecting account
You can disconnect your Heroku and GitHub accounts in the Applications
pane on your Dashboard account
page.
My workflow encompasses the following steps:
Git push (to BitBucket or GitHub depending on the project).
BitBucket/GitHub is integrated with CodeShip, tests are run.
If tests are ok, CodeShip automatically deploys to Heroku.
Everything works fine when, by pushing to the remote repo, the deployment tasks are triggered which ends up with the new version going live when everything is ok.
My question is:
Sometimes, I simply do a git push heroku master which defeats the whole purpose of this workflow.
How can I prevent it from happening? Is there a way to make Heroku only accept the deploy when the source is CodeShip?
After looking around for quite some time, I noticed that there are a some ways to accomplish this, all of them related to simply not giving access to the Heroku Account for the developer:
If you're a single developer ("one-man / one-woman show"):
Do not add the Heroku Remote to your Git Repository. If it is already added, remove it. That way you're not going to push to it by mistake.
If you're managing a team:
Do not give the team a user/pass to access Heroku Toolbelt. That way, the only remote repo they will have access to should be GitHub/BitBucket/Whatever.
You could just create another branch called dev and push to that branch your changes and when you are ready to deploy to heroku merge changes into master branch.
I just came accross your issue and this is what i did as quickest resolution
I have deployed my REST based java application on Heroku.
Everything is working fine. However I can see code on heroku dashboard as other developers working with me also want to collaborate.
Do they need to clone .git repository given in settings page of application.
Please help how to do this ?
And how to push code to bitbucket so my code doesn't get vanished?
When you create application on Heroku it automatically gets Git repo - it's a normal repo so you colleagues can just clone it (if they're added as contributors) as you said.
To push code to bitbucket, create repo there and add it as a remote to your local git configuration. Then just push to heroku remote and bitbucket remote at will. For automated solution you can consider Github Integration: https://devcenter.heroku.com/articles/github-integration
I would like to host multiple apps: a UI app and backend / services app in one github repository and deploy each as a separate app to Heroku. Typically I create one github repo for each app. So in this case I would have a github repo for UI and another github repo for the svcs. Given that I follow the normal github / heroku deploy workflow.
Its certainly easier to create one repo for each deployable web app. But wanted to know if Has anyone done this?
Thanks in advance for any advice
TL;DR
Heroku only runs whatever is stored in its master branch, and ignores all others. You'd be better off using separate repositories, or creating a super-project for local use and pushing individual git submodules to each Heroku app separately.
If you decide to ignore best practices...
You could potentially do this by pushing alternate branches to each Heroku app's master branch. For example, you could have a UI app in one branch, and an API app in another branch. Just change to whatever branch you want to push, and then:
heroku git:remote -a appname -r ui
heroku git:remote -a appname -r api
# push the ui branch to the ui remote's master branch
git checkout ui
git push ui ui:master
# push the api branch to the api remote's master branch
git checkout api
git push api api:master
You can find additional details here.