Can't Repro
Status Update
Comments
gs...@google.com <gs...@google.com>
gs...@google.com <gs...@google.com>
yi...@gmail.com <yi...@gmail.com> #3
Hi, this error only affects Cloud SDK version 186. It was previously reported in Issue 72407295 and a fix for it should be released in Cloud SDK version 187.
In the mean time, you can downgrade to Cloud SDK version 185 as a workaround by running the following command:
gcloud components update --version 185.0.0
In the mean time, you can downgrade to Cloud SDK version 185 as a workaround by running the following command:
gcloud components update --version 185.0.0
gs...@google.com <gs...@google.com> #4
Any Go project can be installed by using go get. What happens is that go get will install packages under $GOPATH/src. This is the directory where your app directory "myapp" resides.
The document you linked to: "Migrating your App Engine app from Go 1.9 to Go 1.11", indicates that you need to change this "myapp" directory so that your main package is in a separate directory with your app.yaml file. Your final file structure should look like the following:
myapp/
bar.go
foo.go
web/
app.yaml
main.go
The document you linked to: "Migrating your App Engine app from Go 1.9 to Go 1.11", indicates that you need to change this "myapp" directory so that your main package is in a separate directory with your app.yaml file. Your final file structure should look like the following:
myapp/
bar.go
foo.go
web/
app.yaml
main.go
yi...@gmail.com <yi...@gmail.com> #5
Got it, thanks!
However, when run under dev_appserver.py, the working directory is in web/
and file paths have to be passed relative to app.yaml. Is there a way to
set the app directory in dev_appserver.py to myapp/ as well?
On Sat, Jan 26, 2019, 5:42 AM <buganizer-system@google.com> wrote:
However, when run under dev_appserver.py, the working directory is in web/
and file paths have to be passed relative to app.yaml. Is there a way to
set the app directory in dev_appserver.py to myapp/ as well?
On Sat, Jan 26, 2019, 5:42 AM <buganizer-system@google.com> wrote:
yi...@gmail.com <yi...@gmail.com> #6
I've noticed that in
`platform/google_appengine/google/appengine/tools/devappserver2/application_configuration.py`
from the gcloud root, theres' some logic for setting the application root
directory:
Line 127:
```
root = os.path.dirname(config_path)
self._is_java = os.path.normpath(config_path).endswith(
os.sep + 'WEB-INF' + os.sep + 'appengine-web.xml')
if self._is_java:
# We assume Java's XML-based config files only if config_path is
# something like /foo/bar/WEB-INF/appengine-web.xml. In this case,
# the application root is /foo/bar. Other apps, configured with
YAML,
# have something like /foo/bar/app.yaml, with application root
/foo/bar.
root = os.path.dirname(root)
self._application_root = os.path.realpath(root)
```
When app.yaml is contained in a subdirectory, this sets the root directory
to that subdirectory, in this case myapp/web.
Later, Go build is called from here, and succeeds because myapp/web is the
main package. However, the application is also started in myapp/web instead
of myapp afterwards.
How is the actual app engine environment able to determine that myapp is
the root directory? Is it similar to how the relative config location is
assumed for Java applications in the above snippet, or an entirely
different method? Could the same logic be implemented in dev_appserver?
On Sun, Jan 27, 2019 at 10:16 PM Jiayu Yi <yijiayu@gmail.com> wrote:
`platform/google_appengine/google/appengine/tools/devappserver2/application_configuration.py`
from the gcloud root, theres' some logic for setting the application root
directory:
Line 127:
```
root = os.path.dirname(config_path)
self._is_java = os.path.normpath(config_path).endswith(
os.sep + 'WEB-INF' + os.sep + 'appengine-web.xml')
if self._is_java:
# We assume Java's XML-based config files only if config_path is
# something like /foo/bar/WEB-INF/appengine-web.xml. In this case,
# the application root is /foo/bar. Other apps, configured with
YAML,
# have something like /foo/bar/app.yaml, with application root
/foo/bar.
root = os.path.dirname(root)
self._application_root = os.path.realpath(root)
```
When app.yaml is contained in a subdirectory, this sets the root directory
to that subdirectory, in this case myapp/web.
Later, Go build is called from here, and succeeds because myapp/web is the
main package. However, the application is also started in myapp/web instead
of myapp afterwards.
How is the actual app engine environment able to determine that myapp is
the root directory? Is it similar to how the relative config location is
assumed for Java applications in the above snippet, or an entirely
different method? Could the same logic be implemented in dev_appserver?
On Sun, Jan 27, 2019 at 10:16 PM Jiayu Yi <yijiayu@gmail.com> wrote:
gs...@google.com <gs...@google.com> #7
Working directory is supposed to be in web/ if you use Go 1.11. Did you notice a different behavior? If so, in which way, exactly? A detailed description, preferably in step-by-step format, would be appreciated.
This Public Issue Tracker is meant to keep track of issues related to Cloud Platform. Questions on coding and programming of a general nature, without direct bearing to any actual issue, and related rather to your interests, will get more attention and attract valuable answers in forums such as stackoverflow, where programmers are active and willing to give advice.
This Public Issue Tracker is meant to keep track of issues related to Cloud Platform. Questions on coding and programming of a general nature, without direct bearing to any actual issue, and related rather to your interests, will get more attention and attract valuable answers in forums such as stackoverflow, where programmers are active and willing to give advice.
Description
Problem you have encountered:
I would like to
1. Structure my application as described in the article "Migrating your App Engine app from Go 1.9 to Go 1.11" under "Structuring your files" (
myapp/
|- bar.go
|- foo.go
|- web/
|-app.yaml
|- main.go
2. Reference the files in my application at runtime. Given the following directory structure,
```
myapp/
|- data1.json
|- index1.html
|- foo.go
|- go.mod
|- go.sum
|- web/
|- app.yaml
|- main.go
|- data.json
|- index.html
```
I would like to reference `web/index.html` from `web/app.yaml` and `web/data.json` from `web/main.go` like this:
In main.go, I load `data.json` using `os.Open("data.json")`
In `app.yaml`, I use
```
handlers:
- url: /$
static_files: index.html
upload: index.html
secure: always
```
to serve `web/index.html` statically under `/`.
However, at runtime, `data.json` is not found and `/` returns a 404 not found.
What you expected to happen:
I can refer to `data.json` and `index.html` relative to the location of `app.yaml`.
This is the behaviour when running under `dev_appserver web/app.yaml`.
Steps to reproduce:
Create a Go 1.11 application using Go modules for dependency management with the main package and app.yaml in a subdirectory, and try to refer to files in the same folder as the main package and app.yaml.
Sample project structure:
myapp/
|- go.mod
|- go.sum
|- version.go
|- web/
|- app.yaml
|- main.go
|- hello.txt
web/hello.txt:
```
Hello, World
```
version.go:
```
package myapp
const Version = "VERSION"
```
web/main.go
```
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
)
func handler(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadFile("hello.txt")
if err != nil {
fmt.Fprintf(w, "error reading hello.txt: %v\n", err)
} else {
fmt.Fprintf(w, "Contents of hello.txt: %s\n", string(b))
}
b, err = ioutil.ReadFile("version.go")
if err != nil {
fmt.Fprintf(w, "error reading version.go: %v\n", err)
} else {
fmt.Fprintf(w, "First line of version.go: %s\n", strings.SplitN(string(b), "\n", 2))
}
}
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "8080"
log.Printf("Defaulting to port %s", port)
}
log.Printf("Listening on port %s", port)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), http.HandlerFunc(handler)))
}
```
Output under `dev_appserver web/app.yaml`:
```
Contents of hello.txt: Hello, World
error reading goodbye.txt: open goodbye.txt: no such file or directory
```
Output when deployed:
```
error reading hello.txt: open hello.txt: no such file or directory
Contents of goodbye.txt: Goodbye, World
```
Other information (workarounds you have tried, documentation consulted, etc):
Workaround:
When deployed, the app appears to be running from the `myapp` directory instead of `myapp/web`, so I can place my files there instead.