|
| 1 | +name: Upload Image |
| 2 | +on: |
| 3 | + workflow_dispatch: {} |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +jobs: |
| 8 | + build-docker-image: |
| 9 | + strategy: |
| 10 | + matrix: |
| 11 | + arch: [amd64, arm64] |
| 12 | + runs-on: ${{ fromJson('{"amd64":"ubuntu-latest", "arm64":["self-hosted", "Linux", "ARM64"]}')[matrix.arch] }} |
| 13 | + outputs: |
| 14 | + image_tag: ${{ steps.image_tag.outputs.image_tag }} |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v2 |
| 17 | + - |
| 18 | + name: Set up Docker Buildx |
| 19 | + uses: docker/setup-buildx-action@v2 |
| 20 | + - name: Extract Image Tag |
| 21 | + shell: bash |
| 22 | + run: | |
| 23 | + IMAGE_TAG=${GITHUB_REF##*/} |
| 24 | + if [ "${IMAGE_TAG}" = "master" ] ; then |
| 25 | + IMAGE_TAG=latest; |
| 26 | + fi |
| 27 | +
|
| 28 | + echo "::set-output name=image_tag::$(echo $IMAGE_TAG)" |
| 29 | + id: image_tag |
| 30 | + |
| 31 | + - name: Log in to GitHub Docker Registry |
| 32 | + uses: docker/login-action@v1 |
| 33 | + with: |
| 34 | + registry: ghcr.io |
| 35 | + username: ${{ github.actor }} |
| 36 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + |
| 38 | + - name: Build Chaos CoreDNS Image |
| 39 | + env: |
| 40 | + IMAGE_TAG: ${{ steps.image_tag.outputs.image_tag }} |
| 41 | + ARCH: ${{ matrix.arch }} |
| 42 | + GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }} |
| 43 | + run: | |
| 44 | + docker build -t ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG-$ARCH . |
| 45 | +
|
| 46 | + - name: Upload Chaos CoreDNS |
| 47 | + env: |
| 48 | + IMAGE_TAG: ${{ steps.image_tag.outputs.image_tag }} |
| 49 | + ARCH: ${{ matrix.arch }} |
| 50 | + GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }} |
| 51 | + run: | |
| 52 | + # ${VAR,,} convert VAR to lower case |
| 53 | + docker push ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG-$ARCH |
| 54 | +
|
| 55 | + upload-manifest: |
| 56 | + runs-on: ubuntu-latest |
| 57 | + needs: build-docker-image |
| 58 | + steps: |
| 59 | + - name: Build Chaos Mesh manifest |
| 60 | + env: |
| 61 | + IMAGE_TAG: ${{ needs.build-docker-image.outputs.image_tag }} |
| 62 | + GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }} |
| 63 | + run: | |
| 64 | + # ${VAR,,} convert VAR to lower case |
| 65 | + docker manifest create ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG \ |
| 66 | + ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG-amd64 \ |
| 67 | + ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG-arm64 |
| 68 | +
|
| 69 | + docker manifest annotate ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG \ |
| 70 | + ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG-amd64 \ |
| 71 | + --os linux --arch amd64 |
| 72 | + docker manifest annotate ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG \ |
| 73 | + ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG-arm64 \ |
| 74 | + --os linux --arch arm64 |
| 75 | +
|
| 76 | + - name: Log in to GitHub Docker Registry |
| 77 | + uses: docker/login-action@v1 |
| 78 | + with: |
| 79 | + registry: ghcr.io |
| 80 | + username: ${{ github.actor }} |
| 81 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + |
| 83 | + - name: Upload Chaos Mesh |
| 84 | + env: |
| 85 | + IMAGE: ${{ matrix.image }} |
| 86 | + IMAGE_TAG: ${{ needs.build-docker-image.outputs.image_tag }} |
| 87 | + GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }} |
| 88 | + run: | |
| 89 | + # ${VAR,,} convert VAR to lower case |
| 90 | + docker manifest push ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG |
0 commit comments