Skip to content

Commit 884f84c

Browse files
Merge pull request #87 from servian/rice
Asset bundling.
2 parents 2ed9d91 + b808495 commit 884f84c

File tree

13 files changed

+93
-60
lines changed

13 files changed

+93
-60
lines changed

.circleci/config.yml

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
name: Setup
2929
command: |
3030
go get -v -t -d ./...
31+
go get github.com/GeertJohan/go.rice/rice
3132
mkdir output
3233
go build -ldflags="-s -w" -a -v -o TechChallengeApp .
3334
ls
@@ -47,9 +48,12 @@ jobs:
4748
mkdir -p dist
4849
4950
go build -ldflags="-s -w" -a -v -o TechChallengeApp .
50-
51+
52+
pushd ui
53+
rice append --exec ../TechChallengeApp
54+
popd
55+
5156
cp TechChallengeApp dist/
52-
cp -r assets dist/
5357
cp conf.toml dist/
5458
5559
rm TechChallengeApp
@@ -72,11 +76,14 @@ jobs:
7276
mkdir -p dist
7377
7478
go build -ldflags="-s -w" -a -v -o TechChallengeApp .
75-
79+
80+
pushd ui
81+
rice append --exec ../TechChallengeApp
82+
popd
83+
7684
cp TechChallengeApp dist/
77-
cp -r assets dist/
7885
cp conf.toml dist/
79-
86+
8087
rm TechChallengeApp
8188
8289
export version=$(cat versionfile)
@@ -101,11 +108,14 @@ jobs:
101108
mkdir -p dist
102109
103110
go build -ldflags="-s -w" -a -v -o TechChallengeApp.exe .
104-
111+
112+
pushd ui
113+
rice append --exec ../TechChallengeApp.exe
114+
popd
115+
105116
cp TechChallengeApp.exe dist/
106-
cp -r assets dist/
107117
cp conf.toml dist/
108-
118+
109119
rm TechChallengeApp.exe
110120
111121
export version=$(cat versionfile)
@@ -126,11 +136,14 @@ jobs:
126136
mkdir -p dist
127137
128138
go build -ldflags="-s -w" -a -v -o TechChallengeApp.exe .
129-
139+
140+
pushd ui
141+
rice append --exec ../TechChallengeApp.exe
142+
popd
143+
130144
cp TechChallengeApp.exe dist/
131-
cp -r assets dist/
132145
cp conf.toml dist/
133-
146+
134147
rm TechChallengeApp.exe
135148
136149
export version=$(cat versionfile)

Dockerfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ RUN dir=$(mktemp -d) \
1212
&& mv /tmp/swagger-ui-$SWAGGER_UI_VERSION /tmp/swagger \
1313
&& sed -i 's#"https://petstore\.swagger\.io/v2/swagger\.json"#"./swagger.json"#g' /tmp/swagger/dist/index.html
1414

15+
RUN go get github.com/GeertJohan/go.rice/rice
16+
1517
WORKDIR $GOPATH/src/github.com/servian/TechChallengeApp
1618

1719
COPY go.mod go.sum $GOPATH/src/github.com/servian/TechChallengeApp/
@@ -20,18 +22,18 @@ RUN go mod tidy
2022

2123
COPY . .
2224

23-
RUN go build -ldflags="-s -w" -a -o /TechChallengeApp
24-
RUN swagger generate spec -o /swagger.json
25+
RUN CGO_ENABLED="0" go build -ldflags="-s -w" -a -o /TechChallengeApp
26+
RUN swagger generate spec -o /swagger.json \
27+
&& cp /swagger.json ui/assets/swagger/ \
28+
&& cp -R /tmp/swagger/dist ui/assets/swagger
29+
30+
RUN cd ui && rice append --exec /TechChallengeApp
2531

2632
FROM alpine:latest
2733

2834
WORKDIR /TechChallengeApp
2935

30-
COPY assets ./assets
3136
COPY conf.toml ./conf.toml
32-
33-
COPY --from=build /tmp/swagger/dist ./assets/swagger
34-
COPY --from=build /swagger.json ./assets/swagger/swagger.json
3537
COPY --from=build /TechChallengeApp TechChallengeApp
3638

3739
ENTRYPOINT [ "./TechChallengeApp" ]

build.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ mkdir -p dist
88

99
go mod tidy
1010

11-
go build -ldflags="-s -w" -a -v -o TechChallengeApp .
11+
CGO_ENABLED="0" go build -ldflags="-s -w" -a -v -o TechChallengeApp .
12+
13+
pushd ui
14+
rice append --exec TechChallengeApp
15+
popd
1216

1317
cp TechChallengeApp dist/
14-
cp -r assets dist/
1518
cp conf.toml dist/
1619

1720
rm TechChallengeApp

cmd/root.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@
2121
package cmd
2222

2323
import (
24-
"fmt"
25-
"os"
24+
"fmt"
25+
"os"
2626

27-
"github.com/servian/TechChallengeApp/config"
28-
"github.com/servian/TechChallengeApp/daemon"
29-
"github.com/spf13/cobra"
27+
"github.com/servian/TechChallengeApp/config"
28+
"github.com/servian/TechChallengeApp/daemon"
29+
"github.com/spf13/cobra"
3030
)
3131

3232
var cfgFile string
3333
var cfg *daemon.Config
3434

