Compare commits

..

No commits in common. "246a189bea909f885b98581f6615440ff5130806" and "6341aa84f48aac498bf4f83033141bae275e33a2" have entirely different histories.

3 changed files with 44 additions and 75 deletions

View file

@ -16,8 +16,8 @@ jobs:
publish: publish:
runs-on: docker runs-on: docker
env: env:
# Use explicit override when provided, otherwise use the known-good host # Allow explicit override from Forgejo variables.
DOCKER_HOST: ${{ vars.DOCKER_HOST != '' && vars.DOCKER_HOST || 'tcp://172.17.0.1:2375' }} DOCKER_HOST: ${{ vars.DOCKER_HOST }}
steps: steps:
- name: Checkout - name: Checkout
@ -65,29 +65,35 @@ jobs:
echo "${HOME}/.local/bin" >> "${GITHUB_PATH}" echo "${HOME}/.local/bin" >> "${GITHUB_PATH}"
"${HOME}/.local/bin/docker" --version "${HOME}/.local/bin/docker" --version
- name: Ensure Docker Buildx exists - name: Resolve Docker daemon endpoint
run: | run: |
set -eu set -eu
if docker buildx version >/dev/null 2>&1; then
docker buildx version if [ -n "${DOCKER_HOST:-}" ]; then
echo "Using configured DOCKER_HOST=${DOCKER_HOST}"
echo "DOCKER_HOST=${DOCKER_HOST}" >> "${GITHUB_ENV}"
exit 0 exit 0
fi fi
ARCH="$(uname -m)" if [ -S /var/run/docker.sock ]; then
case "${ARCH}" in echo "DOCKER_HOST=unix:///var/run/docker.sock" >> "${GITHUB_ENV}"
x86_64) BUILDX_ARCH="amd64" ;; echo "Resolved DOCKER_HOST from local docker socket"
aarch64|arm64) BUILDX_ARCH="arm64" ;; exit 0
*) echo "Unsupported architecture for Docker Buildx bootstrap: ${ARCH}"; exit 1 ;; fi
esac
BUILDX_VERSION="v0.21.1" # Try a set of common candidate endpoints reachable from inside job containers.
mkdir -p "${HOME}/.docker/cli-plugins" CANDIDATES="forgejo-docker-in-docker host.docker.internal 172.17.0.1 172.18.0.1 10.0.2.2"
curl -fsSL "https://github.com/docker/buildx/releases/download/${BUILDX_VERSION}/buildx-${BUILDX_VERSION}.linux-${BUILDX_ARCH}" -o "${HOME}/.docker/cli-plugins/docker-buildx" for c in $CANDIDATES; do
chmod +x "${HOME}/.docker/cli-plugins/docker-buildx" echo "Testing http://${c}:2375/_ping ..."
docker buildx version if curl --silent --max-time 2 "http://${c}:2375/_ping" >/dev/null 2>&1 || curl --silent --max-time 2 "http://${c}:2375/version" >/dev/null 2>&1; then
echo "DOCKER_HOST=tcp://${c}:2375" >> "${GITHUB_ENV}"
echo "Resolved DOCKER_HOST to tcp://${c}:2375"
exit 0
fi
done
# Simplified: we trust DOCKER_HOST (default to tcp://172.17.0.1:2375). If you echo "Could not determine a reachable Docker daemon endpoint from candidates. Set vars.DOCKER_HOST explicitly."
# need a different endpoint, set the Forgejo variable `DOCKER_HOST`. exit 1
- name: Check Docker daemon connectivity - name: Check Docker daemon connectivity
run: | run: |
@ -96,13 +102,6 @@ jobs:
docker version docker version
docker info >/dev/null docker info >/dev/null
- name: Create Buildx builder
run: |
set -eu
docker buildx rm forgejo-builder >/dev/null 2>&1 || true
docker buildx create --name forgejo-builder --driver docker-container --use
docker buildx inspect --bootstrap
- name: Restore and publish app - name: Restore and publish app
run: dotnet publish src/MaddoScientisto.Web/MaddoScientisto.Web.csproj -c Release -o ./artifacts/publish run: dotnet publish src/MaddoScientisto.Web/MaddoScientisto.Web.csproj -c Release -o ./artifacts/publish
@ -110,14 +109,17 @@ jobs:
run: | run: |
echo "${{ secrets.FORGEJO_REGISTRY_TOKEN }}" | docker login "${REGISTRY}" -u "${{ secrets.FORGEJO_REGISTRY_USERNAME }}" --password-stdin echo "${{ secrets.FORGEJO_REGISTRY_TOKEN }}" | docker login "${REGISTRY}" -u "${{ secrets.FORGEJO_REGISTRY_USERNAME }}" --password-stdin
- name: Build and push image - name: Build image
run: | run: |
set -eu set -eu
IMAGE_REF="${REGISTRY}/${IMAGE_NAMESPACE}/${IMAGE_NAME}" IMAGE_REF="${REGISTRY}/${IMAGE_NAMESPACE}/${IMAGE_NAME}"
SHORT_SHA="$(echo "${GITHUB_SHA}" | cut -c1-12)" SHORT_SHA="$(echo "${GITHUB_SHA}" | cut -c1-12)"
docker buildx build \ docker build -t "${IMAGE_REF}:sha-${SHORT_SHA}" -t "${IMAGE_REF}:latest" .
--builder forgejo-builder \
--tag "${IMAGE_REF}:sha-${SHORT_SHA}" \ - name: Push image tags
--tag "${IMAGE_REF}:latest" \ run: |
--push \ set -eu
. IMAGE_REF="${REGISTRY}/${IMAGE_NAMESPACE}/${IMAGE_NAME}"
SHORT_SHA="$(echo "${GITHUB_SHA}" | cut -c1-12)"
docker push "${IMAGE_REF}:sha-${SHORT_SHA}"
docker push "${IMAGE_REF}:latest"

