4.4 KiB
tags
| tags | |||
|---|---|---|---|
|
To test and validate your docker-compose infrastructure configurations right inside your homelab, you can use Gitea Actions to automatically check your YAML syntax and test your container builds every time you make an edit. [1, 2]
Here is how to set up an automated testing pipeline specifically for a homelab Docker Compose repository.
🛠️ Step 1: Set Up the Workflow Directory
In your homelab Git repository containing your docker-compose.yml files, create the specific workflow path: [1]
- File path:
.gitea/workflows/docker-test.yaml
📝 Step 2: Paste the Homelab Validation Template
Copy and paste this template into your new file. It is optimized to perform two critical steps: lint your YAML formatting for typos, and dry-run your Docker Compose setup to ensure your container configurations are valid. [1, 2]
name: Docker Compose Validator
run-name: Homelab configuration test by ${{ gitea.actor }} 🛠️
on:
push:
branches: [ "main", "master" ]
pull_request:
branches: [ "main", "master" ]
jobs:
validate-and-test:
runs-on: ubuntu-latest
`steps:`
`# 1. Pull down your homelab repository code`
`- name: Checkout Repository Code`
`uses: actions/checkout@v4`
`# 2. Check all YAML files for syntax, indentation, and formatting errors`
`- name: Lint YAML Syntax`
`uses: https://github.com`
`with:`
`file_or_dir: "."`
`# 3. Verify that the docker-compose syntax is structurally sound`
`- name: Verify Compose File Validity`
`run: |`
`echo "Checking docker-compose configuration..."`
`docker compose config`
`# 4. Dry-run the build sequence to ensure images and contexts are reachable`
`- name: Test Build Sequence`
`run: |`
`echo "Simulating container build sequence..."`
`docker compose build`
🔍 Breaking Down How This Works for Homelabbers
- YAML Linting: Homelab configurations frequently break due to an accidental extra space or missing indentation. The
action-yamllintstep scans your files and alerts you to formatting errors before they hit your live system. docker compose config: This command acts as a built-in validator. It reads yourdocker-compose.ymlfile, processes any variables, and outputs an error if you have typos in your keys, volume definitions, or network syntax. [1, 2, 3]docker compose build: If your compose files use thebuild:block to compile local Dockerfiles instead of just pulling pre-made images, this step ensures your Dockerfiles successfully build without crashing.
⚠️ Crucial Homelab Gotchas to Keep in Mind
- Environment Variables (
.env): If yourdocker-compose.ymlrelies on an external.envfile containing local paths, secret tokens, or personal domain names,docker compose configwill fail in Gitea Actions because that file is missing. You should either add a.env.examplefile to your Git repository and rename it during the workflow run, or map those variables into Gitea Secrets. - Local Volume Paths: If your compose files map to absolute local storage paths (e.g.,
/mnt/user/appdata/nginx), the Gitea Act Runner environment won't have access to those actual directories. For testing purposes, it is safest to use relative paths (e.g.,./nginx/config) or let Docker generate named volumes during the validation phase. - Runner Capabilities: Ensure that your local
act_runnersetup has access to a Docker daemon. If you installed your runner using Docker-in-Docker (DinD), it will easily execute thedocker composecommands embedded in this workflow. [1]