Skip to content

Commit 42d9b1b

Browse files
committed
updating documentation
we also add a demo app to help understanding where exactly this project is useful
1 parent 4370922 commit 42d9b1b

File tree

5 files changed

+103
-1
lines changed

5 files changed

+103
-1
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# HTTP Status Code Checker
22

3-
dead simple binary to check http status code returned from health-check
3+
dead simple binary to check http status code(s) returned from health-check
44
endpoint.
55

66
## Why not just use cURL?
@@ -14,10 +14,22 @@ status codes and let you dealing only with the program exit code itself:
1414
- 0 - if the status code is inside the list of expected ones
1515
- 1 - if the status code is outside the list of expected ones
1616

17+
Also. In a scenario where one of the containers get compromised a tool like curl
18+
can become a liability helping the intruder having an easier time fetching more
19+
external data/tools.
20+
1721
## Install
1822

1923
`cargo install http_status_code_check`
2024

25+
or
26+
27+
```
28+
curl -L https://github.com/rmoraes92/http_status_code_check/releases/download/0.1.2/http_status_code_check \
29+
> /bin/http_status_code_check && \
30+
chmod 755 /bin/http_status_code_check
31+
```
32+
2133
## Usage
2234

2335
- Checking for single code:
@@ -28,6 +40,12 @@ status codes and let you dealing only with the program exit code itself:
2840

2941
`http_status_code_check -u http://google.com -s 201,200`
3042

43+
## Example Mocking AWS ECS
44+
45+
An example using docker compose is located at `demo/` folder.
46+
47+
It uses to barebones container images with the healthcheck capability of docker
48+
compose.
3149

3250
## License
3351

demo/Dockerfile.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM golang:1.23
2+
WORKDIR /src
3+
RUN curl -L https://github.com/rmoraes92/http_status_code_check/releases/download/0.1.1/http_status_code_check > /bin/http_status_code_check && \
4+
chmod 755 /bin/http_status_code_check
5+
RUN go mod init example/http_server
6+
COPY <<EOF ./main.go
7+
package main
8+
9+
import (
10+
"github.com/gin-gonic/gin"
11+
"net/http"
12+
)
13+
14+
func main() {
15+
r := gin.Default()
16+
17+
r.GET("/", func(c *gin.Context) {
18+
c.String(http.StatusOK, "hello world")
19+
})
20+
21+
r.Run()
22+
}
23+
EOF
24+
RUN go get .
25+
RUN go build -o /bin/http_server ./main.go
26+
27+
FROM debian
28+
COPY --from=0 /bin/http_server /bin/http_server
29+
COPY --from=0 /bin/http_status_code_check /bin/http_status_code_check
30+
RUN apt-get update && apt-get install -y libssl-dev
31+
CMD ["http_server"]

demo/Dockerfile.python

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM debian
2+
RUN apt-get update -y && apt-get install -y curl
3+
RUN curl -L https://github.com/rmoraes92/http_status_code_check/releases/download/0.1.1/http_status_code_check > /bin/http_status_code_check && \
4+
chmod 755 /bin/http_status_code_check
5+
6+
FROM python:3-slim
7+
COPY --from=0 /bin/http_status_code_check /bin/http_status_code_check
8+
CMD ["python", "-m", "http.server"]

demo/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Demo
2+
3+
We have two small http echo servers using Python and Go:
4+
5+
- Dockerfile.python
6+
- Dockerfile.go
7+
8+
The focus here is on the compose file. Specifically in the healthcheck section:
9+
10+
```
11+
healthcheck:
12+
test: ["CMD", "http_status_code_check", "-u", "http://localhost:8080/", "-s", "200"]
13+
interval: 2s
14+
timeout: 5s
15+
retries: 3
16+
```
17+
18+
This more or less replicates the scenario where AWS ECS Task definition will
19+
ask you to have an internal call/script/routine that can confirm the server is
20+
up.
21+
22+
Using `http_status_code_check` will handle the task of checking for the HTTP
23+
status code without providing any extra function reducing the amount of vectors
24+
we could had if the container get compromised.

demo/docker-compose.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
services:
2+
python:
3+
image: simple-python-http
4+
build:
5+
dockerfile: Dockerfile.python
6+
context: .
7+
healthcheck:
8+
test: [ "CMD", "http_status_code_check", "-u", "http://localhost:8000/", "-s", "200" ]
9+
interval: 2s
10+
timeout: 5s
11+
retries: 3
12+
go:
13+
image: simple-go-http
14+
build:
15+
dockerfile: Dockerfile.go
16+
context: .
17+
healthcheck:
18+
test: ["CMD", "http_status_code_check", "-u", "http://localhost:8080/", "-s", "200"]
19+
interval: 2s
20+
timeout: 5s
21+
retries: 3

0 commit comments

Comments
 (0)