Build and Publish Docker image to Docker Hub #409
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 and Publish Docker image to Docker Hub | |
| on: | |
| push: | |
| branches: | |
| - main | |
| schedule: | |
| # nightly run to pick up new Kubernetes stable version | |
| - cron: '0 0 * * *' | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| image: ${{ steps.tag.outputs.image }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v7 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v4 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Determine Kubernetes version | |
| id: tag | |
| shell: bash | |
| run: | | |
| # Fetch the upstream stable Kubernetes version (e.g. v1.24.7) | |
| K8S_VER=$(curl -Ls https://dl.k8s.io/release/stable.txt) | |
| # Strip leading 'v' | |
| IMAGE_TAG=${K8S_VER#v} | |
| echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV | |
| echo "image=${IMAGE_TAG}" >> $GITHUB_OUTPUT | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| tags: | | |
| oneidels/kubectl:${{ env.IMAGE_TAG }} | |
| oneidels/kubectl:latest | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| smoke-test: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v4 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Pull image for testing | |
| run: docker pull oneidels/kubectl:${{ needs.build.outputs.image }} | |
| - name: Smoke test kubectl | |
| run: docker run --rm oneidels/kubectl:${{ needs.build.outputs.image }} kubectl version --client | |
| - name: Smoke test helm | |
| run: docker run --rm oneidels/kubectl:${{ needs.build.outputs.image }} helm version |