英文:
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 的场景,可以应用符号链接技术:
- 在 App Engine 模块之间共享实体
- 如何在 App Engine 模块之间共享文件和 HTML 模板
- 在多个 YAML 文件之间复制/跳过文件是否必要
- 如何从 Python Google App Engine 模块中访问供应商库
- 默认模块和非默认模块是否可以是 Google App Engine 应用程序的同级目录
英文:
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:
- https://stackoverflow.com/questions/34291075/sharing-entities-between-app-engine-modules/34291789#34291789
- https://stackoverflow.com/questions/33088104/how-can-i-share-files-html-templates-between-app-engine-modules/33091084#33091084
- https://stackoverflow.com/questions/33307128/do-i-need-to-copy-skip-files-across-multiple-yaml-files/33308640#33308640
- https://stackoverflow.com/questions/34973058/how-do-i-access-a-vendored-library-from-a-module-in-python-google-app-engine/34985211#34985211
- https://stackoverflow.com/questions/34110178/can-a-default-module-in-a-google-app-engine-app-be-a-sibling-of-a-non-default-mo/34111170#34111170
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论