View file

@ -34,30 +34,6 @@ docker run --rm -p 8080:80 maddoscientisto-web:local
Open `http://localhost:8080`. Open `http://localhost:8080`.
## Docker Compose deployment
A ready-to-use `docker-compose.yml` is included to build and run the site container. By default it maps container port `80` to host port `8002`.
Start the service (builds the image if needed) with:
```bash
docker compose up --build -d
```
Verify the site at:
```bash
curl http://localhost:8002/
```
To stop and remove the service:
```bash
docker compose down
```
You can customize the built image name and tag via environment variables read by Compose (`IMAGE_REGISTRY` and `IMAGE_TAG`), or edit `docker-compose.yml` to change the published host port.
## Forgejo registry configuration ## Forgejo registry configuration
Set these Forgejo Actions variables: Set these Forgejo Actions variables:
@ -74,7 +50,7 @@ Set these Forgejo Actions secrets:
## Workflow behavior ## Workflow behavior
The workflow in `.forgejo/workflows/publish-container.yml` runs on pushes to `master` (and manual dispatch), bootstraps Docker Buildx if needed, then builds and pushes the container image with BuildKit: The workflow in `.forgejo/workflows/publish-container.yml` runs on pushes to `master` (and manual dispatch), builds the container image, and pushes:
- `${FORGEJO_REGISTRY}/${IMAGE_NAMESPACE}/${IMAGE_NAME}:latest` - `${FORGEJO_REGISTRY}/${IMAGE_NAMESPACE}/${IMAGE_NAME}:latest`
- `${FORGEJO_REGISTRY}/${IMAGE_NAMESPACE}/${IMAGE_NAME}:sha-<12-char-commit>` - `${FORGEJO_REGISTRY}/${IMAGE_NAMESPACE}/${IMAGE_NAME}:sha-<12-char-commit>`
@ -83,6 +59,13 @@ The workflow in `.forgejo/workflows/publish-container.yml` runs on pushes to `ma
If the runner image does not contain the `docker` binary, the workflow bootstraps a Docker CLI in user space before login/build/push. If the runner image does not contain the `docker` binary, the workflow bootstraps a Docker CLI in user space before login/build/push.
If the runner image does not contain the Buildx plugin, the workflow also installs `docker-buildx` in the Docker CLI plugin directory before creating a builder. For dind-based runners, the workflow resolves `DOCKER_HOST` in this order:
For your current dind-based runner, the workflow defaults `DOCKER_HOST` to `tcp://172.17.0.1:2375` unless you set `vars.DOCKER_HOST` explicitly. - `vars.DOCKER_HOST` if explicitly set
- `/var/run/docker.sock` if mounted into the job
- `tcp://forgejo-docker-in-docker:2375` if that DNS name is visible inside the job container
- `tcp://<job-container-default-gateway>:2375` as a fallback for nested Docker bridge setups
If you still get connection failures after the CLI bootstrap step, set a repo variable named `DOCKER_HOST` to the daemon endpoint that is reachable from inside the job container.
Important: the Compose service name `forgejo-docker-in-docker` is often only resolvable from the outer runner container, not from the inner job container created by the Docker daemon. In that case, use the gateway-based fallback or set `DOCKER_HOST` explicitly.

View file

@ -1,16 +0,0 @@
version: '3.8'
services:
maddoscientisto-web:
build:
context: .
dockerfile: Dockerfile
image: ${IMAGE_REGISTRY:-maddoscientisto-web}:${IMAGE_TAG:-latest}
ports:
- "8002:80"
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1/ >/dev/null 2>&1 || exit 1"]
interval: 30s
timeout: 5s
retries: 3