How to toggle worker dynos on/off using Heroku CLI - heroku

I have this dynos in my Heroku application :
worker: node app.js
How do I turn it off / on using the Heroku CLI ?

Nevermind, found it.
$ heroku ps:scale worker=1 -a my-application to start it
$ heroku ps:scale worker=0 -a my-application to stop it

Related

How to deploy staging env using a docker container on Heroku

I use to deploy docker-compose on heroku.
like this command↓
heroku container:login
heroku container:push web
heroku container:release web
heroku open
And, I am trying to add a staging environment. What commands can I use to deploy to the staging environment?
I would like to deploy a docker container to the staging environment in the same way as the prod environment.
Thank you.

Deploy Existing Docker Image To Heroku

I am unable to deploy an existing docker image to Heroku.
Image
docker run -it --name xp-home enonic/xp-home
docker run -d -p 8080:8080 --volumes-from xp-home --name xp-app enonic/xp-app
The steps I took to do it.
heroku login
sudo heroku container:login
sudo docker tag dpd-image registry.heroku.com/hidden-mountain-63983/web
sudo docker push registry.heroku.com/hidden-mountain-63983/web
heroku open -a hidden-mountain-63983
What Am I doing wrong here?
Thank you in advance
I'll answer this for others that might have the same question.
As per the Heroku Container Registry & Runtime (Docker Deploys) documentation, you need to release the image. In your case
heroku container:release registry.heroku.com/hidden-mountain-63983/web

How can I expose the dynamic $PORT from Heroku in a Dockerfile?

How can I expose the dynamic $PORT from Heroku in a Dockerfile?
I push my docker container with heroku container:push web --app=... to Heroku, this works.
In there Heroku logs however I read this: heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch, I interpret this as if the port from my Dockerfile can't be exposed through Heroku.
No documentation can be found about this. How can I expose my Docker port to the Heroku port?
This is my Dockerfile:
FROM alpine:3.3
ADD binary_file .
EXPOSE 37780
CMD ["./binary_file"]
I don't think you can (isn't the port dynamic?).
I think you are supposed to use the PORT environment variable in your app (ie, your app has to bind to that port inside the container).
Supposing your app would start the python http server, your CMD should be something like this:
CMD ["sh", "-c", "/usr/bin/python -m SimpleHTTPServer ${PORT}"]

Kubernetes Installation with Vagrant & CoreOS and insecure Docker registry

I have followed the steps at https://coreos.com/kubernetes/docs/latest/kubernetes-on-vagrant.html to launch a multi-node Kubernetes cluster using Vagrant and CoreOS.
But,I could not find a way to set an insecure docker registry for that environment.
To be more specific, when I run
kubectl run api4docker --image=myhost:5000/api4docker:latest --replicas=2 --port=8080
on this set up, it tries to get the image thinking it is a secure registry. But, it is an insecure one.
I appreciate any suggestions.
This is how I solved the issue for now. I will add later if I can automate it on Vagrantfile.
cd ./coreos-kubernetes/multi-node/vagrant
vagrant ssh w1 (and repeat these steps for w2, w3, etc.)
cd /etc/systemd/system/docker.service.d
sudo vi 50-insecure-registry.conf
add below line to this file
[Service]
Environment=DOCKER_OPTS='--insecure-registry="<your-registry-host>/24"'
after adding this file, we need to restart the docker service on this worker.
sudo systemctl stop docker
sudo systemctl daemon-reload
sudo systemctl start docker
sudo systemctl status docker
now, docker pull should work on this worker.
docker pull <your-registry-host>:5000/api4docker
Let's try to deploy our application on Kubernetes cluster one more time.
Logout from the workers and come back to your host.
$ kubectl run api4docker --image=<your-registry-host>:5000/api4docker:latest --replicas=2 --port=8080 —env="SPRING_PROFILES_ACTIVE=production"
when you get the pods, you should see the status running.
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
api4docker-2839975483-9muv5 1/1 Running 0 8s
api4docker-2839975483-lbiny 1/1 Running 0 8s

ssh: connect to host heroku.com port 22: Connection timed out

I am working on Ubuntu 11.10
Local branch of my git-repo is up to date
I then wrote following command in terminal: heroku create --stack cedar and it said:
Notice: on Wed, 20 June, our default stack will change to Cedar. http://bit.ly/Lh0rM5
Creating radiant-wind-7413... done, stack is cedar
http://radiant-wind-7413.herokuapp.com/ | git#heroku.com:radiant-wind-7413.git
Git remote heroku added
All fine till now, then I typed following in terminal:
git push heroku master
and the following error occured:
ssh: connect to host heroku.com port 22: Connection timed out
fatal: The remote end hung up unexpectedly
As of November 30, 2021, the SSH Git Transport feature has been deprecated by Heroku and only HTTP transport is supported. The real shutdown of SSH was in March 2022.
You have to reconfigure the repo with :
heroku git:remote -a <app-name>
Official statement from Heroku
If you are using a remote with a different name, e.g. production then use
heroku git:remote -a <app-name> -r <remote-name>
Maybe you will have to unset ssh connections on git global config :
git config --global --unset url.ssh://git#heroku/.insteadof
git config --global --unset url.ssh://git#heroku.com/.insteadof
Most probably some sort of firewall issue or your network admin has blocked outgoing port 22 in your network.
You may use simple scrip to see your connection to Heroku by :
$ ssh -vvv git#heroku.com
If you seeing connect timed out then you may need to request your admin to unblock port 22. Alternatively may access Heroku via tunneling as per my answer in Connecting to heroku using port 443
I had the similar problem with keys. Ok this is what I did.
Check the status of your keys with
heroku keys
It shows you list of keys that are added to heroku. You can always generate new keys and add them to heroku.
ssh-keygen -t rsa
Generates new key.
heroku keys:add
adds the keys to heroku. Before adding it lists the available keys that you can add. Enter the option and you key is added to heroku.
This article can be helpful. If that doesn't work then there should be some problem with ssh. Try doing an ssh localhost and see if ssh is working.
Today Heroku uses git over ssh. The default port for ssh is 22 and it looks like your network doesn't allow outbound connections to port 22. Perhaps this is something your network administrator can change.
I had been working on this for hours trying to figure out how I could suddenly have a closed port 22, etc. when literally 5 hours ago everything was working and nothing had changed.
Finally I just reset my Git repo on Heroku and repushed everything. Still no idea what happened.
heroku plugins:install heroku-repo
heroku repo:reset --app appname
Do following steps.
ssh-keygen -t rsa
heroku keys:add
heroku keys # lists keys
For me helped destroying whole app and recreating again - leaving it here for future reference.
heroku apps:destroy appname
heroku apps:create appname
heroku git:remote -a appname
git push heroku master
I added the https url to the .git/config file in my project folder. I found the HTTPS URL in the project Settings on Heroku. I then added that URL to replace the SSH url inside the .git/config text file.

Resources