build asar file for frontend only
This commit is contained in:
parent
b288844193
commit
5c6d5d13ae
|
@ -0,0 +1 @@
|
||||||
|
*.asar
|
|
@ -14,6 +14,7 @@ import (
|
||||||
|
|
||||||
"github.com/Xe/asarfs"
|
"github.com/Xe/asarfs"
|
||||||
"github.com/gernest/front"
|
"github.com/gernest/front"
|
||||||
|
"github.com/urfave/negroni"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Post is a single post summary for the menu.
|
// Post is a single post summary for the menu.
|
||||||
|
@ -129,21 +130,23 @@ func main() {
|
||||||
})
|
})
|
||||||
|
|
||||||
if os.Getenv("USE_ASAR") == "yes" {
|
if os.Getenv("USE_ASAR") == "yes" {
|
||||||
fe, err := asarfs.New("./frontend.asar", http.HandlerFunc(writeIndexHTML))
|
log.Println("serving site frontend from asar file")
|
||||||
|
|
||||||
|
do404 := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
http.Error(w, "Not found", http.StatusNotFound)
|
||||||
|
})
|
||||||
|
fe, err := asarfs.New("./frontend.asar", do404)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal("frontend: ", err)
|
||||||
}
|
|
||||||
st, err := asarfs.New("./static.asar", http.HandlerFunc(writeIndexHTML))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
http.Handle("/dist/", fe)
|
http.Handle("/dist/", fe)
|
||||||
http.Handle("/static", st)
|
|
||||||
} else {
|
} else {
|
||||||
|
log.Println("serving site frontend from filesystem")
|
||||||
http.Handle("/dist/", http.FileServer(http.Dir("./frontend/static/")))
|
http.Handle("/dist/", http.FileServer(http.Dir("./frontend/static/")))
|
||||||
http.Handle("/static/", http.FileServer(http.Dir(".")))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
http.Handle("/static/", http.FileServer(http.Dir(".")))
|
||||||
http.HandleFunc("/", writeIndexHTML)
|
http.HandleFunc("/", writeIndexHTML)
|
||||||
|
|
||||||
port := os.Getenv("PORT")
|
port := os.Getenv("PORT")
|
||||||
|
@ -151,7 +154,10 @@ func main() {
|
||||||
port = "9090"
|
port = "9090"
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Fatal(http.ListenAndServe(":"+port, nil))
|
n := negroni.Classic()
|
||||||
|
n.UseHandler(http.DefaultServeMux)
|
||||||
|
|
||||||
|
log.Fatal(http.ListenAndServe(":"+port, n))
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeBlogPosts(w http.ResponseWriter, r *http.Request) {
|
func writeBlogPosts(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
39
box.rb
39
box.rb
|
@ -1,22 +1,4 @@
|
||||||
from "phusion/baseimage:0.9.19"
|
from "xena/go"
|
||||||
|
|
||||||
copy "./runit/", "/etc/system/"
|
|
||||||
|
|
||||||
run %q[ curl -o backplane-stable-linux-amd64.tgz https://bin.equinox.io/c/jWahGASjoRq/backplane-stable-linux-amd64.tgz \
|
|
||||||
&& tar xf backplane-stable-linux-amd64.tgz \
|
|
||||||
&& mv backplane /usr/bin/backplane \
|
|
||||||
&& rm backplane-stable-linux-amd64.tgz ]
|
|
||||||
|
|
||||||
run %q[ cd /usr/local && curl -o go.tar.gz https://storage.googleapis.com/golang/go1.7.4.linux-amd64.tar.gz \
|
|
||||||
&& tar xf go.tar.gz && rm go.tar.gz && mkdir -p /go/src ]
|
|
||||||
env "GOPATH" => "/go"
|
|
||||||
run %q[ apt-get update && apt-get install -y git-core \
|
|
||||||
&& /usr/local/go/bin/go get github.com/gernest/front && /usr/local/go/bin/go get gopkg.in/yaml.v2 ]
|
|
||||||
|
|
||||||
run %q[ apt-get update && apt-get install xz-utils bzip2 ]
|
|
||||||
|
|
||||||
run %q[ cd /usr/local && curl -o node.tar.xz https://nodejs.org/dist/v6.9.2/node-v6.9.2-linux-x64.tar.xz \
|
|
||||||
&& tar xf node.tar.xz && mv node-v6.9.2-linux-x64 node && rm node.tar.xz ]
|
|
||||||
|
|
||||||
### Copy files
|
### Copy files
|
||||||
run "mkdir -p /site"
|
run "mkdir -p /site"
|
||||||
|
@ -28,26 +10,27 @@ end
|
||||||
files = [
|
files = [
|
||||||
"backend",
|
"backend",
|
||||||
"blog",
|
"blog",
|
||||||
"frontend/package.json",
|
"frontend.asar",
|
||||||
"frontend/bower.json",
|
|
||||||
"frontend/webpack.production.config.js",
|
|
||||||
"frontend/src",
|
|
||||||
"static",
|
"static",
|
||||||
"build.sh",
|
"build.sh",
|
||||||
"run.sh",
|
"run.sh",
|
||||||
|
|
||||||
|
# This file is packaged in the asar file, but the go app relies on being
|
||||||
|
# able to read it so it can cache the contents in ram.
|
||||||
|
"frontend/static/dist/index.html",
|
||||||
]
|
]
|
||||||
|
|
||||||
files.each { |x| put(x) }
|
files.each { |x| put x }
|
||||||
|
|
||||||
### Build
|
### Build
|
||||||
run %q[ cd /site && bash ./build.sh ]
|
run "apk add --no-cache git"
|
||||||
|
run %q[ cd /site && sh ./build.sh ]
|
||||||
|
|
||||||
### Cleanup
|
### Cleanup
|
||||||
run %q[ rm -rf /usr/local/go /usr/local/node /site/frontend/node_modules /site/frontend/bower_components /go /site/backend /tmp/phantomjs /site/frontend /site/static ]
|
run %q[ rm -rf /usr/local/go /usr/local/node /site/frontend/node_modules /site/frontend/bower_components /go /site/backend /tmp/phantomjs ]
|
||||||
run %q[ apt-get remove -y xz-utils bzip2 git-core && apt-get -y autoremove && apt-get clean ]
|
run %q[ apk del go git ]
|
||||||
|
|
||||||
### Runtime
|
### Runtime
|
||||||
entrypoint "/sbin/my_init"
|
|
||||||
cmd "/site/run.sh"
|
cmd "/site/run.sh"
|
||||||
|
|
||||||
env "USE_ASAR" => "yes"
|
env "USE_ASAR" => "yes"
|
||||||
|
|
28
build.sh
28
build.sh
|
@ -1,27 +1,19 @@
|
||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
export PATH="$PATH:/usr/local/go/bin:/usr/local/node/bin"
|
export PATH="$PATH:/usr/local/go/bin"
|
||||||
export CI="true"
|
export CI="true"
|
||||||
|
|
||||||
npm install -g asar
|
|
||||||
|
|
||||||
(cd /site/frontend
|
|
||||||
yes | npm install
|
|
||||||
npm install -g bower
|
|
||||||
yes 2 | bower install --allow-root
|
|
||||||
npm run build
|
|
||||||
asar pack static ../frontend.asar
|
|
||||||
rm -rf bower_components node_modules) &
|
|
||||||
|
|
||||||
(cd /site/backend/christine.website
|
(cd /site/backend/christine.website
|
||||||
go build
|
go get github.com/Xe/asarfs
|
||||||
|
go get github.com/gernest/front
|
||||||
|
go get layeh.com/asar
|
||||||
|
go get gopkg.in/yaml.v2
|
||||||
|
go get github.com/urfave/negroni
|
||||||
|
|
||||||
|
go build -v
|
||||||
mv christine.website /usr/bin) &
|
mv christine.website /usr/bin) &
|
||||||
|
|
||||||
(cd /site
|
|
||||||
asar pack static ./static.asar) &
|
|
||||||
|
|
||||||
wait
|
wait
|
||||||
|
|
||||||
rm -rf /usr/lib/node_modules
|
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
set -x
|
||||||
|
|
||||||
|
(cd frontend && rm -rf node_modules bower_components && npm install && npm run build && asar pack static ../frontend.asar)
|
||||||
|
|
||||||
|
box box.rb
|
2
run.sh
2
run.sh
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
|
|
||||||
cd /site
|
cd /site
|
||||||
/usr/bin/christine.website
|
/usr/bin/christine.website
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
if [ -n "$BACKPLANE_TOKEN" ]
|
|
||||||
then
|
|
||||||
/usr/bin/backplane connect
|
|
||||||
else
|
|
||||||
sleep 999d
|
|
||||||
fi
|
|
Loading…
Reference in New Issue