mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-19 23:54:22 +01:00
added health check endpoint + fixed logging
* set go-gin to release mode * added health check endpoint * excluded endpoint from logger see #63
This commit is contained in:
@@ -9,8 +9,6 @@ ARG SIGNAL_CLI_VERSION
|
|||||||
ARG ZKGROUP_VERSION
|
ARG ZKGROUP_VERSION
|
||||||
ARG SWAG_VERSION
|
ARG SWAG_VERSION
|
||||||
|
|
||||||
ENV GIN_MODE=release
|
|
||||||
|
|
||||||
COPY ext/libraries/zkgroup/v${ZKGROUP_VERSION} /tmp/zkgroup-libraries
|
COPY ext/libraries/zkgroup/v${ZKGROUP_VERSION} /tmp/zkgroup-libraries
|
||||||
|
|
||||||
RUN ls -la /tmp/zkgroup-libraries/x86-64
|
RUN ls -la /tmp/zkgroup-libraries/x86-64
|
||||||
@@ -74,6 +72,8 @@ RUN cd /tmp/signal-cli-rest-api-src && swag init && go build
|
|||||||
# Start a fresh container for release container
|
# Start a fresh container for release container
|
||||||
FROM adoptopenjdk:11-jre-hotspot-bionic
|
FROM adoptopenjdk:11-jre-hotspot-bionic
|
||||||
|
|
||||||
|
ENV GIN_MODE=release
|
||||||
|
|
||||||
ENV PORT=8080
|
ENV PORT=8080
|
||||||
|
|
||||||
ARG SIGNAL_CLI_VERSION
|
ARG SIGNAL_CLI_VERSION
|
||||||
@@ -100,4 +100,4 @@ EXPOSE ${PORT}
|
|||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
|
||||||
HEALTHCHECK --interval=20s --timeout=10s --retries=3 \
|
HEALTHCHECK --interval=20s --timeout=10s --retries=3 \
|
||||||
CMD curl -f http://localhost:${PORT}/v1/about || exit 1
|
CMD curl -f http://localhost:${PORT}/v1/health || exit 1
|
||||||
|
|||||||
@@ -850,3 +850,13 @@ func (a *Api) UpdateProfile(c *gin.Context) {
|
|||||||
cleanupTmpFiles(avatarTmpPaths)
|
cleanupTmpFiles(avatarTmpPaths)
|
||||||
c.Status(http.StatusNoContent)
|
c.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Summary API Health Check
|
||||||
|
// @Tags General
|
||||||
|
// @Description Internally used by the docker container to perform the health check.
|
||||||
|
// @Produce json
|
||||||
|
// @Success 204 {string} OK
|
||||||
|
// @Router /v1/health [get]
|
||||||
|
func (a *Api) Health(c *gin.Context) {
|
||||||
|
c.Status(http.StatusNoContent)
|
||||||
|
}
|
||||||
|
|||||||
@@ -264,6 +264,26 @@ var doc = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/v1/health": {
|
||||||
|
"get": {
|
||||||
|
"description": "Internally used by the docker container to perform the health check.",
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"General"
|
||||||
|
],
|
||||||
|
"summary": "API Health Check",
|
||||||
|
"responses": {
|
||||||
|
"204": {
|
||||||
|
"description": "No Content",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/v1/profiles/{number}": {
|
"/v1/profiles/{number}": {
|
||||||
"put": {
|
"put": {
|
||||||
"description": "Set your name and optional an avatar.",
|
"description": "Set your name and optional an avatar.",
|
||||||
|
|||||||
@@ -249,6 +249,26 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/v1/health": {
|
||||||
|
"get": {
|
||||||
|
"description": "Internally used by the docker container to perform the health check.",
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"General"
|
||||||
|
],
|
||||||
|
"summary": "API Health Check",
|
||||||
|
"responses": {
|
||||||
|
"204": {
|
||||||
|
"description": "No Content",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/v1/profiles/{number}": {
|
"/v1/profiles/{number}": {
|
||||||
"put": {
|
"put": {
|
||||||
"description": "Set your name and optional an avatar.",
|
"description": "Set your name and optional an avatar.",
|
||||||
|
|||||||
@@ -244,6 +244,19 @@ paths:
|
|||||||
summary: Delete a Signal Group.
|
summary: Delete a Signal Group.
|
||||||
tags:
|
tags:
|
||||||
- Groups
|
- Groups
|
||||||
|
/v1/health:
|
||||||
|
get:
|
||||||
|
description: Internally used by the docker container to perform the health check.
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"204":
|
||||||
|
description: No Content
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
summary: API Health Check
|
||||||
|
tags:
|
||||||
|
- General
|
||||||
/v1/profiles/{number}:
|
/v1/profiles/{number}:
|
||||||
put:
|
put:
|
||||||
description: Set your name and optional an avatar.
|
description: Set your name and optional an avatar.
|
||||||
|
|||||||
13
src/main.go
13
src/main.go
@@ -45,7 +45,13 @@ func main() {
|
|||||||
avatarTmpDir := flag.String("avatar-tmp-dir", "/tmp/", "Avatar tmp directory")
|
avatarTmpDir := flag.String("avatar-tmp-dir", "/tmp/", "Avatar tmp directory")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
router := gin.Default()
|
router := gin.New()
|
||||||
|
router.Use(gin.LoggerWithConfig(gin.LoggerConfig{
|
||||||
|
SkipPaths: []string{"/v1/health"}, //do not log the health requests (to avoid spamming the log file)
|
||||||
|
}))
|
||||||
|
|
||||||
|
router.Use(gin.Recovery())
|
||||||
|
|
||||||
log.Info("Started Signal Messenger REST API")
|
log.Info("Started Signal Messenger REST API")
|
||||||
|
|
||||||
api := api.NewApi(*signalCliConfig, *attachmentTmpDir, *avatarTmpDir)
|
api := api.NewApi(*signalCliConfig, *attachmentTmpDir, *avatarTmpDir)
|
||||||
@@ -56,6 +62,11 @@ func main() {
|
|||||||
about.GET("", api.About)
|
about.GET("", api.About)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
health := v1.Group("/health")
|
||||||
|
{
|
||||||
|
health.GET("", api.Health)
|
||||||
|
}
|
||||||
|
|
||||||
register := v1.Group("/register")
|
register := v1.Group("/register")
|
||||||
{
|
{
|
||||||
register.POST(":number", api.RegisterNumber)
|
register.POST(":number", api.RegisterNumber)
|
||||||
|
|||||||
Reference in New Issue
Block a user