Build Docker-outside-of-Docker Images #19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build Docker-outside-of-Docker Images | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "30 4 * * 3" # 04:30 UTC every Wednesday | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'src/*/*-dood/**' | |
| - '.github/workflows/build-dood.yml' | |
| workflow_run: | |
| workflows: ["Build Base Common Images"] | |
| types: [completed] | |
| branches: [main] | |
| jobs: | |
| discover: | |
| name: Discover DooD Images | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Discover DooD image paths | |
| id: set-matrix | |
| run: | | |
| # Find all DooD images | |
| images=$(find src -name "metadata.json" -type f | while read -r metadata; do | |
| dir=$(dirname "$metadata") | |
| image_path="${dir#src/}" | |
| image_name=$(basename "$dir") | |
| # Include only *-dood images | |
| if [[ "$image_name" == *-dood ]]; then | |
| echo "$image_path" | |
| fi | |
| done | jq -R -s -c 'split("\n") | map(select(length > 0))') | |
| echo "matrix=$images" >> $GITHUB_OUTPUT | |
| echo "Found DooD images: $images" | |
| build: | |
| name: Build ${{ matrix.image }} | |
| needs: discover | |
| if: needs.discover.outputs.matrix != '[]' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| image: ${{ fromJson(needs.discover.outputs.matrix) }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 'lts/*' | |
| - name: Install dependencies | |
| run: npm install -g @devcontainers/cli | |
| - name: Read metadata | |
| id: metadata | |
| run: | | |
| platforms=$(jq -r '.platforms | join(",")' src/${{ matrix.image }}/metadata.json) | |
| name=$(jq -r '.name' src/${{ matrix.image }}/metadata.json) | |
| echo "platforms=$platforms" >> $GITHUB_OUTPUT | |
| echo "name=$name" >> $GITHUB_OUTPUT | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| with: | |
| platforms: ${{ steps.metadata.outputs.platforms }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Generate version tag | |
| id: version | |
| run: | | |
| DATE_TAG=$(date +%Y%m%d) | |
| VERSION="${DATE_TAG}.${{ github.run_number }}" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Build and push | |
| run: | | |
| devcontainer build \ | |
| --workspace-folder src/${{ matrix.image }} \ | |
| --platform ${{ steps.metadata.outputs.platforms }} \ | |
| --image-name ghcr.io/${{ github.repository }}/${{ steps.metadata.outputs.name }}:latest \ | |
| --image-name ghcr.io/${{ github.repository }}/${{ steps.metadata.outputs.name }}:${{ steps.version.outputs.version }} \ | |
| --no-cache \ | |
| --push |