I'm using docker containers for some of my golang web service projects and part of the development workflow is using goconvey for some fast tdd feedback. I'd like to spin this up within a docker container and expose the port to the host machine so I can point my web browser to it and get coding.
We have compiled the goconvey binary and have popped it in /usr/local/bin
The problem is that whenever I connect to the port exposed form the docker container I only get "404 Page not found" errors.
There are a few tweaks we have with out GOPATH specifically I'm vendoring my libs eg GOPATH=/proj-dir/vendor and code dev is happening in /src
I can get goconvey working nicely on my host but in the docker i'm stumped.
The 404 suggest that I'm hitting the goconvey server but it does not serve up anything?
Any assistance appreciated.
The goconvey server returns 404 when it cannot find the directory that contains the static resources.
The location of this directory depends on where go get stored the goconvey files, usually in
$GOPATH/src/github.com/smartystreets/goconvey
So in your docker container, ensure that goconvey is installed using the current $GOPATH value, and also verify that the /goconvey dir contains /web/client/... subdirectories, which is where the html, css, and js files for the Web UI reside.
(To test this, I renamed the client dir, which caused goconvey to return a plain 404 message.)
Related
I am working on a compiled Golang server that displays a home page, and upload page, and a file repository. It can also upload a file to its backend. The goal is to put this into a container and use it.
Code: https://github.com/thatMacAdmin/go-webserver
If I do the following on my local machine:
go run webserver.go
Then it works as expected. The page in /static/index.html loads. I can upload files etc (as long as the repo exists in the right location). However when I build this and put it in a docker container, the repo file list works, and the upload endpoint exists, however the two static html pages get 404 errors.
What am I doing wrong? Why doesn't http://localhost:8080 work to display my home page in the container but it does work with the go run method?
Thanks,
Ed
The issue here was that Docker uses / as its relative path unless you tell it otherwise. In this instance my code expected the relative path to be where my server binary was located. In my case:
/server
Setting the WORKDIR option correctly in my Dockerfile fixed this.
Example:
FROM alpine:latest
RUN mkdir -p /server/static
COPY webserver /server
COPY static /server/static
WORKDIR /server
ENTRYPOINT ["/server/webserver"]
EXPOSE 8080
The static files are not automatically included in your binary. So you need to make sure that the running application working directory (even if it is running within a docker container) contains the folder "static" and its files. Otherwise the file is not found and you get an 404.
One alternative to this is to compile the static files into your binary. You can use gofiles for this.
I followed the instructions on the official Dockerhub repo for IIS (https://hub.docker.com/_/microsoft-windows-servercore-iis), but running into "Site can't be reached" when trying to access via the IP of the container.
I get 403 forbidden when I try htp://localhost:8000.
I copied a test.html page into C:/inetpub/wwwroot and verified by logging into the container as well.
The results of appcmd list site is as follows:
SITE "Default Web Site" (id:1,bindings:http/*:80:,state:Started)
403 typically indicates that the web address we are trying to access is not the root directory of the website.
I doubt if there exist any files, which have been copied to the remote docker container.
Please make sure that the directory where the dockerfile is located contains the content folder and contains all site files.
WORKDIR /inetpub/wwwroot
COPY content/ .
Feel free to let me know if the problem persists.
You are right in your analysis. What i didn't realize is IIS perhaps serves index.html as default and my file was called helloworld.html which obviously wasn't going to be to served when i access localhost:8000; it works when i try localhost:8000/helloworld.html.
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.
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.
I am attempting to deploy my first web application (a version of Telescope from the MeteorJS framework) via Heroku to a custom subdomain from a Amazon Linux AMI 2013.09.2 instance. I am following along with this tutorial - http://satishgandham.com/2013/12/a-complete-guide-to-install-production-ready-telescope-on-your-own-server/ - but once I attempt to run Telescope using PORT=3000 MONGO_URL=mongodb://localhost:3000/Telescope ROOT_URL=http://ec2-54-193-42-229.us-west-1.compute.amazonaws.com node client/main.js, I receive this error message: Error: Cannot find module '/home/ec2-user/bundle/programs/server/node_modules/fibers/client/main.js'
What I have attempted to do to solve this problem is performed cp || mv on the file main.js which is originally located in the ~/Telescope/client directory over to /home/ec2-user/bundle/programs/server directory and even '/home/ec2-user/bundle/programs/server/node_modules/fibers but I cannot seem to separate main.js from the /client directory. I am not sure if that is the issue or if there is some other underlying problem but I want to find a work around to using a proxy server at this point. I thought that moving the main.js file out of the /client directory was sufficient but apparently not. I am not sure it is imperative for my purposes to continue attempting to use a proxy but if there is a fix, I would not mind learning about it.
Or if any one could direct me on how this - https://github.com/aldeed/deploymeteor/ - could be a potential work-around to using an NGINX server proxy your help would be much appreciated.
You are getting the error because you are not running the command from your home folder.
You were at bundle/programs/server/node_modules/fibers.
Either use absolute path for client/main.js, or cd to ~
MONGO_URL=mongodb://localhost:3000/Telescope ROOT_URL=http://ec2-54-193-42-229.us-west-1.compute.amazonaws.com node client/main.js
PS: It will be helpful for others if you asked the question on the post itself, instead of here