|
| 1 | +name: Upload Image |
| 2 | +on: |
| 3 | + workflow_dispatch: {} |
| 4 | + schedule: |
| 5 | + - cron: "0 18 * * *" |
| 6 | + release: |
| 7 | + types: [published] |
| 8 | + |
| 9 | +jobs: |
| 10 | + build-coredns: |
| 11 | + strategy: |
| 12 | + matrix: |
| 13 | + arch: [amd64, arm64] |
| 14 | + runs-on: ${{ fromJson('{"amd64":"ubuntu-latest", "arm64":["self-hosted", "Linux", "ARM64"]}')[matrix.arch] }} |
| 15 | + |
| 16 | + container: |
| 17 | + image: golang:1.13 |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Clone CoreDNS |
| 21 | + run: | |
| 22 | + apt update -y && apt install git make -y |
| 23 | +
|
| 24 | + git clone https://github.com/coredns/coredns.git . |
| 25 | + git checkout 7d5f5b87a4fb310d442f7ef0d52e3fead0e10d39 |
| 26 | + sed -i 's/stable/buster/g' Dockerfile |
| 27 | +
|
| 28 | + - uses: actions/checkout@v3 |
| 29 | + with: |
| 30 | + path: 'plugin/k8s_dns_chaos' |
| 31 | + |
| 32 | + - name: Build Chaos CoreDNS |
| 33 | + run: | |
| 34 | + sed -i '/kubernetes/a\k8s_dns_chaos\:k8s_dns_chaos' plugin.cfg |
| 35 | + go mod edit -require github.com/chaos-mesh/k8s_dns_chaos@649fd5298a454eb59b6080fd670e7f7ea1f5b1b4 |
| 36 | + SWAGGER=1 UI=1 make coredns |
| 37 | +
|
| 38 | + - name: upload coredns binary |
| 39 | + uses: actions/upload-artifact@v2 |
| 40 | + with: |
| 41 | + name: coredns-${{ matrix.arch }} |
| 42 | + path: coredns |
| 43 | + retention-days: 7 |
| 44 | + |
| 45 | + build-docker-image: |
| 46 | + strategy: |
| 47 | + matrix: |
| 48 | + arch: [amd64, arm64] |
| 49 | + runs-on: ${{ fromJson('{"amd64":"ubuntu-latest", "arm64":["self-hosted", "Linux", "ARM64"]}')[matrix.arch] }} |
| 50 | + outputs: |
| 51 | + image_tag: ${{ steps.image_tag.outputs.image_tag }} |
| 52 | + needs: build-coredns |
| 53 | + steps: |
| 54 | + - name: Extract Image Tag |
| 55 | + shell: bash |
| 56 | + run: | |
| 57 | + IMAGE_TAG=${GITHUB_REF##*/} |
| 58 | + if [ "${IMAGE_TAG}" = "master" ] ; then |
| 59 | + IMAGE_TAG=latest; |
| 60 | + fi |
| 61 | +
|
| 62 | + echo "::set-output name=image_tag::$(echo $IMAGE_TAG)" |
| 63 | + id: image_tag |
| 64 | + |
| 65 | + - name: Log in to GitHub Docker Registry |
| 66 | + uses: docker/login-action@v1 |
| 67 | + with: |
| 68 | + registry: ghcr.io |
| 69 | + username: ${{ github.actor }} |
| 70 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + |
| 72 | + - name: Clone CoreDNS |
| 73 | + run: | |
| 74 | + apt update -y && apt install git make -y |
| 75 | +
|
| 76 | + git clone https://github.com/coredns/coredns.git . |
| 77 | + git checkout 7d5f5b87a4fb310d442f7ef0d52e3fead0e10d39 |
| 78 | + sed -i 's/stable/buster/g' Dockerfile |
| 79 | +
|
| 80 | + - name: Download coredns binary |
| 81 | + uses: actions/download-artifact@v2 |
| 82 | + with: |
| 83 | + name: coredns-${{ matrix.arch }} |
| 84 | + path: coredns |
| 85 | + |
| 86 | + - name: Build Chaos CoreDNS Image |
| 87 | + env: |
| 88 | + IMAGE_TAG: ${{ steps.image_tag.outputs.image_tag }} |
| 89 | + ARCH: ${{ matrix.arch }} |
| 90 | + GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }} |
| 91 | + run: | |
| 92 | + docker build -t ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG-$ARCH . |
| 93 | +
|
| 94 | + - name: Upload Chaos CoreDNS |
| 95 | + env: |
| 96 | + IMAGE_TAG: ${{ steps.image_tag.outputs.image_tag }} |
| 97 | + ARCH: ${{ matrix.arch }} |
| 98 | + GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }} |
| 99 | + run: | |
| 100 | + # ${VAR,,} convert VAR to lower case |
| 101 | + docker push ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG-$ARCH |
| 102 | +
|
| 103 | + upload-manifest: |
| 104 | + runs-on: ubuntu-latest |
| 105 | + needs: build-docker-image |
| 106 | + steps: |
| 107 | + - name: Build Chaos Mesh manifest |
| 108 | + env: |
| 109 | + IMAGE_TAG: ${{ needs.build-docker-image.outputs.image_tag }} |
| 110 | + GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }} |
| 111 | + run: | |
| 112 | + # ${VAR,,} convert VAR to lower case |
| 113 | + docker manifest create ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG \ |
| 114 | + ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG-amd64 \ |
| 115 | + ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG-arm64 |
| 116 | +
|
| 117 | + docker manifest annotate ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG \ |
| 118 | + ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG-amd64 \ |
| 119 | + --os linux --arch amd64 |
| 120 | + docker manifest annotate ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG \ |
| 121 | + ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG-arm64 \ |
| 122 | + --os linux --arch arm64 |
| 123 | +
|
| 124 | + - name: Log in to GitHub Docker Registry |
| 125 | + uses: docker/login-action@v1 |
| 126 | + with: |
| 127 | + registry: ghcr.io |
| 128 | + username: ${{ github.actor }} |
| 129 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 130 | + |
| 131 | + - name: Upload Chaos Mesh |
| 132 | + env: |
| 133 | + IMAGE: ${{ matrix.image }} |
| 134 | + IMAGE_TAG: ${{ needs.build-docker-image.outputs.image_tag }} |
| 135 | + GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }} |
| 136 | + run: | |
| 137 | + # ${VAR,,} convert VAR to lower case |
| 138 | + docker manifest push ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/chaos-coredns:$IMAGE_TAG |
0 commit comments