|
| 1 | +name: Build and Publish Docker image |
| 2 | + |
| 3 | + |
| 4 | +on: |
| 5 | + release: |
| 6 | + types: [published] |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + paths: |
| 11 | + - SGXDev/** |
| 12 | + - SGXSolDev/** |
| 13 | + - .github/workflows/build-sgx-dev.yaml |
| 14 | + |
| 15 | + |
| 16 | +jobs: |
| 17 | + build_sgx_dev: |
| 18 | + name: Build and publish SGX Dev image |
| 19 | + runs-on: ubuntu-22.04 |
| 20 | + permissions: |
| 21 | + packages: write |
| 22 | + contents: read |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Check out the repo |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Set up Docker Buildx |
| 29 | + uses: docker/setup-buildx-action@v2 |
| 30 | + |
| 31 | + - name: Log in to the Container registry |
| 32 | + uses: docker/login-action@v3 |
| 33 | + with: |
| 34 | + registry: ghcr.io |
| 35 | + username: ${{ github.actor }} |
| 36 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + |
| 38 | + - name: Generate package repo name |
| 39 | + id: ghcr_repo |
| 40 | + run: echo "path=ghcr.io/${{ github.repository_owner }}/decent-sgxdev" | tr '[:upper:]' '[:lower:]' >> $GITHUB_OUTPUT |
| 41 | + |
| 42 | + - name: Extract metadata (tags, labels) for Docker |
| 43 | + id: meta |
| 44 | + uses: docker/metadata-action@v5 |
| 45 | + with: |
| 46 | + images: | |
| 47 | + ${{ steps.ghcr_repo.outputs.path }} |
| 48 | +
|
| 49 | + - name: Get current commit SHA short |
| 50 | + id: commit_sha |
| 51 | + run: echo "short=$(git rev-parse --short HEAD)" | tr '[:upper:]' '[:lower:]' >> $GITHUB_OUTPUT |
| 52 | + |
| 53 | + - name: Manually generate sha tag |
| 54 | + id: tag_sha |
| 55 | + run: echo "tag=${{ steps.ghcr_repo.outputs.path }}:${{ steps.commit_sha.outputs.short }}" >> $GITHUB_OUTPUT |
| 56 | + |
| 57 | + - name: Manually generate ver tag |
| 58 | + if: ${{ startsWith(github.ref, 'refs/tags/') }} |
| 59 | + id: tag_ver |
| 60 | + run: echo "tag=${{ steps.ghcr_repo.outputs.path }}:${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 61 | + |
| 62 | + - name: Build and push Docker images for each commit |
| 63 | + uses: docker/build-push-action@v5 |
| 64 | + if: ${{ !startsWith(github.ref, 'refs/tags/') }} |
| 65 | + with: |
| 66 | + context: ./SGXDev |
| 67 | + platforms: linux/amd64 |
| 68 | + push: true |
| 69 | + tags: | |
| 70 | + ${{ steps.tag_sha.outputs.tag }} |
| 71 | + labels: ${{ steps.meta.outputs.labels }} |
| 72 | + |
| 73 | + - name: Create and push a manifest with ver referencing latest commit |
| 74 | + if: ${{ startsWith(github.ref, 'refs/tags/') }} |
| 75 | + run: | |
| 76 | + docker buildx imagetools create \ |
| 77 | + -t ${{ steps.tag_ver.outputs.tag }} \ |
| 78 | + ${{ steps.tag_sha.outputs.tag }} |
| 79 | +
|
| 80 | +
|
| 81 | + build_sgx_sol_dev: |
| 82 | + name: Build and publish SGX Solidity Dev image |
| 83 | + needs: [ build_sgx_dev ] |
| 84 | + runs-on: ubuntu-22.04 |
| 85 | + permissions: |
| 86 | + packages: write |
| 87 | + contents: read |
| 88 | + |
| 89 | + steps: |
| 90 | + - name: Check out the repo |
| 91 | + uses: actions/checkout@v4 |
| 92 | + |
| 93 | + - name: Set up Docker Buildx |
| 94 | + uses: docker/setup-buildx-action@v2 |
| 95 | + |
| 96 | + - name: Log in to the Container registry |
| 97 | + uses: docker/login-action@v3 |
| 98 | + with: |
| 99 | + registry: ghcr.io |
| 100 | + username: ${{ github.actor }} |
| 101 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 102 | + |
| 103 | + - name: Generate package repo name |
| 104 | + id: ghcr_repo |
| 105 | + run: echo "path=ghcr.io/${{ github.repository_owner }}/decent-sgxsoldev" | tr '[:upper:]' '[:lower:]' >> $GITHUB_OUTPUT |
| 106 | + |
| 107 | + - name: Extract metadata (tags, labels) for Docker |
| 108 | + id: meta |
| 109 | + uses: docker/metadata-action@v5 |
| 110 | + with: |
| 111 | + images: | |
| 112 | + ${{ steps.ghcr_repo.outputs.path }} |
| 113 | +
|
| 114 | + - name: Get current commit SHA short |
| 115 | + id: commit_sha |
| 116 | + run: echo "short=$(git rev-parse --short HEAD)" | tr '[:upper:]' '[:lower:]' >> $GITHUB_OUTPUT |
| 117 | + |
| 118 | + - name: Manually generate sha tag |
| 119 | + id: tag_sha |
| 120 | + run: echo "tag=${{ steps.ghcr_repo.outputs.path }}:${{ steps.commit_sha.outputs.short }}" >> $GITHUB_OUTPUT |
| 121 | + |
| 122 | + - name: Manually generate ver tag |
| 123 | + if: ${{ startsWith(github.ref, 'refs/tags/') }} |
| 124 | + id: tag_ver |
| 125 | + run: echo "tag=${{ steps.ghcr_repo.outputs.path }}:${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 126 | + |
| 127 | + - name: Build and push Docker images for each commit |
| 128 | + uses: docker/build-push-action@v5 |
| 129 | + if: ${{ !startsWith(github.ref, 'refs/tags/') }} |
| 130 | + with: |
| 131 | + context: ./SGXSolDev |
| 132 | + platforms: linux/amd64 |
| 133 | + build-args: | |
| 134 | + BASE_IMG_TAG=${{ steps.commit_sha.outputs.short }} |
| 135 | + push: true |
| 136 | + tags: | |
| 137 | + ${{ steps.tag_sha.outputs.tag }} |
| 138 | + labels: ${{ steps.meta.outputs.labels }} |
| 139 | + |
| 140 | + - name: Create and push a manifest with ver referencing latest commit |
| 141 | + if: ${{ startsWith(github.ref, 'refs/tags/') }} |
| 142 | + run: | |
| 143 | + docker buildx imagetools create \ |
| 144 | + -t ${{ steps.tag_ver.outputs.tag }} \ |
| 145 | + ${{ steps.tag_sha.outputs.tag }} |
| 146 | +
|
0 commit comments