Skip to content

Commit

Permalink
feat: go - http
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Davids <[email protected]>
  • Loading branch information
sdavids committed Dec 6, 2024
1 parent 3cb4a14 commit 0b92b9a
Show file tree
Hide file tree
Showing 29 changed files with 775 additions and 0 deletions.
1 change: 1 addition & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ scripts/shellscript_check.sh "${base_dir}"
yamllint --strict "${base_dir}"

# https://github.com/hadolint/hadolint#cli
hadolint --no-color go/http/Dockerfile
hadolint --no-color js/nodejs/Dockerfile
hadolint --no-color rust/http/Dockerfile
hadolint --no-color rust/https/Dockerfile
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ jobs:
- js/nodejs/prettier.config.mjs
- 'js/nodejs/src/**.mjs'
- 'js/nodejs/test/**.mjs'
go-http-Dockerfile:
- .hadolint.yaml
- go/http/Dockerfile
go-http:
- go/http/go.mod
- go/http/go.sum
- 'go/http/**.go'
rust-http-Dockerfile:
- .hadolint.yaml
- rust/http/Dockerfile
Expand Down Expand Up @@ -100,6 +107,35 @@ jobs:
name: Test js/nodejs
working-directory: js/nodejs
run: scripts/test.sh
# --- go/http ----------------------------------------------------------
- if: steps.changes.outputs.go-http-Dockerfile == 'true'
name: Lint go/http/Dockerfile
# https://github.com/hadolint/hadolint-action/releases
uses: hadolint/[email protected]
with:
dockerfile: go/http/Dockerfile
- if: steps.changes.outputs.go-http == 'true'
name: Install Go for go/http
# https://github.com/actions/setup-go/releases
uses: actions/[email protected]
with:
go-version-file: go/http/go.mod
- if: steps.changes.outputs.go-http == 'true'
name: Lint go/http files
# https://github.com/golangci/golangci-lint-action/releases
uses: golangci/[email protected]
with:
# https://github.com/golangci/golangci-lint/releases
version: v1.62.0
working-directory: go/http
- if: steps.changes.outputs.go-http == 'true'
name: Test go/http
working-directory: go/http
run: scripts/test.sh
- if: steps.changes.outputs.go-http == 'true'
name: Build go/http
working-directory: go/http
run: scripts/build_release.sh
# --- rust/http ------------------------------------------------------
- if: steps.changes.outputs.rust-http-Dockerfile == 'true'
name: Lint rust/http Dockerfile
Expand Down
22 changes: 22 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ toc::[]

Available Docker health checks:

link:go/http/README.adoc[Go - http]:: a Go-based Docker health check for an HTTP URL
link:js/nodejs/README.adoc/[JavaScript - Node.js]:: a Node.js-based Docker health check for an HTTP(S) URL
link:rust/http/README.adoc[Rust - http]:: a Rust-based Docker health check for an HTTP URL
link:rust/https/README.adoc[Rust - https]:: a Rust-based Docker health check for an HTTP(S) URL
Expand Down Expand Up @@ -76,6 +77,10 @@ link:shell/nc/README.adoc[shell - nc]:: an nc-based Docker health check for a da
>|480.0K
|

|<<go-http,Go - http>>
>|5.0M
|

|<<wget-alpine,wget alpine>>
>|8.6M
|
Expand All @@ -101,6 +106,23 @@ link:shell/nc/README.adoc[shell - nc]:: an nc-based Docker health check for a da
|
|===

=== Go

[#go-http]
==== Go - http

[source,shell]
----
$ cd go/http
$ scripts/docker_build.sh -t go-http
$ docker run --rm de.sdavids/sdavids-docker-healthcheck:go-http sh -c 'du -kh /usr/local/bin/healthcheck'
5.0M /usr/local/bin/healthcheck
----

===== Usage

link:go/http/README.adoc#usage[Go - http]

=== JavaScript

[#js-nodejs]
Expand Down
1 change: 1 addition & 0 deletions go/.golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ linters-settings:
allow:
- $gostd
- sdavids.de
- github.com/dedelala/sysexits
deny:
- pkg: io/ioutil
desc: >-
Expand Down
17 changes: 17 additions & 0 deletions go/http/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-FileCopyrightText: © 2024 Sebastian Davids <[email protected]>
# SPDX-License-Identifier: Apache-2.0

# https://docs.docker.com/build/building/context/#dockerignore-files

*~
*.orig
*.sw[a-p]
*.tmp
.DS_Store
[Dd]esktop.ini
Thumbs.db

*.adoc
.dockerignore
Dockerfile
scripts/
57 changes: 57 additions & 0 deletions go/http/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# syntax=docker/dockerfile:1

# SPDX-FileCopyrightText: © 2024 Sebastian Davids <[email protected]>
# SPDX-License-Identifier: Apache-2.0

# https://docs.docker.com/engine/reference/builder/

### healthcheck builder ###

# https://hub.docker.com/_/golang/
FROM golang:1.23.4-alpine3.20 AS healthcheck

WORKDIR /app

COPY go.sum go.mod ./

RUN go mod download

COPY cmd cmd

RUN CGO_ENABLED=0 GOOS=linux go build -ldflags '-s -w' -o target/healthcheck cmd/healthcheck.go

LABEL de.sdavids.docker.group="sdavids-docker-healthcheck" \
de.sdavids.docker.type="builder"

### HTTP server ###

# https://hub.docker.com/_/nginx/
FROM nginx:1.27.3-alpine3.20-slim AS http_server

RUN mkdir -p /usr/share/nginx/html/-/health && \
touch /usr/share/nginx/html/-/health/liveness && \
printf '<!doctype html><title>sdavids-docker-healthcheck-go-http</title><h1>sdavids-docker-healthcheck-go-http</h1>' > /usr/share/nginx/html/index.html && \
printf 'server {listen 3000;listen [::]:3000;location / {root /usr/share/nginx/html;index index.html;}}' > /etc/nginx/conf.d/default.conf

LABEL de.sdavids.docker.group="sdavids-docker-healthcheck" \
de.sdavids.docker.type="builder"

### final ###

FROM http_server

EXPOSE 3000

COPY --from=healthcheck \
/app/target/healthcheck \
/usr/local/bin/healthcheck

HEALTHCHECK --interval=5s --timeout=5s --start-period=5s \
CMD healthcheck || exit 1

# https://github.com/opencontainers/image-spec/blob/master/annotations.md
LABEL org.opencontainers.image.licenses="Apache-2.0" \
org.opencontainers.image.vendor="Sebastian Davids" \
org.opencontainers.image.title="healthcheck-go-http" \
de.sdavids.docker.group="sdavids-docker-healthcheck" \
de.sdavids.docker.type="development"
Loading

0 comments on commit 0b92b9a

Please sign in to comment.