3535
// rootCmd represents the base command when called without any subcommands
3636
var rootCmd = &cobra.Command{
37-
Use: "TechChallengeApp",
38-
Short: "Application used to test potential candidates at Servian",
39-
Long: `
37+
Use: "TechChallengeApp",
38+
Short: "Application used to test potential candidates at Servian",
39+
Long: `
4040
.:ooooool, .:odddddl;. .;ooooc. .l, ;c. ::. 'coddddoc' ,looooooc.
4141
'kk;....';, .lOx:'...,cxkc. .dOc.... .xO' ,0d. .kk. ,xko;....;okx, .xkl,....;dOl.
4242
:Xl .xO, :0d. ;Kl ,0o .dO' .kk. :0d. .d0: .xO' lK:
@@ -50,37 +50,37 @@ var rootCmd = &cobra.Command{
5050
This application is used as part of challenging potential candiates at Sevian.
5151
5252
Please visit http://Servian.com for more details`,
53-
Version: "0.8.0",
53+
Version: "0.8.0",
5454
}
5555

5656
// Execute adds all child commands to the root command and sets flags appropriately.
5757
// This is called by main.main(). It only needs to happen once to the rootCmd.
5858
func Execute() {
59-
if err := rootCmd.Execute(); err != nil {
60-
fmt.Println(err)
61-
os.Exit(1)
62-
}
59+
if err := rootCmd.Execute(); err != nil {
60+
fmt.Println(err)
61+
os.Exit(1)
62+
}
6363
}
6464

6565
func init() {
66-
cobra.OnInitialize(initConfig)
66+
cobra.OnInitialize(initConfig)
6767
}
6868

6969
// initConfig reads in config file and ENV variables if set.
7070
func initConfig() {
71-
conf, err := config.LoadConfig()
71+
conf, err := config.LoadConfig()
7272

73-
if err != nil {
74-
fmt.Print(err)
75-
os.Exit(1)
76-
}
73+
if err != nil {
74+
fmt.Print(err)
75+
os.Exit(1)
76+
}
7777

78-
cfg = &daemon.Config{}
79-
cfg.UI.DB.DbName = conf.DbName
80-
cfg.UI.DB.DbPassword = conf.DbPassword
81-
cfg.UI.DB.DbUser = conf.DbUser
82-
cfg.UI.DB.DbHost = conf.DbHost
83-
cfg.UI.DB.DbPort = conf.DbPort
84-
cfg.ListenSpec = conf.ListenHost + ":" + conf.ListenPort
78+
cfg = &daemon.Config{}
79+
cfg.UI.DB.DbName = conf.DbName
80+
cfg.UI.DB.DbPassword = conf.DbPassword
81+
cfg.UI.DB.DbUser = conf.DbUser
82+
cfg.UI.DB.DbHost = conf.DbHost
83+
cfg.UI.DB.DbPort = conf.DbPort
84+
cfg.ListenSpec = conf.ListenHost + ":" + conf.ListenPort
8585

8686
}

cmd/updatedb.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"fmt"
2525
"os"
2626

27-
2827
"github.com/servian/TechChallengeApp/db"
2928
"github.com/spf13/cobra"
3029
)

daemon/deamon.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,16 @@ func Run(cfg *Config) error {
5454
}
5555

5656
func waitForSignal() {
57-
ch := make(chan os.Signal)
58-
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
59-
s := <-ch
60-
log.Printf("Got signal: %v, exiting.", s)
57+
xsig := make(chan os.Signal)
58+
signal.Notify(xsig, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
59+
hsig := make(chan os.Signal)
60+
signal.Notify(hsig, syscall.SIGHUP)
61+
for {
62+
select {
63+
case s := <-xsig:
64+
log.Fatalf("Got signal: %v, exiting.", s)
65+
case s := <-hsig:
66+
log.Printf("Got signal: %v, continue.", s)
67+
}
68+
}
6169
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.14
44

55
require (
66
github.com/BurntSushi/toml v0.3.1 // indirect
7-
github.com/davecgh/go-spew v1.1.1 // indirect
7+
github.com/GeertJohan/go.rice v1.0.2
88
github.com/fsnotify/fsnotify v1.4.7 // indirect
99
github.com/gorilla/context v1.1.1 // indirect
1010
github.com/gorilla/mux v1.6.2

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
22
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3+
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
4+
github.com/GeertJohan/go.rice v1.0.2 h1:PtRw+Tg3oa3HYwiDBZyvOJ8LdIyf6lAovJJtr7YOAYk=
5+
github.com/GeertJohan/go.rice v1.0.2/go.mod h1:af5vUNlDNkCjOZeSGFgIJxDje9qdjsO6hshx0gTmZt4=
6+
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
7+
github.com/daaku/go.zipexe v1.0.0 h1:VSOgZtH418pH9L16hC/JrgSNJbbAL26pj7lmD1+CGdY=
8+
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
39
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
410
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
511
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -13,12 +19,14 @@ github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce h1:xdsDDbiBDQTKASoGE
1319
github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w=
1420
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
1521
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
22+
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
1623
github.com/lib/pq v0.0.0-20180327071824-d34b9ff171c2 h1:hRGSmZu7j271trc9sneMrpOW7GN5ngLm8YUZIPzf394=
1724
github.com/lib/pq v0.0.0-20180327071824-d34b9ff171c2/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
1825
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
1926
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
2027
github.com/mitchellh/mapstructure v0.0.0-20180715050151-f15292f7a699 h1:KXZJFdun9knAVAR8tg/aHJEr5DgtcbqyvzacK+CDCaI=
2128
github.com/mitchellh/mapstructure v0.0.0-20180715050151-f15292f7a699/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
29+
github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc=
2230
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
2331
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
2432
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -38,6 +46,8 @@ github.com/spf13/viper v1.0.2/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7Sr
3846
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
3947
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
4048
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
49+
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
50+
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
4151
golang.org/x/sys v0.0.0-20180724212812-e072cadbbdc8 h1:7T3bTJEttnfJdEY+NY/VYT7IXRaul8potWiyw/n7LB8=
4252
golang.org/x/sys v0.0.0-20180724212812-e072cadbbdc8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
4353
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)