diff --git a/.forgejo/workflows/ansible.yml b/.forgejo/workflows/ansible.yml index e6c905e..196a689 100644 --- a/.forgejo/workflows/ansible.yml +++ b/.forgejo/workflows/ansible.yml @@ -1,10 +1,14 @@ +# Workflow name +name: Build and Push Ansible Container + +# Run-name for each workflow run run-name: Build and Push Ansible Container on: push: branches: - main paths: - - 'containers/${{ github.workflow }}/**' # This path will look for 'containers/Build and Push Ansible Container/**' + - 'containers/ansible/**' - '.forgejo/workflows/ansible.yml' workflow_dispatch: {} schedule: @@ -16,20 +20,29 @@ jobs: matrix: arch: [ amd64, arm64 ] runs-on: ${{ matrix.arch }} - container: - image: node:latest - volumes: - - /var/run/docker.sock:/var/run/docker.sock + services: + dind: + image: docker:dind + privileged: true + env: + DOCKER_HOST: tcp://dind:2375 steps: - - - name: Install Docker CLI - run: | - apt-get update - apt-get install -y docker.io - - name: Checkout repository uses: actions/checkout@v4 + - name: Wait for Docker to start + run: | + i=0 + while ! docker info >/dev/null 2>&1; + i=$((i+1)) + if [ $i -ge 15 ]; then + echo "Docker did not start within 15 seconds" + exit 1 + fi + echo "Waiting for Docker to start..." + sleep 1 + done + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -40,30 +53,40 @@ jobs: username: ${{ secrets.CI_REGISTRY_USER }} password: ${{ secrets.CI_TOKEN }} - # Removed the `cd` step as `context` and `file` can handle the path directly. - - name: Build and push (${{ matrix.arch }}) uses: docker/build-push-action@v5 with: - context: ./containers/${{ github.workflow }}/ # Relative to the checkout root - file: ./containers/${{ github.workflow }}/Dockerfile # Relative to the checkout root + context: ./containers/ansible/ + file: ./containers/ansible/Dockerfile platforms: linux/${{ matrix.arch }} push: true tags: | - ${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}:${{ matrix.arch }}-latest - cache-from: type=registry,ref=${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}:buildcache-${{ matrix.arch }} # Add caching - cache-to: type=registry,ref=${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}:buildcache-${{ matrix.arch }},mode=max # Add caching + ${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}/ansible:${{ matrix.arch }}-latest + cache-from: type=registry,ref=${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}/ansible:buildcache-${{ matrix.arch }} + cache-to: type=registry,ref=${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}/ansible:buildcache-${{ matrix.arch }},mode=max manifest: needs: build-and-push - runs-on: ubuntu-latest # or amd64 if you have a specific AMD64 runner for manifest creation + runs-on: amd64 + services: + dind: + image: docker:dind + privileged: true + env: + DOCKER_HOST: tcp://dind:2375 steps: - - name: Install Docker CLI + - name: Wait for Docker to start run: | - # Ensure docker CLI is available in the runner environment for `docker manifest` - # Most `ubuntu-latest` runners already have it, but explicit is better. - sudo apt-get update - sudo apt-get install -y docker-ce-cli # Install only the client if the runner is not dind + i=0 + while ! docker info >/dev/null 2>&1; + i=$((i+1)) + if [ $i -ge 15 ]; then + echo "Docker did not start within 15 seconds" + exit 1 + fi + echo "Waiting for Docker to start..." + sleep 1 + done - name: Login to Forgejo Registry uses: docker/login-action@v3 @@ -74,8 +97,7 @@ jobs: - name: Create and push multi-arch manifest run: | - # Use the explicit "docker" command which should be available - docker manifest create ${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}:latest \ - ${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}:amd64-latest \ - ${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}:arm64-latest - docker manifest push ${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}:latest + docker manifest create ${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}/ansible:latest \ + --amend ${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}/ansible:amd64-latest \ + --amend ${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}/ansible:arm64-latest + docker manifest push ${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}/ansible:latest diff --git a/.forgejo/workflows/dockerindocker.yml b/.forgejo/workflows/dockerindocker.yml index 4f0e503..8de2fef 100644 --- a/.forgejo/workflows/dockerindocker.yml +++ b/.forgejo/workflows/dockerindocker.yml @@ -28,16 +28,40 @@ jobs: # Use a runner that matches the architecture. # This assumes you have runners tagged with 'amd64' and 'arm64'. runs-on: ${{ matrix.arch }} + # Add a Docker-in-Docker service to the job. + # This is necessary to build Docker images. + # The 'privileged' flag is required for the Docker daemon to run. + services: + dind: + image: docker:dind + privileged: true + # Set the DOCKER_HOST environment variable to connect to the dind service. + env: + DOCKER_HOST: tcp://dind:2375 steps: # 1. Check out the repository code - name: Checkout repository uses: actions/checkout@v4 - # 2. Set up Docker Buildx for multi-platform builds + # 2. Wait for the Docker daemon to be ready + - name: Wait for Docker to start + run: | + i=0 + while ! docker info >/dev/null 2>&1; do + i=$((i+1)) + if [ $i -ge 15 ]; then + echo "Docker did not start within 15 seconds" + exit 1 + fi + echo "Waiting for Docker to start..." + sleep 1 + done + + # 3. Set up Docker Buildx for multi-platform builds - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - # 3. Login to the Forgejo container registry + # 4. Login to the Forgejo container registry # Requires CI_REGISTRY, CI_REGISTRY_USER, and CI_TOKEN secrets to be set in Forgejo. - name: Login to Forgejo Registry uses: docker/login-action@v3 @@ -46,7 +70,7 @@ jobs: username: ${{ secrets.CI_REGISTRY_USER }} password: ${{ secrets.CI_TOKEN }} - # 4. Build and push the Docker image for the specific architecture + # 5. Build and push the Docker image for the specific architecture - name: Build and push (${{ matrix.arch }}) uses: docker/build-push-action@v5 with: @@ -65,8 +89,32 @@ jobs: needs: build-and-push # A standard runner is sufficient for creating a manifest runs-on: amd64 + # Add a Docker-in-Docker service to the job. + # This is necessary to create the manifest. + # The 'privileged' flag is required for the Docker daemon to run. + services: + dind: + image: docker:dind + privileged: true + # Set the DOCKER_HOST environment variable to connect to the dind service. + env: + DOCKER_HOST: tcp://dind:2375 steps: - # 1. Login to the Forgejo container registry again + # 1. Wait for the Docker daemon to be ready + - name: Wait for Docker to start + run: | + i=0 + while ! docker info >/dev/null 2>&1; do + i=$((i+1)) + if [ $i -ge 15 ]; then + echo "Docker did not start within 15 seconds" + exit 1 + fi + echo "Waiting for Docker to start..." + sleep 1 + done + + # 2. Login to the Forgejo container registry again - name: Login to Forgejo Registry uses: docker/login-action@v3 with: @@ -74,7 +122,7 @@ jobs: username: ${{ secrets.CI_REGISTRY_USER }} password: ${{ secrets.CI_TOKEN }} - # 2. Create and push the multi-arch manifest + # 3. Create and push the multi-arch manifest # This combines the amd64 and arm64 images under a single 'latest' tag. - name: Create and push multi-arch manifest run: |