diff --git a/Dockerfile b/Dockerfile index ccc4e97..c6be970 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,8 +9,6 @@ ARG SIGNAL_CLI_VERSION ARG ZKGROUP_VERSION ARG SWAG_VERSION -ENV GIN_MODE=release - COPY ext/libraries/zkgroup/v${ZKGROUP_VERSION} /tmp/zkgroup-libraries 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 FROM adoptopenjdk:11-jre-hotspot-bionic +ENV GIN_MODE=release + ENV PORT=8080 ARG SIGNAL_CLI_VERSION @@ -100,4 +100,4 @@ EXPOSE ${PORT} ENTRYPOINT ["/entrypoint.sh"] 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 diff --git a/src/api/api.go b/src/api/api.go index f7aa643..b3198f1 100644 --- a/src/api/api.go +++ b/src/api/api.go @@ -850,3 +850,13 @@ func (a *Api) UpdateProfile(c *gin.Context) { cleanupTmpFiles(avatarTmpPaths) 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) +} diff --git a/src/docs/docs.go b/src/docs/docs.go index d592327..8382bb8 100644 --- a/src/docs/docs.go +++ b/src/docs/docs.go @@ -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}": { "put": { "description": "Set your name and optional an avatar.", diff --git a/src/docs/swagger.json b/src/docs/swagger.json index 7a1dd58..3b714b5 100644 --- a/src/docs/swagger.json +++ b/src/docs/swagger.json @@ -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}": { "put": { "description": "Set your name and optional an avatar.", diff --git a/src/docs/swagger.yaml b/src/docs/swagger.yaml index 4ec235d..52f3210 100644 --- a/src/docs/swagger.yaml +++ b/src/docs/swagger.yaml @@ -244,6 +244,19 @@ paths: summary: Delete a Signal Group. tags: - 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}: put: description: Set your name and optional an avatar. diff --git a/src/main.go b/src/main.go index 75c299b..a60a664 100644 --- a/src/main.go +++ b/src/main.go @@ -45,7 +45,13 @@ func main() { avatarTmpDir := flag.String("avatar-tmp-dir", "/tmp/", "Avatar tmp directory") 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") api := api.NewApi(*signalCliConfig, *attachmentTmpDir, *avatarTmpDir) @@ -56,6 +62,11 @@ func main() { about.GET("", api.About) } + health := v1.Group("/health") + { + health.GET("", api.Health) + } + register := v1.Group("/register") { register.POST(":number", api.RegisterNumber)