feat(docker): test a container to check that it is still working (#346)

This commit is contained in:
Bo-Yi Wu 2018-03-17 23:07:38 +08:00 committed by GitHub
parent 86630e0fc7
commit b3bdd9b79e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 0 deletions

View File

@ -10,4 +10,8 @@ LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>"
ADD release/linux/amd64/gorush /bin/ ADD release/linux/amd64/gorush /bin/
EXPOSE 8088 9000 EXPOSE 8088 9000
HEALTHCHECK --start-period=2s --interval=10s --timeout=5s \
CMD ["/bin/gorush", "--ping"]
ENTRYPOINT ["/bin/gorush"] ENTRYPOINT ["/bin/gorush"]

View File

@ -13,4 +13,7 @@ RUN apk add --no-cache ca-certificates && \
ADD release/linux/amd64/gorush /bin/ ADD release/linux/amd64/gorush /bin/
EXPOSE 8088 9000 EXPOSE 8088 9000
HEALTHCHECK --start-period=2s --interval=10s --timeout=5s \
CMD ["/bin/gorush", "--ping"]
ENTRYPOINT ["/bin/gorush"] ENTRYPOINT ["/bin/gorush"]

View File

@ -10,4 +10,7 @@ LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>"
ADD release/linux/arm/gorush /bin/ ADD release/linux/arm/gorush /bin/
EXPOSE 8088 9000 EXPOSE 8088 9000
HEALTHCHECK --start-period=2s --interval=10s --timeout=5s \
CMD ["/bin/gorush", "--ping"]
ENTRYPOINT ["/bin/gorush"] ENTRYPOINT ["/bin/gorush"]

View File

@ -10,4 +10,7 @@ LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>"
ADD release/linux/arm64/gorush /bin/ ADD release/linux/arm64/gorush /bin/
EXPOSE 8088 9000 EXPOSE 8088 9000
HEALTHCHECK --start-period=2s --interval=10s --timeout=5s \
CMD ["/bin/gorush", "--ping"]
ENTRYPOINT ["/bin/gorush"] ENTRYPOINT ["/bin/gorush"]

View File

@ -10,4 +10,7 @@ LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>"
ADD release/linux/i386/gorush /bin/ ADD release/linux/i386/gorush /bin/
EXPOSE 8088 9000 EXPOSE 8088 9000
HEALTHCHECK --start-period=2s --interval=10s --timeout=5s \
CMD ["/bin/gorush", "--ping"]
ENTRYPOINT ["/bin/gorush"] ENTRYPOINT ["/bin/gorush"]

View File

@ -6,4 +6,7 @@ LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.schema-version="1.0" org.label-schema.schema-version="1.0"
ADD release/gorush.exe /gorush.exe ADD release/gorush.exe /gorush.exe
HEALTHCHECK --start-period=2s --interval=10s --timeout=5s \
CMD ["\\gorush.exe", "--ping"]
ENTRYPOINT [ "\\gorush.exe" ] ENTRYPOINT [ "\\gorush.exe" ]

25
main.go
View File

@ -4,6 +4,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"log" "log"
"net/http"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
@ -19,6 +20,7 @@ func main() {
opts := config.ConfYaml{} opts := config.ConfYaml{}
var ( var (
ping bool
showVersion bool showVersion bool
configFile string configFile string
topic string topic string
@ -56,6 +58,7 @@ func main() {
flag.BoolVar(&opts.Ios.Production, "production", false, "production mode in iOS") flag.BoolVar(&opts.Ios.Production, "production", false, "production mode in iOS")
flag.StringVar(&topic, "topic", "", "apns topic in iOS") flag.StringVar(&topic, "topic", "", "apns topic in iOS")
flag.StringVar(&proxy, "proxy", "", "http proxy url") flag.StringVar(&proxy, "proxy", "", "http proxy url")
flag.BoolVar(&ping, "ping", false, "ping server")
flag.Usage = usage flag.Usage = usage
flag.Parse() 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 // send android notification
if opts.Android.Enabled { if opts.Android.Enabled {
gorush.PushConf.Android.Enabled = opts.Android.Enabled gorush.PushConf.Android.Enabled = opts.Android.Enabled
@ -270,6 +280,7 @@ Server Options:
--proxy <proxy> Proxy URL (only for GCM) --proxy <proxy> Proxy URL (only for GCM)
--pid <pid path> Process identifier path --pid <pid path> Process identifier path
--redis-addr <redis addr> Redis addr (default: localhost:6379) --redis-addr <redis addr> Redis addr (default: localhost:6379)
--ping healthy check command for container
iOS Options: iOS Options:
-i, --key <file> certificate key file path -i, --key <file> certificate key file path
-P, --password <password> certificate key password -P, --password <password> certificate key password
@ -290,6 +301,20 @@ func usage() {
os.Exit(0) 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 { func createPIDFile() error {
if !gorush.PushConf.Core.PID.Enabled { if !gorush.PushConf.Core.PID.Enabled {
return nil return nil