diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 1162c9d..26060cd 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -3,57 +3,61 @@ name: Docker CI on: workflow_call: inputs: - imagename: - description: 'A Docker image name passed from the caller workflow' + image-name: + description: 'A Docker image name passed from the caller workflow.' required: true type: string path: - description: 'A path containing a Dockerfile passed from the caller workflow' + description: 'A path containing a Dockerfile passed from the caller workflow.' required: true type: string - chaincode: - description: 'A boolean indicating whether to create a chaincode package passed from the caller workflow' + chaincode-label: + description: 'An optional chaincode label passed from the caller workflow. If present, will prepare a chaincode package.' required: false - default: false - type: boolean + type: string jobs: build: runs-on: ubuntu-latest outputs: - image_digest: ${{ steps.publish_image.outputs.image_digest }} + image_digest: ${{ steps.push.outputs.digest }} steps: - - uses: actions/checkout@v3 - - name: Build Docker image - run: | - docker build ${DOCKER_BUILD_PATH} --file ${DOCKER_BUILD_PATH}/Dockerfile --label "org.opencontainers.image.revision=${GITHUB_SHA}" --tag ${IMAGE_NAME} - docker tag ${IMAGE_NAME} ghcr.io/hyperledger-labs/${IMAGE_NAME}:${GITHUB_SHA} - if [ "${GITHUB_REF:0:10}" = "refs/tags/" ]; then - docker tag ${IMAGE_NAME} ghcr.io/hyperledger-labs/${IMAGE_NAME}:${GITHUB_REF_NAME} - docker tag ${IMAGE_NAME} ghcr.io/hyperledger-labs/${IMAGE_NAME}:latest - fi - env: - DOCKER_BUILD_PATH: ${{ inputs.path }} - IMAGE_NAME: ${{ inputs.imagename }} - - name: Publish Docker image - id: publish_image - if: github.event_name != 'pull_request' - run: | - echo ${DOCKER_PW} | docker login ghcr.io -u ${DOCKER_USER} --password-stdin - docker push ghcr.io/hyperledger-labs/${IMAGE_NAME}:${GITHUB_SHA} - if [ "${GITHUB_REF:0:10}" = "refs/tags/" ]; then - docker push ghcr.io/hyperledger-labs/${IMAGE_NAME}:${GITHUB_REF_NAME} - docker push ghcr.io/hyperledger-labs/${IMAGE_NAME}:latest - fi - echo ::set-output name=image_digest::$(docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/hyperledger-labs/${IMAGE_NAME}:${GITHUB_SHA} | cut -d'@' -f2) - env: - IMAGE_NAME: ${{ inputs.imagename }} - DOCKER_USER: ${{ github.actor }} - DOCKER_PW: ${{ secrets.GITHUB_TOKEN }} + - name: Checkout + uses: actions/checkout@v3 + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ inputs.image-name }} + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha,format=long + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push + id: push + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} package: - if: inputs.chaincode && needs.build.outputs.image_digest != '' + if: inputs.chaincode-label != '' && needs.build.outputs.image_digest != '' needs: build runs-on: ubuntu-latest @@ -61,19 +65,19 @@ jobs: - name: Create package uses: hyperledgendary/package-k8s-chaincode-action@ba10aea43e3d4f7991116527faf96e3c2b07abc7 with: - chaincode-label: ${{ inputs.imagename }} - chaincode-image: ghcr.io/hyperledger-labs/${{ inputs.imagename }} + chaincode-label: ${{ inputs.chaincode-label }} + chaincode-image: ${{ inputs.image-name }} chaincode-digest: ${{ needs.build.outputs.image_digest }} - name: Rename package if: startsWith(github.ref, 'refs/tags/v') - run: mv ${IMAGE_NAME}.tgz ${IMAGE_NAME}-${CHAINCODE_VERSION}.tgz + run: mv ${CHAINCODE_LABEL}.tgz ${CHAINCODE_LABEL}-${CHAINCODE_VERSION}.tgz env: - IMAGE_NAME: ${{ inputs.imagename }} + CHAINCODE_LABEL: ${{ inputs.chaincode-label }} CHAINCODE_VERSION: ${{ github.ref_name }} - name: Release package if: startsWith(github.ref, 'refs/tags/v') uses: softprops/action-gh-release@v1 with: - files: ${{ inputs.imagename }}-${{ github.ref_name }}.tgz + files: ${{ inputs.chaincode-label }}-${{ github.ref_name }}.tgz diff --git a/.github/workflows/go-contract-image.yml b/.github/workflows/go-contract-image.yml index c48fda9..11935c1 100644 --- a/.github/workflows/go-contract-image.yml +++ b/.github/workflows/go-contract-image.yml @@ -19,6 +19,6 @@ jobs: name: Docker build uses: ./.github/workflows/docker-build.yml with: - imagename: go-contract + image-name: ghcr.io/hyperledger-labs/fabric-builder-k8s/sample-go-contract path: samples/go-contract - chaincode: true + chaincode-label: go-contract diff --git a/.github/workflows/java-contract-image.yml b/.github/workflows/java-contract-image.yml index 6975957..5b7af4d 100644 --- a/.github/workflows/java-contract-image.yml +++ b/.github/workflows/java-contract-image.yml @@ -19,6 +19,6 @@ jobs: name: Docker build uses: ./.github/workflows/docker-build.yml with: - imagename: java-contract + image-name: ghcr.io/hyperledger-labs/fabric-builder-k8s/sample-java-contract path: samples/java-contract - chaincode: true + chaincode-label: java-contract diff --git a/.github/workflows/node-contract-image.yml b/.github/workflows/node-contract-image.yml index 36af117..603e4b4 100644 --- a/.github/workflows/node-contract-image.yml +++ b/.github/workflows/node-contract-image.yml @@ -19,6 +19,6 @@ jobs: name: Docker build uses: ./.github/workflows/docker-build.yml with: - imagename: node-contract + image-name: ghcr.io/hyperledger-labs/fabric-builder-k8s/sample-node-contract path: samples/node-contract - chaincode: true + chaincode-label: node-contract diff --git a/.github/workflows/peer-image.yml b/.github/workflows/peer-image.yml index a0b3d3b..6dfcc57 100644 --- a/.github/workflows/peer-image.yml +++ b/.github/workflows/peer-image.yml @@ -23,5 +23,5 @@ jobs: name: Docker build uses: ./.github/workflows/docker-build.yml with: - imagename: k8s-fabric-peer + image-name: ghcr.io/hyperledger-labs/fabric-builder-k8s/k8s-fabric-peer path: .