|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "main" |
| 7 | + paths: |
| 8 | + - ".github/image/Dockerfile" |
| 9 | + - ".github/workflows/build.yml" |
| 10 | + - "operator/**" |
| 11 | + - "proxy/**" |
| 12 | + |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + continue-on-error: true |
| 16 | + |
| 17 | + strategy: |
| 18 | + matrix: |
| 19 | + include: |
| 20 | + - release_for: Linux-x86_64 |
| 21 | + build_on: ubuntu-22.04 |
| 22 | + target: x86_64-unknown-linux-gnu |
| 23 | + args: "--locked --release" |
| 24 | + |
| 25 | + - release_for: Linux-arm64 |
| 26 | + build_on: ubuntu-22.04-arm |
| 27 | + target: "aarch64-unknown-linux-gnu" |
| 28 | + args: "--locked --release" |
| 29 | + |
| 30 | + runs-on: ${{ matrix.build_on }} |
| 31 | + |
| 32 | + steps: |
| 33 | + - name: checkout repository |
| 34 | + uses: actions/checkout@v4 |
| 35 | + |
| 36 | + - uses: Swatinem/rust-cache@v2 |
| 37 | + with: |
| 38 | + shared-key: "release" |
| 39 | + |
| 40 | + - name: Install stable toolchain |
| 41 | + uses: actions-rs/toolchain@v1 |
| 42 | + with: |
| 43 | + toolchain: stable |
| 44 | + |
| 45 | + - name: Run cargo build |
| 46 | + run: cargo build --target ${{ matrix.target }} ${{ matrix.args }} |
| 47 | + |
| 48 | + - name: rename binaries |
| 49 | + run: | |
| 50 | + mv target/${{ matrix.target }}/release/controller${{ matrix.ext }} controller-${{ matrix.release_for }}${{ matrix.ext }} |
| 51 | + mv target/${{ matrix.target }}/release/proxy${{ matrix.ext }} proxy-${{ matrix.release_for }}${{ matrix.ext }} |
| 52 | +
|
| 53 | + - name: upload controller |
| 54 | + uses: actions/upload-artifact@v4 |
| 55 | + with: |
| 56 | + name: binaries-controller-${{ matrix.release_for }} |
| 57 | + path: controller-${{ matrix.release_for }}${{ matrix.ext }} |
| 58 | + |
| 59 | + - name: upload proxy |
| 60 | + uses: actions/upload-artifact@v4 |
| 61 | + with: |
| 62 | + name: binaries-proxy-${{ matrix.release_for }} |
| 63 | + path: proxy-${{ matrix.release_for }}${{ matrix.ext }} |
| 64 | + |
| 65 | + docker: |
| 66 | + runs-on: ubuntu-latest |
| 67 | + needs: [build] |
| 68 | + |
| 69 | + strategy: |
| 70 | + matrix: |
| 71 | + include: |
| 72 | + - tags: ghcr.io/demeter-run/ext-cardano-submitapi-operator,ghcr.io/demeter-run/ext-cardano-submitapi-operator:${{ github.sha }} |
| 73 | + binary: controller |
| 74 | + - tags: ghcr.io/demeter-run/ext-cardano-submitapi-proxy,ghcr.io/demeter-run/ext-cardano-submitapi-proxy:${{ github.sha }} |
| 75 | + binary: proxy |
| 76 | + |
| 77 | + permissions: |
| 78 | + contents: read |
| 79 | + packages: write |
| 80 | + |
| 81 | + steps: |
| 82 | + - name: Checkout repository |
| 83 | + uses: actions/checkout@v4 |
| 84 | + |
| 85 | + - name: Set up Docker Buildx |
| 86 | + uses: docker/setup-buildx-action@v3 |
| 87 | + |
| 88 | + - name: Login to DockerHub |
| 89 | + uses: docker/login-action@v3 |
| 90 | + with: |
| 91 | + registry: ghcr.io |
| 92 | + username: ${{ github.actor }} |
| 93 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 94 | + |
| 95 | + - name: Download artifacts |
| 96 | + uses: actions/download-artifact@v4 |
| 97 | + with: |
| 98 | + pattern: binaries-* |
| 99 | + merge-multiple: true |
| 100 | + path: .github/image/bin |
| 101 | + |
| 102 | + # Add docker layer caching to avoid doing extra computation |
| 103 | + - uses: satackey/[email protected] |
| 104 | + continue-on-error: true |
| 105 | + |
| 106 | + # we need to rename the artifact so that the name matches |
| 107 | + # the value that Docker uses for TARGET_ARCH to keep the |
| 108 | + # Dockerfile simple |
| 109 | + - name: Rename artifacts |
| 110 | + run: |+ |
| 111 | + mv .github/image/bin/controller-Linux-x86_64 .github/image/bin/controller-Linux-amd64 |
| 112 | + mv .github/image/bin/proxy-Linux-x86_64 .github/image/bin/proxy-Linux-amd64 |
| 113 | +
|
| 114 | + - name: Build and push |
| 115 | + uses: docker/build-push-action@v5 |
| 116 | + with: |
| 117 | + context: .github/image |
| 118 | + platforms: linux/arm64,linux/amd64 |
| 119 | + push: true |
| 120 | + tags: ${{ matrix.tags }} |
| 121 | + build-args: BIN=${{ matrix.binary }} |
| 122 | + |
0 commit comments