feat(docker): test a container to check that it is still working (#346)
This commit is contained in:
parent
86630e0fc7
commit
b3bdd9b79e
|
@ -10,4 +10,8 @@ LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>"
|
|||
ADD release/linux/amd64/gorush /bin/
|
||||
|
||||
EXPOSE 8088 9000
|
||||
|
||||
HEALTHCHECK --start-period=2s --interval=10s --timeout=5s \
|
||||
CMD ["/bin/gorush", "--ping"]
|
||||
|
||||
ENTRYPOINT ["/bin/gorush"]
|
||||
|
|
|
@ -13,4 +13,7 @@ RUN apk add --no-cache ca-certificates && \
|
|||
ADD release/linux/amd64/gorush /bin/
|
||||
|
||||
EXPOSE 8088 9000
|
||||
HEALTHCHECK --start-period=2s --interval=10s --timeout=5s \
|
||||
CMD ["/bin/gorush", "--ping"]
|
||||
|
||||
ENTRYPOINT ["/bin/gorush"]
|
||||
|
|
|
@ -10,4 +10,7 @@ LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>"
|
|||
ADD release/linux/arm/gorush /bin/
|
||||
|
||||
EXPOSE 8088 9000
|
||||
HEALTHCHECK --start-period=2s --interval=10s --timeout=5s \
|
||||
CMD ["/bin/gorush", "--ping"]
|
||||
|
||||
ENTRYPOINT ["/bin/gorush"]
|
||||
|
|
|
@ -10,4 +10,7 @@ LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>"
|
|||
ADD release/linux/arm64/gorush /bin/
|
||||
|
||||
EXPOSE 8088 9000
|
||||
HEALTHCHECK --start-period=2s --interval=10s --timeout=5s \
|
||||
CMD ["/bin/gorush", "--ping"]
|
||||
|
||||
ENTRYPOINT ["/bin/gorush"]
|
||||
|
|
|
@ -10,4 +10,7 @@ LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>"
|
|||
ADD release/linux/i386/gorush /bin/
|
||||
|
||||
EXPOSE 8088 9000
|
||||
HEALTHCHECK --start-period=2s --interval=10s --timeout=5s \
|
||||
CMD ["/bin/gorush", "--ping"]
|
||||
|
||||
ENTRYPOINT ["/bin/gorush"]
|
||||
|
|
|
@ -6,4 +6,7 @@ LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
|
|||
org.label-schema.schema-version="1.0"
|
||||
|
||||
ADD release/gorush.exe /gorush.exe
|
||||
HEALTHCHECK --start-period=2s --interval=10s --timeout=5s \
|
||||
CMD ["\\gorush.exe", "--ping"]
|
||||
|
||||
ENTRYPOINT [ "\\gorush.exe" ]
|
||||
|
|
25
main.go
25
main.go
|
@ -4,6 +4,7 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
@ -19,6 +20,7 @@ func main() {
|
|||
opts := config.ConfYaml{}
|
||||
|
||||
var (
|
||||
ping bool
|
||||
showVersion bool
|
||||
configFile string
|
||||
topic string
|
||||
|
@ -56,6 +58,7 @@ func main() {
|
|||
flag.BoolVar(&opts.Ios.Production, "production", false, "production mode in iOS")
|
||||
flag.StringVar(&topic, "topic", "", "apns topic in iOS")
|
||||
flag.StringVar(&proxy, "proxy", "", "http proxy url")
|
||||
flag.BoolVar(&ping, "ping", false, "ping server")
|
||||
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
|
@ -126,6 +129,13 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
if ping {
|
||||
if err := pinger(); err != nil {
|
||||
gorush.LogError.Warnf("ping server error: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// send android notification
|
||||
if opts.Android.Enabled {
|
||||
gorush.PushConf.Android.Enabled = opts.Android.Enabled
|
||||
|
@ -270,6 +280,7 @@ Server Options:
|
|||
--proxy <proxy> Proxy URL (only for GCM)
|
||||
--pid <pid path> Process identifier path
|
||||
--redis-addr <redis addr> Redis addr (default: localhost:6379)
|
||||
--ping healthy check command for container
|
||||
iOS Options:
|
||||
-i, --key <file> certificate key file path
|
||||
-P, --password <password> certificate key password
|
||||
|
@ -290,6 +301,20 @@ func usage() {
|
|||
os.Exit(0)
|
||||
}
|
||||
|
||||
// handles pinging the endpoint and returns an error if the
|
||||
// agent is in an unhealthy state.
|
||||
func pinger() error {
|
||||
resp, err := http.Get("http://localhost:" + gorush.PushConf.Core.Port + gorush.PushConf.API.HealthURI)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
return fmt.Errorf("server returned non-200 status code")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func createPIDFile() error {
|
||||
if !gorush.PushConf.Core.PID.Enabled {
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue