|
| 1 | +# Github workflow that rebuilds already released images |
| 2 | + |
| 3 | +name: Daily build |
| 4 | +on: |
| 5 | + schedule: |
| 6 | + - cron: "0 1 * * 1-5" |
| 7 | + - cron: "0 3 * * 1-5" |
| 8 | + |
| 9 | +jobs: |
| 10 | + read-versions: |
| 11 | + name: Read config file |
| 12 | + runs-on: ubuntu-latest |
| 13 | + outputs: |
| 14 | + matrix: ${{ steps.images-matrix.outputs.matrix }} |
| 15 | + platforms: ${{ steps.images-matrix.outputs.platforms }} |
| 16 | + date: ${{ steps.set-date.outputs.date }} |
| 17 | + steps: |
| 18 | + - name: Check out code |
| 19 | + |
| 20 | + with: |
| 21 | + submodules: true |
| 22 | + fetch-depth: 0 |
| 23 | + - name: Read config file (daily-builds.json) |
| 24 | + id: images-matrix |
| 25 | + run: | |
| 26 | + CONTENT=`cat ./daily-builds.json` |
| 27 | + CONTENT="${CONTENT//'%'/'%25'}" |
| 28 | + echo matrix=${CONTENT} >> $GITHUB_OUTPUT |
| 29 | + - name: Set date |
| 30 | + id: set-date |
| 31 | + run: | |
| 32 | + DATE=$(date -f '%Y-%m-%d') |
| 33 | + echo date=${DATE} >> $GITHUB_OUTPUT |
| 34 | + |
| 35 | + build-and-publish-image: |
| 36 | + runs-on: ubuntu-latest |
| 37 | + env: |
| 38 | + IMAGE_REPOSITORY: mongodb/mongodb-atlas-kubernetes-operator |
| 39 | + needs: |
| 40 | + - read-versions |
| 41 | + strategy: |
| 42 | + matrix: |
| 43 | + version: ${{ fromJSON(needs.read-versions.outputs.matrix).versions }} |
| 44 | + steps: |
| 45 | + - name: Print daily tag |
| 46 | + id: daily-tag |
| 47 | + run: | |
| 48 | + DAILY_TAG="${{ matrix.version }}-${{needs.read-versions.outputs.date}}" |
| 49 | + echo "daily-tag=${DAILY_TAG}" >> $GITHUB_OUTPUT |
| 50 | + - name: Rebuild ${{matrix.version}} |
| 51 | + run: | |
| 52 | + echo "Building ${{matrix.version}} version" |
| 53 | + - name: Check out code |
| 54 | + |
| 55 | + with: |
| 56 | + ref: ${{ matrix.version }} |
| 57 | + submodules: true |
| 58 | + fetch-depth: 0 |
| 59 | + - name: "Set up QEMU" |
| 60 | + uses: docker/setup-qemu-action@v2 |
| 61 | + with: |
| 62 | + platforms: ${{ fromJSON(needs.read-versions.outputs.matrix).platforms }} |
| 63 | + - name: "Set up Docker Buildx" |
| 64 | + uses: docker/setup-buildx-action@v2 |
| 65 | + with: |
| 66 | + platforms: ${{ fromJSON(needs.read-versions.outputs.matrix).platforms }} |
| 67 | + - name: Login to docker registry |
| 68 | + uses: docker/login-action@v2 |
| 69 | + with: |
| 70 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 71 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 72 | + - name: Set up Go |
| 73 | + uses: actions/setup-go@v3 |
| 74 | + with: |
| 75 | + go-version-file: "${{ github.workspace }}/go.mod" |
| 76 | + - name: Setup cache |
| 77 | + uses: actions/cache@v3 |
| 78 | + with: |
| 79 | + path: | |
| 80 | + ~/.cache/go-build |
| 81 | + ~/go/pkg/mod |
| 82 | + key: ${{ runner.os }}-build-${{ hashFiles('**/go.sum') }} |
| 83 | + - name: Download go build dependencies |
| 84 | + shell: bash |
| 85 | + run: | |
| 86 | + go mod download |
| 87 | + - name: Build and push operator to the DockerHub (daily-tag) |
| 88 | + uses: docker/build-push-action@v3 |
| 89 | + with: |
| 90 | + context: . |
| 91 | + build-args: VERSION=${{ matrix.version }} |
| 92 | + platforms: ${{ fromJSON(needs.read-versions.outputs.matrix).platforms }} |
| 93 | + tags: ${{ env.IMAGE_REPOSITORY }}:${{ steps.daily-tag.outputs.daily-tag }} |
| 94 | + cache-from: type=gha |
| 95 | + cache-to: type=gha,mode=max |
| 96 | + push: true |
| 97 | + - name: Build and push operator to the DockerHub (release-tag) |
| 98 | + uses: docker/build-push-action@v3 |
| 99 | + with: |
| 100 | + context: . |
| 101 | + build-args: VERSION=${{ matrix.version }} |
| 102 | + platforms: ${{ fromJSON(needs.read-versions.outputs.matrix).platforms }} |
| 103 | + tags: ${{ env.IMAGE_REPOSITORY }}:${{ matrix.version }} |
| 104 | + cache-from: type=gha |
| 105 | + cache-to: type=gha,mode=max |
| 106 | + push: true |
0 commit comments