How can I see the changes I make to a Go app running in Heroku local? - go

I admit I'm a GoLang newbie. In an attempt to learn Go, I developed an app about a year ago (based on the Heroku Getting started repository) and deployed it to Heroku. I used the heroku local server to develop it locally and deployed it successfully. Now I want to make some changes but I don't have the original source, so I have cloned the app from the Heroku repository.
I have got it running locally with the following steps:
export GOPATH=~/project_path
export GOBIN=$GOPATH/bin
go get
go install
heroku local
So far, so good. The problem is that when I make a simple change to the code in main.go, it doesn't show up in the browser. I've tried running go install and restarting the server after making the change but it makes no difference.
I've noticed that the file name in the Procfile is now incorrect (go-getting-started instead of the name of my project folder) but the server still runs and changing the name doesn't make any difference, locally at least. Same goes for the Dockerfile.
What am I doing wrong please?

Every time you make a change to a Go file in the project you need to run go install and stop and restart the heroku local server.
You might want to just run the server yourself with PORT=5000 go run main.go so that you only have to restart one thing. Or you can check out something like https://github.com/pilu/fresh which will listen to filesystem changes and restart your server for you.

Related

Laravel Sail Docker Hub

I've got laravel sail which as I know is few containers (mysql, redis, laravel, ...). Is there an easy way to just pack up the whole thing to ex. Docker Hub and easly download it on production server, and when i update it on localhost and run docker push, just run docker pull. Then everything (like new commands in DockerFile | apt install thing) will be updated and working exacly how it worked on localhost
I read the documentation, but I cannot figure out how docker works and how to easly change project location (Ex. I'm working on project at work, sometimes at home and this will be much easier to run docker push when I need build source code and deploy it)
I'm keeping source code on github, and it's working for dev servers, but to deploy something I have to check all dependencies and DockerFile, .env file and other things to make it works on production.
Thanks for help!
You can use the existing docker-compose.yml and just run docker-compose up -d on production to start all containers. Just be sure to for example disable xdebug on production as it slows down every request.

Problem with deploying Go app to Google App Engine

I developed my first Go app and decided to deploy it to Google Cloud (App Engine). It was running perfectly fine locally but I run into a few issues during the deployment (I'm using Cloud SDK).
I eventually got to the point where I was able to successfully deploy it to GCP but I keep getting
when trying to access the app.
I cannot do any local development either because every time I run go run main.go, go get -u, go build I'm getting:
go: finding module for package github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/mysql
go: found github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/mysql in github.com/GoogleCloudPlatform/cloudsql-proxy v0.0.0-20200513164142-a9864b03c326
go: github.com/GoogleCloudPlatform/cloudsql-proxy#v0.0.0-20200513164142-a9864b03c326 requires
cloud.google.com/go#v0.56.0 requires
cloud.google.com/go/bigquery#v1.4.0 requires
cloud.google.com/go#v0.52.0 requires
cloud.google.com/go/bigquery#v1.0.1/go.mod: verifying module: cloud.google.com/go/bigquery#v1.0.1/go.mod: cannot authenticate record data in server response
My go.mod file looks like this:
module swanson
go 1.14
require github.com/gorilla/mux v1.7.4
and this is the structure of my app (main.go, models, and router are 3 different packages):
I'm new to Go development and never deployed a Go app to GCP so feeling quite lost, any help would be much appreciated.
I have tried deploying a go application in app engine and also running it locally and both worked.
I used
this application
in github, which you can clone with the command:
git clone https://github.com/GoogleCloudPlatform/golang-samples
The command I have used for running the application locally is :
go run helloworld.go
And the command returned the following message:
2020/05/22 11:34:16 Defaulting to port 8080
2020/05/22 11:34:16 Listening on port 8080
Then in the Cloud Shell I have opened the web preview in the port 8080 and it was working as expected.
For more information about the deployment, you can check this documentation.

Parse Dashboard - works locally, blank on Heroku

I am running Parse dashboard locally - works fine
Deployed to Heroku (see references below) - it runs but does now load anything (blank screen). No errors in the log - app is up and running.
I have tried to deploy based on the following links:
Stackoverflow
Codementor
The issues came down to the bundles/ directory not being pushed correctly to git (and thus Heroku).
Make sure you run 'npm install' on your local directory
Make sure you add/commit the entire directory to git.

Simple docker deployment tactics

Hey guys so I've spend the past few days really digging into Docker and I've learned a ton. I'm getting to the point where I'd like to deploy to a digitalocean droplet but I'm starting to wonder about the strategy of building/deploying an image.
I have a perfect Dev setup where I've created a file volume tied to my app.
docker run -d -p 80:3000 --name pug_web -v $DIR/app:/Development test_web
I'd hate to have to run the app in production out of the /Development folder, where I'm actually building the app. This is a nodejs/express app and I'd love to concat/minify/etc. into a local dist folder ane add that build folder to a new dist ready image.
I guess what I'm asking is, A). can I have different dockerfiles, one for Dev and one for Dist? if not B). can I have if statements in my docker files that would do something like... if ENV == 'dist' add /dist... etc.
I'm struggling to figure out how to move this from a Dev environment locally to a tightened up production ready image without any conditionals.
I do both.
My Dockerfile checks out the code for the application from Git. During development I mount a volume over the top of this folder with the version of the code I'm working on. When I'm ready to deploy to production, I just check into Git and re-build the image.
I also have a script that is executed from the ENTRYPOINT command. The script looks at the environment variable "ENV" and if it is set to "DEV" it will start my development server with debugging turned on, otherwise it will launch the production version of the server.
Alternatively, you can avoid using Docker in development, and instead have a Dockerfile at the root of your repo. You can then use your CI server (in our case Jenkins, but Dockerhub also allows for automated build repositories that can do that for you, if you're a small team or don't have access to a dedicated build server.
Then you can just pull the image and run it on your production box.

Deploying Django to Heroku using a Windows machine (Production server NOT development server)

I use a Windows machine and have a Django project that I have successfully deployed to Heroku, albeit using the development server. To use a production server Heroku seems to require 'Gunicorn' which does not run on Windows.
This is not good for testing locally before deploying. Does anyone know of any way to get around this? Perhaps some way to use a different server on Heroku?
I found a solution that may help when deploying to heroku using a Windows machine. Here is what I do:
Use the development server locally with:
python manage.py runserver
Install and add 'Gunicorn' to your installed apps in settings.py.
Add a process file in the root directory that tells heroku to use the Gunicorn server. This is a file called 'Procfile' with the following code:
web: python kalail/manage.py run_gunicorn --bind=0.0.0.0:$PORT
This way you test using the development server, while heroku uses the Gunicorn server. Make sure you set up serving static files(css/js/imgs) after this, because only the development server automatically serves static files, and the Gunicorn server will need to be configured to do so.
You can run the development server locally quite easily:
> python manage.py runserver
All you need to do is specify path to wsgi script from root directory:
$web: gunicorn hellodjango.wsgi

Resources