如何将Google App Engine(Go)项目上传到与app.yaml不同的文件夹中?

huangapple go评论95阅读模式
英文:

How to upload a Google App Engine (Go) project in a different folder than the app.yaml

问题

我的项目结构如下:

| appengine
|---- app.yaml
|---- myScript.go
| bower_components
|----|...
| build
|----|images
|----|----|branding
|----|----|---- favicon.ico
|----|styles
|----|----|*.css
|----|index.html
| src
| ...

当运行 goapp deploy appengine 时,我想要上传 build 文件夹的全部内容。

我的 app.yaml 文件如下:

application: myProject
version: 0-1
runtime: go
api_version: go1

handlers:
- url: /(.*\.(gif|png|jpg|ico|js|css))
  static_files: ../build/
  upload: ../build/(.*\.(gif|png|jpg|ico|js|css))

- url: /.*
  script: _go_app

而我的 myScript.go 文件如下:

package myProject

import (
    "fmt"
    "io/ioutil"
    "net/http"
)

func init() {
    http.HandleFunc("/", handler)
}

func handler(w http.ResponseWriter, r *http.Request) {
    site, err := ioutil.ReadFile("../build/index.html")
    
    if err != nil {
        panic(err)
    }
    
    fmt.Fprint(w, string(site))
}

当我运行 goapp serve appengine 时,网站可以正常显示。然而,当我尝试部署时,只有两个文件被克隆,即 appengine 文件夹内的文件。

英文:

My project has the following structure:

| appengine
|---- app.yaml
|---- myScript.go
| bower_components
|----|...
| build
|----|images
|----|----|branding
|----|----|---- favicon.ico
|----|styles
|----|----|*.css
|----|index.html
| src
| ...

I would like to upload the entire content of the build folder when running goapp deploy appengine.

My app.yaml looks like this:

application: myProject
version: 0-1
runtime: go
api_version: go1

handlers:
- url: /(.*\.(gif|png|jpg|ico|js|css))
  static_files: ../build/
  upload: ../build/(.*\.(gif|png|jpg|ico|js|css))

- url: /.*
  script: _go_app

and myScript.go looks like this:

package myProject

import (
    "fmt"
    "io/ioutil"
    "net/http"
)

func init() {
    http.HandleFunc("/", handler)
}

func handler(w http.ResponseWriter, r *http.Request) {
    site, err := ioutil.ReadFile("../build/index.html")
    
    if err != nil {
        panic(err)
    }
    
    fmt.Fprint(w, string(site))
}

When I run goapp serve appengine, the website displays properly. However, when I try to deploy it, it only clones two files, i.e. the ones inside the appengine folder.

答案1

得分: 2

你可以通过在所需位置的 GAE 应用目录中创建符号链接,将第三方代码文件/目录链接到 GAE 应用代码目录之外的位置,从而保留所需的应用结构。GAE 的上传/部署工具会替换符号链接,并上传符号链接指向的实际文件/目录到相应的位置。

以下是一些其他适用于 GAE 的场景,可以应用符号链接技术:

英文:

You can preserve your desired app structure with 3rd party code residing outside your GAE app code directory yet still be able to upload the 3rd party code together with your GAE app code by just symlinking the 3rd party code files/dirs inside the GAE app dir in the desired locations.

The GAE upload/deploy utilities know to replace the symlinks and upload the actual files/dirs the symlinks point to instead, in the respective locations.

Some other GAE-related scenarios in which the symlink technique can be applied:

huangapple
  • 本文由 发表于 2016年2月6日 02:25:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/35230998.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定