Skip to content

Commit

Permalink
feat: go - https
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Davids <[email protected]>
  • Loading branch information
sdavids committed Oct 27, 2024
1 parent 7830527 commit 270bf6b
Show file tree
Hide file tree
Showing 32 changed files with 1,172 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 @@ -51,6 +51,7 @@ yamllint --strict "${base_dir}"

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

link:go/http/README.adoc[Go - http]:: a Go-based Docker health check for an HTTP URL
link:go/https/README.adoc[Go - https]:: a Go-based Docker health check for an HTTP(S) 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 @@ -81,6 +82,10 @@ link:shell/nc/README.adoc[shell - nc]:: an nc-based Docker health check for a da
>|5.0M
|

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

|<<curl-alpine-3179,curl alpine:3.17.9>>
>|6.2M
|
Expand Down Expand Up @@ -131,6 +136,21 @@ $ docker run --rm de.sdavids/sdavids-docker-healthcheck:go-http sh -c 'du -kh /u

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

[#go-https]
==== Go - https

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

===== Usage

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

=== JavaScript

[#js-nodejs]
Expand Down
12 changes: 12 additions & 0 deletions go/https/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-FileCopyrightText: © 2024 Sebastian Davids <[email protected]>
# SPDX-License-Identifier: Apache-2.0

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

*.adoc
*.swp
.DS_Store
Dockerfile
Thumbs.db
desktop.ini
scripts/
57 changes: 57 additions & 0 deletions go/https/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.2-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"

### HTTPS server ###

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

RUN mkdir -p /usr/share/nginx/html/-/health && \
touch /usr/share/nginx/html/-/health/liveness && \
printf '<!doctype html><title>sdavids-docker-healthcheck-go-https</title><h1>sdavids-docker-healthcheck-go-https</h1>' > /usr/share/nginx/html/index.html && \
printf 'server {listen 3000 ssl;listen [::]:3000 ssl;ssl_certificate /etc/ssl/certs/server.crt;ssl_certificate_key /etc/ssl/private/server.key;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 https_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-https" \
de.sdavids.docker.group="sdavids-docker-healthcheck" \
de.sdavids.docker.type="development"
Loading

0 comments on commit 270bf6b

Please sign in to comment.