Skip to content

Commit

Permalink
Add a health-check path option
Browse files Browse the repository at this point in the history
  • Loading branch information
pottava committed Oct 5, 2017
1 parent 9d0ef04 commit d5d6c32
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions README-ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ APP_PORT | このサービスが待機する `ポート番号`
ACCESS_LOG | 標準出力へアクセスログを送る | | false
STRIP_PATH | 指定した Prefix を S3 のパスから削除 | | -
CONTENT_ENCODING | リクエストが許可して入ればレスポンスを圧縮します | | false
HEALTHCHECK_PATH | 指定すると Basic 認証設定の有無などに依らず 200 OK を返します | | -

### 2. アプリを起動します

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
![circleci status](https://circleci.com/gh/pottava/aws-s3-proxy.svg?style=shield&circle-token=9bc17d02e4513df42196523a1791465e65d8ab01)

Supported tags and respective `Dockerfile` links:
・latest ([prod/Dockerfile](https://github.com/pottava/aws-s3-proxy/blob/master/prod/Dockerfile))
・latest ([prod/Dockerfile](https://github.com/pottava/aws-s3-proxy/blob/master/prod/Dockerfile))
・1.1 ([prod/Dockerfile](https://github.com/pottava/aws-s3-proxy/blob/master/prod/Dockerfile))
・1 ([prod/Dockerfile](https://github.com/pottava/aws-s3-proxy/blob/master/prod/Dockerfile))

## Description

Expand Down Expand Up @@ -43,6 +45,7 @@ APP_PORT | The port number to be assigned for listening. |
ACCESS_LOG | Send access logs to /dev/stdout. | | false
STRIP_PATH | Strip path prefix. | | -
CONTENT_ENCODING | Compress response data if the request allows. | | false
HEALTHCHECK_PATH | If it's specified, the path always returns 200 OK | | -

### 2. Run the application

Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ services:
- CORS_MAX_AGE
- ACCESS_LOG=true
- CONTENT_ENCODING
- HEALTHCHECK_PATH
container_name: app
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type config struct {
corsAllowMethods string // CORS_ALLOW_METHODS
corsAllowHeaders string // CORS_ALLOW_HEADERS
corsMaxAge int64 // CORS_MAX_AGE
healthCheckPath string // HEALTHCHECK_PATH
}

type symlink struct {
Expand All @@ -70,6 +71,12 @@ func main() {
}
})

if c.healthCheckPath != "" {
http.HandleFunc(c.healthCheckPath, func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
}

// Listen & Serve
log.Printf("[service] listening on port %s", c.port)
if (len(c.sslCert) > 0) && (len(c.sslKey) > 0) {
Expand Down Expand Up @@ -143,6 +150,7 @@ func configFromEnvironmentVariables() *config {
corsAllowMethods: os.Getenv("CORS_ALLOW_METHODS"),
corsAllowHeaders: os.Getenv("CORS_ALLOW_HEADERS"),
corsMaxAge: corsMaxAge,
healthCheckPath: os.Getenv("HEALTHCHECK_PATH"),
}
// Proxy
log.Printf("[config] Proxy to %v", conf.s3Bucket)
Expand Down

0 comments on commit d5d6c32

Please sign in to comment.