39 Commits

Author SHA1 Message Date
jcabillot b2c7777597 Merge pull request 'fix(ci): correct corrupted docker/build-push-action SHA' (#20) from fix/build-push-action-sha into master
Main Release / hadolint (push) Successful in 10s
Main Release / test (push) Successful in 17s
Main Release / build (push) Successful in 17s
Main Release / tag (push) Successful in 39s
Tag Release / hadolint (push) Successful in 7s
Tag Release / test (push) Successful in 14s
Tag Release / build-push (push) Failing after 4s
Reviewed-on: #20
2026-06-29 08:08:18 -04:00
cloudix_mcp_server 0ec94f79d4 fix(ci): correct corrupted docker/build-push-action SHA
PR Checks / hadolint (pull_request) Successful in 8s
PR Checks / build-test (pull_request) Successful in 15s
The SHA for docker/build-push-action@v7.2.0 in tag.yaml and cron.yaml
was corrupted: 0d7f5c8f should be 0d6e8b85.

Correct SHA from git ls-remote refs/tags/v7.2.0:
f9f3042f7e2789586610d6e8b85c8f03e5195baf

Fixes CI run #2437 job #6165 (reference not found on docker/login-action
clone — likely cascade from the corrupted build-push-action SHA).
2026-06-29 12:05:31 +00:00
jcabillot 28e3036f5c Merge pull request 'fix(ci): correct corrupted anothrNick/github-tag-action SHA' (#19) from fix/github-tag-action-sha into master
Main Release / hadolint (push) Successful in 7s
Main Release / test (push) Successful in 14s
Main Release / build (push) Successful in 11s
Main Release / tag (push) Successful in 32s
Tag Release / hadolint (push) Successful in 7s
Tag Release / test (push) Successful in 14s
Tag Release / build-push (push) Failing after 30s
Reviewed-on: #19
2026-06-28 22:14:25 -04:00
cloudix_mcp_server 928aca5505 fix(ci): correct corrupted anothrNick/github-tag-action SHA
PR Checks / build-test (pull_request) Successful in 1m59s
PR Checks / hadolint (pull_request) Successful in 6s
The SHA in the tag job of main.yaml was corrupted — missing the leading
'4' and with mutated bytes in the middle (da04aec3cc → da9f2a04ec).
Correct SHA for v1.75.0 is 4ed44965e0db8dab2b466a16da04aec3cc312fd8.

Fixes CI run #1981 job #4861: reference not found.
2026-06-28 18:09:15 +00:00
jcabillot 3166943afc Merge pull request 'chore(deps): update actions/checkout action to v7' (#18) from renovate/actions-checkout-7.x into master
Main Release / hadolint (push) Successful in 7s
Main Release / test (push) Successful in 18s
Main Release / build (push) Successful in 15s
Main Release / tag (push) Failing after 8s
Reviewed-on: #18
2026-06-18 16:22:58 -04:00
renovate 1afb8d92c5 chore(deps): update actions/checkout action to v7
PR Checks / hadolint (pull_request) Successful in 7s
PR Checks / build-test (pull_request) Successful in 14s
2026-06-18 15:24:32 +00:00
jcabillot ddcb9f9e62 Merge pull request 'chore(deps): update docker/metadata-action digest to 80c7e94' (#17) from renovate/docker-metadata-action-digest into master
Main Release / hadolint (push) Successful in 7s
Main Release / test (push) Successful in 14s
Main Release / build (push) Successful in 13s
Main Release / tag (push) Failing after 4s
Reviewed-on: #17
2026-06-13 19:51:22 -04:00
renovate cff4255b94 chore(deps): update docker/metadata-action digest to 80c7e94
PR Checks / build-test (pull_request) Successful in 16s
PR Checks / hadolint (pull_request) Failing after 14m4s
2026-06-13 22:00:28 +00:00
jcabillot 93df1d3f8d Merge pull request 'Convert CI to standard htpasswd 4-workflow pattern (no artifact)' (#16) from fix/workflow-standard into master
Main Release / hadolint (push) Successful in 5s
Main Release / test (push) Successful in 13s
Main Release / build (push) Successful in 20s
Main Release / tag (push) Failing after 5s
Reviewed-on: #16
2026-06-13 17:59:48 -04:00
cloudix_mcp_server a4a70f93da Convert tag.yaml to standard htpasswd 4-workflow pattern (no artifact)
PR Checks / hadolint (pull_request) Successful in 6s
PR Checks / build-test (pull_request) Successful in 14s
Replace artifact upload/download with direct build per job.
Trigger on tag push (v*). Chain: hadolint→test→build-push.
2026-06-13 17:54:46 -04:00
cloudix_mcp_server 19b827a0a7 Convert pr.yaml to standard htpasswd 4-workflow pattern (no artifact)
Replace artifact upload/download with direct build per job.
Chain: hadolint→build-test.
2026-06-13 17:54:41 -04:00
cloudix_mcp_server 361c2c72be Convert cron.yaml to standard htpasswd 4-workflow pattern (no artifact)
Preserve original schedule (0 0 * * *). Replace artifact upload/download
with setup-buildx + metadata-action + build-push-action chain.
2026-06-13 17:54:39 -04:00
cloudix_mcp_server 3c2d96a317 Convert main.yaml to standard htpasswd 4-workflow pattern (no artifact)
Replace artifact upload/download with direct build per job using
setup-buildx-action. Chain: hadolint→test→build→tag.
2026-06-13 17:54:38 -04:00
jcabillot 2aa907190a Merge pull request 'feat(ci): refactor pipelines — hadolint, PR checks, tag releases, nightly rebuild' (#15) from fix/refactor-ci-pipelines into master
Main CI / lint (push) Successful in 6s
Tag Release / tag (push) Failing after 8s
Main CI / build (push) Successful in 58s
Main CI / test (push) Successful in 22s
Main CI / push (push) Successful in 24s
Reviewed-on: #15
2026-06-12 16:23:04 -04:00
cloudix_mcp_server 6eca2fc500 feat(ci): add nightly rebuild workflow
PR Checks / lint (pull_request) Successful in 7s
PR Checks / build (pull_request) Successful in 53s
PR Checks / test (pull_request) Successful in 25s
2026-06-12 16:19:29 -04:00
cloudix_mcp_server e977e99155 feat(ci): add tag release workflow 2026-06-12 16:19:23 -04:00
cloudix_mcp_server ba4c8108ab feat(ci): add main CI workflow — lint, build, test, push to Docker Hub 2026-06-12 16:19:17 -04:00
cloudix_mcp_server 4f38b4377f feat(ci): add PR checks workflow — hadolint, build, test 2026-06-12 16:19:12 -04:00
cloudix_mcp_server 89725e8e1b chore(ci): remove monolithic docker-build.yaml 2026-06-12 16:19:08 -04:00
jcabillot 0ddda779fb Merge pull request 'ci: add automatic semver tagging on merge to master' (#14) from feat/semver-tag-action into master
Docker Build and Push / lint (push) Successful in 6s
Docker Build and Push / build (push) Successful in 56s
Docker Build and Push / test (push) Successful in 32s
Docker Build and Push / push (push) Failing after 1m18s
Reviewed-on: #14
2026-06-12 13:39:40 -04:00
cloudix_mcp_server 2913b930aa ci: add automatic semver tagging on merge to master
Docker Build and Push / lint (pull_request) Successful in 6s
Docker Build and Push / build (pull_request) Successful in 1m0s
Docker Build and Push / test (pull_request) Successful in 25s
Docker Build and Push / push (pull_request) Has been skipped
2026-06-12 13:22:59 -04:00
jcabillot 7342f704b3 Merge pull request 'chore(config): migrate Renovate config' (#13) from renovate/migrate-config into master
Docker Build and Push / lint (push) Successful in 11s
Docker Build and Push / build (push) Successful in 59s
Docker Build and Push / test (push) Successful in 23s
Docker Build and Push / push (push) Successful in 31s
Reviewed-on: #13
2026-06-09 13:32:59 -04:00
renovate 20d77d22de chore(config): migrate config renovate.json
Docker Build and Push / lint (pull_request) Successful in 8s
Docker Build and Push / build (pull_request) Successful in 1m2s
Docker Build and Push / test (pull_request) Successful in 28s
Docker Build and Push / push (pull_request) Has been skipped
2026-06-09 15:30:55 +00:00
jcabillot efa697d122 Merge pull request 'chore: improve renovate dependency detection' (#12) from chore/renovate into master
Docker Build and Push / build (push) Successful in 1m4s
Docker Build and Push / lint (push) Failing after 13m13s
Docker Build and Push / test (push) Has been skipped
Docker Build and Push / push (push) Has been skipped
Reviewed-on: #12
2026-06-09 11:26:57 -04:00
Sagent 5d86dd68d5 chore: remove redundant configs now handled globally
Docker Build and Push / lint (pull_request) Successful in 9s
Docker Build and Push / build (pull_request) Successful in 2m30s
Docker Build and Push / test (pull_request) Successful in 25s
Docker Build and Push / push (pull_request) Has been skipped
2026-06-09 13:40:36 +00:00
Sagent a8feda02a6 chore: improve renovate dependency detection
Docker Build and Push / lint (pull_request) Successful in 7s
Docker Build and Push / build (pull_request) Failing after 2m8s
Docker Build and Push / test (pull_request) Has been skipped
Docker Build and Push / push (pull_request) Has been skipped
- Disable gitlabci manager (legacy CI, migrated to Gitea Actions)
- Add custom regexManager to detect jcabillot/phpapache base image version from ARG VERSION
2026-06-09 02:20:05 +00:00
jcabillot cdd369630c Merge pull request 'Update hadolint/hadolint-action action to v3.3.0' (#11) from renovate/hadolint-hadolint-action-3.x into master
Docker Build and Push / lint (push) Successful in 12s
Docker Build and Push / build (push) Failing after 2m11s
Docker Build and Push / test (push) Has been skipped
Docker Build and Push / push (push) Has been skipped
Reviewed-on: #11
2026-06-08 15:44:13 -04:00
renovate 11acb639ea Update hadolint/hadolint-action action to v3.3.0
Docker Build and Push / lint (pull_request) Successful in 14s
Docker Build and Push / build (pull_request) Successful in 54s
Docker Build and Push / test (pull_request) Successful in 31s
Docker Build and Push / push (pull_request) Has been skipped
2026-06-08 18:30:21 +00:00
jcabillot 5eef598d4f Merge pull request 'feat: add test' (#10) from feat/test into master
Docker Build and Push / lint (push) Successful in 55s
Docker Build and Push / build (push) Successful in 1m4s
Docker Build and Push / test (push) Successful in 24s
Docker Build and Push / push (push) Successful in 55s
Reviewed-on: #10
2026-06-08 14:22:49 -04:00
Sagent 690859448e fix(test): use Docker bridge gateway for DinD networking
Docker Build and Push / lint (pull_request) Successful in 12s
Docker Build and Push / build (pull_request) Successful in 1m9s
Docker Build and Push / test (pull_request) Successful in 29s
Docker Build and Push / push (pull_request) Has been skipped
2026-06-08 18:19:35 +00:00
Sagent 9da0efa29c fix(test): use --network=host for Docker-in-Docker compatibility
Docker Build and Push / lint (pull_request) Successful in 1m9s
Docker Build and Push / build (pull_request) Successful in 2m20s
Docker Build and Push / test (pull_request) Failing after 1m41s
Docker Build and Push / push (pull_request) Has been skipped
2026-06-08 17:57:50 +00:00
Sagent 268d8d2b62 fix: use container IP instead of port mapping for health check
Docker Build and Push / lint (pull_request) Successful in 13s
Docker Build and Push / build (pull_request) Successful in 1m4s
Docker Build and Push / test (pull_request) Failing after 1h7m58s
Docker Build and Push / push (pull_request) Failing after 14m37s
When running inside Gitea Actions runner (Docker-in-Docker),
127.0.0.1:HOST_PORT doesn't work because the runner container
doesn't have access to the host's port mappings.
Use docker inspect to get the container's direct IP address.
2026-06-08 16:46:13 +00:00
Sagent 97ccaee674 fix: sanitize container name in test script
Docker Build and Push / lint (pull_request) Successful in 54s
Docker Build and Push / build (pull_request) Successful in 1m27s
Docker Build and Push / test (pull_request) Failing after 1m37s
Docker Build and Push / push (pull_request) Has been skipped
Replace : and / with - to comply with Docker container naming rules.
The colon in image:tag format is invalid in container names.
2026-06-08 16:33:31 +00:00
Sagent e858cb9646 fix: pin actions to SHA and use Gitea-compatible artifact actions
Docker Build and Push / lint (pull_request) Successful in 1m6s
Docker Build and Push / build (pull_request) Successful in 2m19s
Docker Build and Push / test (pull_request) Failing after 23s
Docker Build and Push / push (pull_request) Has been skipped
- Pin all actions to commit SHAs for supply chain security
- Replace actions/upload-artifact@v4 with ChristopherHX/gitea-upload-artifact
- Replace actions/download-artifact@v4 with ChristopherHX/gitea-download-artifact
- These forks work on Gitea Actions (GHES-compatible)
2026-06-08 16:25:59 +00:00
Julien Cabillot d5fc87f67b feat: add integration tests and hadolint to CI pipeline
Docker Build and Push / lint (pull_request) Successful in 19s
Docker Build and Push / build (pull_request) Failing after 40s
Docker Build and Push / test (pull_request) Has been skipped
Docker Build and Push / push (pull_request) Has been skipped
2026-06-08 11:34:24 -04:00
Julien Cabillot d8cc2d80b6 feat: add AGENTS.md 2026-06-08 11:07:14 -04:00
jcabillot e18636904b Merge pull request 'feat: add Gitea Actions workflow' (#9) from feat/gitea-actions into master
Docker Build and Push / build (push) Successful in 2m9s
Reviewed-on: #9
2026-05-29 15:04:52 -04:00
Julien Cabillot af820add1a feat: add Gitea Actions workflow
Docker Build and Push / build (pull_request) Successful in 8m43s
2026-05-29 14:46:20 -04:00
Julien Cabillot c5542d0baf feat: add gitea actions
Docker Build and Push / build (push) Successful in 1m43s
2026-05-29 13:26:42 -04:00
7 changed files with 291 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
name: Nightly Rebuild
on:
schedule:
- cron: '0 0 * * *'
jobs:
hadolint:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
- uses: hadolint/hadolint-action@2332a7b74a6de0dda2e2221d575162eba76ba5e5 # v3.3.0
with:
dockerfile: Dockerfile
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
- uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4
- run: docker build -t ci-image:${{ github.sha }} .
- run: bash tests/test.sh ci-image:${{ github.sha }}
build-push:
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
with:
fetch-depth: 0
- uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4
- uses: docker/login-action@650006c6eb7dba73a995cc03b0b2df7f5ca915bee # v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- id: get-latest-tag
run: |
TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
echo "tag=$TAG" >> $GITHUB_OUTPUT
- id: meta
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6
with:
images: jcabillot/ip
tags: |
type=raw,value=${{ steps.get-latest-tag.outputs.tag }}-latest,enable=${{ steps.get-latest-tag.outputs.tag != '' }}
- uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
pull: true
+49
View File
@@ -0,0 +1,49 @@
name: Main Release
on:
push:
branches: [master]
jobs:
hadolint:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
- uses: hadolint/hadolint-action@2332a7b74a6de0dda2e2221d575162eba76ba5e5 # v3.3.0
with:
dockerfile: Dockerfile
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
- uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4
- run: docker build -t ci-image:${{ github.sha }} .
- run: bash tests/test.sh ci-image:${{ github.sha }}
build:
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
- uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4
- run: docker build -t jcabillot/ip:${{ github.sha }} .
tag:
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
with:
fetch-depth: 0
- name: Configure git auth
run: |
git remote set-url origin "https://x-access-token:${{ secrets.SA_TOKEN_ACTION_PUSH_TAGS }}@scm.cabillot.eu/web/ip.git"
- uses: anothrNick/github-tag-action@4ed44965e0db8dab2b466a16da04aec3cc312fd8 # v1.75.0
env:
GITHUB_TOKEN: ${{ secrets.SA_TOKEN_ACTION_PUSH_TAGS }}
DEFAULT_BUMP: patch
RELEASE_BRANCHES: master
WITH_V: true
GIT_API_TAGGING: false
+22
View File
@@ -0,0 +1,22 @@
name: PR Checks
on:
pull_request:
branches: [master]
jobs:
hadolint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
- uses: hadolint/hadolint-action@2332a7b74a6de0dda2e2221d575162eba76ba5e5 # v3.3.0
with:
dockerfile: Dockerfile
build-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
- uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4
- run: docker build -t ci-image:${{ github.sha }} .
- run: bash tests/test.sh ci-image:${{ github.sha }}
+48
View File
@@ -0,0 +1,48 @@
name: Tag Release
on:
push:
tags: ['*']
jobs:
hadolint:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
- uses: hadolint/hadolint-action@2332a7b74a6de0dda2e2221d575162eba76ba5e5 # v3.3.0
with:
dockerfile: Dockerfile
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
- uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4
- run: docker build -t ci-image:${{ github.sha }} .
- run: bash tests/test.sh ci-image:${{ github.sha }}
build-push:
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
- uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4
- uses: docker/login-action@650006c6eb7dba73a995cc03b0b2df7f5ca915bee # v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- id: meta
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6
with:
images: jcabillot/ip
tags: |
type=ref,event=tag
type=ref,event=tag,suffix=-latest
- uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
pull: true
+30
View File
@@ -0,0 +1,30 @@
# AGENTS.md
## 1. Overview
Lightweight PHP micro-service that returns the client's public IP address as JSON. Containerized with Docker and deployed on Kubernetes.
## 2. Folder Structure
- `root/`: Application source code served by Apache.
- `index.php`: Single endpoint returning `REMOTE_ADDR` as JSON.
- `.gitea/workflows/`: Gitea Actions CI pipelines.
- `docker-build.yaml`: Build and push Docker image to Docker Hub on push/PR to master + daily cron.
- `Dockerfile`: Multi-stage build extending `jcabillot/phpapache` base image, copies `root/` into `/var/www/html`.
- `.gitlab-ci.yml`: Legacy GitLab CI config (deprecated, replaced by Gitea Actions).
- `Jenkinsfile`: Legacy Jenkins pipeline (deprecated, replaced by Gitea Actions).
## 3. Core Behaviors & Patterns
- **Request/Response Flow**: Single PHP endpoint sets `Content-Type: application/json` header and returns `$_SERVER['REMOTE_ADDR']` encoded as JSON string. No routing, no framework, no state.
- **Container Base Image Pattern**: `Dockerfile` uses `ARG VERSION="latest"` to allow version pinning at build time, extends `jcabillot/phpapache` which provides PHP + Apache pre-configured. Application code is layered on top via `COPY root /var/www/html`.
- **Traefik IngressRoute with HTTPS Redirect**: Two IngressRoute resources handle traffic — `ip-websecure` serves HTTPS on the `websecure` entrypoint, `ip-web` catches HTTP on `web` entrypoint and applies a `redirectScheme` middleware for permanent HTTPS redirect. The Service reference in the HTTP IngressRoute is required by Traefik even though the middleware intercepts before reaching it.
- **Health Probes**: Deployment defines both `livenessProbe` and `readinessProbe` using `httpGet` on `/` at the named `http` port (8080). Kubernetes uses these to restart unhealthy pods and exclude unready pods from the Service endpoints.
- **Security Hardening**: Pod spec sets `automountServiceAccountToken: false` to prevent unnecessary Kubernetes API access from the container.
## 4. Conventions
- **Kubernetes Labels**: Pods use `app: "front"` for Service selector matching and `owner: "jcabillot"` for resource attribution. Deployment-level labels use `app: "front"`.
- **Named Ports**: Container port is named `http` (8080) and referenced by name in probes and Service targetPort, avoiding hardcoded port numbers.
- **Docker Image Tagging**: CI uses `docker/metadata-action` to generate tags — `latest` for master branch pushes, branch/PR/SHA tags for other events. Push is skipped on pull requests.
- **CI Secrets**: Docker Hub credentials are stored as Gitea Actions secrets (`DOCKERHUB_USERNAME`, `DOCKERHUB_TOKEN`), never hardcoded.
+17
View File
@@ -0,0 +1,17 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"customManagers": [
{
"customType": "regex",
"description": "Detect ARG VERSION pin for jcabillot/phpapache base image",
"managerFilePatterns": [
"/^Dockerfile$/"
],
"matchStrings": [
"ARG\\s+VERSION=\"(?<currentValue>[^\"]+)\""
],
"depNameTemplate": "jcabillot/phpapache",
"datasourceTemplate": "docker"
}
]
}
Executable
+72
View File
@@ -0,0 +1,72 @@
#!/usr/bin/env bash
set -euo pipefail
IMAGE="${1:?Usage: test.sh <image>}"
CONTAINER_NAME="test-$(echo "$IMAGE" | tr ':/' '-')-$$"
PASSED=0
FAILED=0
TOTAL=0
cleanup() {
docker rm -f "$CONTAINER_NAME" >/dev/null 2>&1 || true
}
trap cleanup EXIT
assert() {
local name="$1" expected="$2" actual="$3"
TOTAL=$((TOTAL + 1))
if [ "$expected" = "$actual" ]; then
echo " PASS: $name"
PASSED=$((PASSED + 1))
else
echo " FAIL: $name (expected: '$expected', got: '$actual')"
FAILED=$((FAILED + 1))
fi
}
assert_match() {
local name="$1" pattern="$2" actual="$3"
TOTAL=$((TOTAL + 1))
if echo "$actual" | grep -qE "$pattern"; then
echo " PASS: $name"
PASSED=$((PASSED + 1))
else
echo " FAIL: $name (pattern: '$pattern', got: '$actual')"
FAILED=$((FAILED + 1))
fi
}
echo "Running container: $IMAGE"
docker run -d --name "$CONTAINER_NAME" -p 8080:8080 "$IMAGE" >/dev/null
DOCKER_GW=$(docker network inspect bridge --format '{{range .IPAM.Config}}{{.Gateway}}{{end}}')
BASE_URL="http://${DOCKER_GW}:8080"
echo "Waiting for container on ${DOCKER_GW}:8080..."
for i in $(seq 1 30); do
if curl -sf "$BASE_URL/" >/dev/null 2>&1; then
echo "Container ready after ${i}s"
break
fi
if [ "$i" -eq 30 ]; then
echo "FAIL: Container did not become ready within 30s"
docker logs "$CONTAINER_NAME"
exit 1
fi
sleep 1
done
echo ""
echo "Test: GET /"
RESPONSE=$(curl -sf -D - "$BASE_URL/")
STATUS=$(echo "$RESPONSE" | head -1 | grep -oP '\d{3}')
CONTENT_TYPE=$(echo "$RESPONSE" | grep -i 'content-type' | tr -d '\r' | cut -d: -f2- | xargs)
BODY=$(echo "$RESPONSE" | tail -1)
assert "HTTP status is 200" "200" "$STATUS"
assert_match "Content-Type is application/json" "application/json" "$CONTENT_TYPE"
assert_match "Body contains valid IP" '^(\"[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\"|\"[0-9a-fA-F:]+\")$' "$BODY"
echo ""
echo "Results: $PASSED/$TOTAL passed, $FAILED failed"
[ "$FAILED" -eq 0 ]