test multitags #21
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 | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| tags: | ||
| type: string | ||
| description: The Docker Tags (see docker/metadata-action@v4 for available values) | ||
| required: true | ||
| env: | ||
| IMAGE_REPOSITORY: ghcr.io/cooptilleuls/sre | ||
| BASE_IMAGE: ghcr.io/cooptilleuls/sre/kubectl | ||
| jobs: | ||
| fetch-data: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| versions: ${{ steps.data.outputs.versions }} | ||
| tags: ${{ steps.data.outputs.tags }} | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v3 | ||
| - name: 'Set up skopeo' | ||
| uses: warjiang/setup-skopeo@main | ||
| with: | ||
| version: latest | ||
| - id: data | ||
| run: | | ||
| python --version | ||
| export ALL_VERSIONS=$(skopeo list-tags docker://registry.k8s.io/kubectl | jq -r '.Tags | .[]| select(. | match("v[0-9].[0-9]{2}.[0-9]$"))') | ||
| python ./get_kubectl_versions.py > data.json | ||
| echo "versions=$(cat data.json )" >> "$GITHUB_OUTPUT" | ||
| echo "tags=$(cat data.json | jq -c 'keys')" >> "$GITHUB_OUTPUT" | ||
| build-kubectl: | ||
| runs-on: ubuntu-latest | ||
| needs: fetch-data | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| tag: ${{ fromJSON(needs.fetch-data.outputs.tags) }} | ||
| steps: | ||
| - name: test | ||
| run: echo "$OUTPUT1 $OUTPUT2 ${{matrix.tag}}" | ||
| - name: data | ||
| id: data | ||
| run: | | ||
| KUBECTL_VERSION=$(echo '${{needs.fetch-data.outputs.versions }}' | jq -r --arg KEY "${{ matrix.tag }}" '.[$KEY]') | ||
| echo "build_args=KUBECTL_VERSION=$KUBECTL_VERSION" >> "$GITHUB_OUTPUT" | ||
| echo "tags=${{ env.BASE_IMAGE }}:${KUBECTL_VERSION},${{BASE_IMAGE}}:${{matrix.tag}}" >> "$GITHUB_OUTPUT" | ||
| - name: Set up Docker Buildx | ||
| id: buildx | ||
| uses: docker/[email protected] | ||
| - name: Login to registry | ||
| uses: docker/login-action@v1 | ||
| with: | ||
| registry: ${{ env.IMAGE_REPOSITORY }} | ||
| username: _json_key | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Build image and push to registry | ||
| uses: docker/build-push-action@v6 | ||
| id: docker_build_push | ||
| env: | ||
| DOCKER_BUILD_SUMMARY: true | ||
| with: | ||
| context: ./kubectl | ||
| tags: ${{ steps.data.outputs.tags }} | ||
| build-args: ${{ steps.data.outputs.build_args }} | ||
| target: debian-kubectl | ||
| push: true | ||
| cache-from: | | ||
| type=gha | ||
| cache-to: | | ||
| type=gha,mode=max | ||